I worked on a project for a client some time ago [1] where extraction of text from PDFs was a big part of it. Researched several products, tried them, settled on xpdf - the C library, used it from my C code. It worked well for many PDFs but not for some others [2].
[1] There could be better products by now. Also, had heard good things about PDFTextStream, which another comment here mentions.
[2] Some data would get corrupted, e.g. characters interchanged, missing characters, etc, in the extracted text.
There are technical reasons inherent in the nature of the PDF format, due to which 100% perfect text extraction, including correct character positions, is not always possible for all PDF files (only for some) - that's one thing I learned from working on that project. Some of that learning was from a key person at the company that sells and supports xpdf. His support and knowledge was very good. They even quickly fixed a bug or two that I found in the product.
But things do work for many cases. As an aside, I also developed a small program that used heuristics to identify cases in which the PDF extraction was incorrect. Was fun.