Click here to Skip to main content
15,394,479 members
Articles / Programming Languages / C#
Posted 20 May 2006


174 bookmarked

Extract Text from PDF in C# (100% .NET)

Rate me:
Please Sign up or sign in to vote.
3.66/5 (59 votes)
20 May 2006CPOL1 min read
A simple class to extract plain text from PDF documents with ITextSharp


This is a 100% .NET solution to extract text from PDF documents.


Dan Letecky posted a nice code on how to extract text from PDF documents in C# based on PDFBox. Although 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 Code

In order to use this solution in your projects, you need to do the following steps:

  • Add references to itextsharp.dll and SharpZiplib.dll
  • Add the PDFParser.cs class to your project

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 resultant 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, I use a simple function ExtractTextFromPDFBytes 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.


  • 20th May, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Romania Romania
No Biography provided

Comments and Discussions

QuestionRequires iTextSharp, which uses a "copyleft" license (AGPL) - so must buy iTextSharp if use commercially. Pin
ToolmakerSteve23-Jan-19 13:31
MemberToolmakerSteve23-Jan-19 13:31 
BugSee your return type Pin
shezee61112-Aug-17 6:59
Membershezee61112-Aug-17 6:59 
QuestionNot working Pin
Member 1293388831-Mar-17 19:34
MemberMember 1293388831-Mar-17 19:34 
Questionwaste of time Pin
Member 1259699615-Mar-17 0:59
MemberMember 1259699615-Mar-17 0:59 
AnswerRe: waste of time Pin
ngoj27-Apr-17 23:36
Memberngoj27-Apr-17 23:36 
QuestionNot working Pin
Onur Guzel8-Mar-17 23:52
MemberOnur Guzel8-Mar-17 23:52 
Questionyour code is dumb Pin
Hassan Alrehamy14-Aug-16 18:39
MemberHassan Alrehamy14-Aug-16 18:39 
AnswerRe: your code is dumb Pin
The Magical Magikarp19-Nov-19 10:53
MemberThe Magical Magikarp19-Nov-19 10:53 
Questionempty txt file Pin
xxsaxx24-Feb-16 7:43
Memberxxsaxx24-Feb-16 7:43 
AnswerRe: empty txt file Pin
duy nguyễn6-Aug-17 16:54
Memberduy nguyễn6-Aug-17 16:54 
QuestionNeed to convert pdf to excel Pin
atulonweb@gmail.com17-Nov-15 20:43
Memberatulonweb@gmail.com17-Nov-15 20:43 
QuestionExtract Text from PDF in C# (100% .NET) Pin
rose lindo12-Aug-15 19:53
Memberrose lindo12-Aug-15 19:53 
GeneralNice demo Pin
awaneesh jatrana1-Jul-15 0:04
Memberawaneesh jatrana1-Jul-15 0:04 
QuestionKaputt for me Pin
B. Clay Shannon29-Jun-15 5:51
professionalB. Clay Shannon29-Jun-15 5:51 
QuestionGet an err msg instead of the actual contents Pin
B. Clay Shannon25-Jun-15 8:52
professionalB. Clay Shannon25-Jun-15 8:52 
QuestionProbably a Dumb Question Pin
Member 117451965-Jun-15 9:35
MemberMember 117451965-Jun-15 9:35 
GeneralGreat Job Pin
khaen31-Mar-15 13:41
Memberkhaen31-Mar-15 13:41 
QuestionIt is not working. Pin
irensaltali28-Mar-15 5:54
Memberirensaltali28-Mar-15 5:54 
AnswerRe: It is not working. Pin
savage824-May-20 6:45
Membersavage824-May-20 6:45 
QuestionI think you have the files mixed (Source and Demo) Pin
jadaho2-Dec-14 1:54
Memberjadaho2-Dec-14 1:54 
AnswerGood tool, thanks for sharing. Pin
mic.xu25-Sep-14 8:40
Membermic.xu25-Sep-14 8:40 
GeneralMy vote of 2 Pin
Member 107128088-Aug-14 1:43
MemberMember 107128088-Aug-14 1:43 
QuestionTanks a lot! Pin
KrNeS23-Jan-14 5:41
MemberKrNeS23-Jan-14 5:41 
QuestionWorks (kind of) Pin
matt.whitby10-Dec-13 1:09
Membermatt.whitby10-Dec-13 1:09 
GeneralGreat job. Pin
Perry Orr7-Aug-13 17:20
MemberPerry Orr7-Aug-13 17:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.