|
|||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThis is a 100% .NET solution to extract text from PDF documents. BackgroundDan Letecky posted a nice code how to extract text from PDF documents in C# based on PDFBox. Altough his solution works well it has a drawback, the size of the required additional libraries is almost 16 MB. Using iTextSharp the size of required additional libraries is only 2.3 MB. Using the codeIn order to use this solution in your projects you need to do the following steps:
Then you can use the newly added class in the following way: // create an instance of the pdfparser class PDFParser pdfParser = new PDFParser(); // extract the text String result = pdfParser.ExtractText(pdfFile); I also created a small console application which uses the class and shows the progress of the conversion. Please keep in mind that if you try to extract text from big pdf files keeping all the resulted text in memory is not the best solution, in these cases you should write the extracted text to the file after parsing every page.
How is it working?My code is based on the algorithm in C ExtractPDFText. Using iTextSharp's PdfReader class to extract the deflated content of every page, then i use a simple functionExtractTextFromPDFBytes to extract the text contents from the deflated page.
Further improvements Although the code worked well for me, i didn't find in Adobe's pdf reference
how to parse special characters. So if someone knows how to do this, just post it and i will update the class.
|
||||||||||||||||||||||||||||||