In order for anyone to sell anything, they must "compete with free." The idea of competing with free means that the cost of paying for a product must be lower than the cost of producing or acquiring it by other means (not necessarily illegal). I suppose "free" in this sense means something more along the lines of "acquiring without purchase," because it still may incur cost. The cost of paying for the product is dollars and cents. The cost of producing it or acquiring it by other means may be money (material costs), time (labor costs), and risk cost (potential consequences from broken laws or morals).
Stealing a book from a store involves high risk cost, since stores are equipped with cameras and other security measures. Producing the book yourself would involve taking the time to copy pages from a borrowed book, whether digitally, or physically, so this takes time and material costs (if you print it). These costs are pretty high, and often, in the process, quality of the product is degraded. However, these are still options to get the product for free (the same goes for something like a baseball bat - it could be reproduced by a carpenter without having to buy one from the store).
Compare these costs with the cost of pirating an existing digital edition of a book. The time cost is extremely low and in most cases negligible, as it is pretty easy to copy a file with any modern computer. The risk cost is (until recently) fairly low, as pirating can be done (somewhat) anonymously over a network like the Internet, and there are still relatively low security measures. There is no material cost (negligible amount of bandwidth or disk space).
Competing with these extremely low costs has been the crux of the digital media market. However, it is often discussed among proponents of pirating that these costs are not the only factors. One large factor is how much the content producer deserves the money from a purchase. A study has shown, in the music industry, that piracy has boosted CD sales. When discussed on sites like Reddit, the consensus is that there is another cost involved in acquiring content - value. What if you buy a CD for $20 only to find you hate it, or only like one song? What if you buy a textbook for $200 and find that you never need it for class? The value would then be so low, the monetary cost was a waste. However, if you were to pirate these items, find that they are of low value, you haven't wasted as much. Why then, would those who pirate content choose to buy it, if they could get it free (or rather, because of the costs listed above, extremely cheap)? It seems to center on the value aspect. If a piece of media is found to be of high value, the consumer deems the media worthy of purchase, and shells out money for a copy straight from the source.
As case examples from two other digital media markets - video games and videos - take The Witcher 2 (game) and Louis C.K.'s latest comedy act. Neither copy employed DRM, and neither was sold for unreasonable costs - Louis C.K.'s video is available for a mere $5, and The Witcher 2 is a mere $39.99 ($10-$20 less than a normal game) and includes all bonus content and free downloadable content upgrades for the life of the game. Sales of both skyrocketed, because the products were available at low cost, with low restrictions, and were high quality products. Both of these successfully competed with free.
Piracy is a problem because people don't know how to properly view, categorize, or handle it. Currently, the vast majority of piracy combatants see the solution as making the cost of piracy higher, by making it more difficult and imposing higher consequences. However, the consumers view the solution from the opposite side: make the content available at a fair price, or we won't buy it, we'll go to the competition. If Piracy were a business, this would be seen solely as an issue of competition, and prices would drop.