Reading PDF File (ItextSharp) in CSharp
Reading PDF File – I started my day searching a solution on how to read PDF file and finally I was able to search for a solution . Here is a solution from stack overflow.
I am posting this to be able to help readers from this blog who have also searching for this problem.
Credit to stackoverflow:
Here’s a code found on this link which helps me a lot.
public string ReadPdfFile(object Filename)
string strText = string.Empty;
PdfReader reader = new PdfReader((string)Filename);
for (int page = 1; page <= reader.NumberOfPages; page++)
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
String s = PdfTextExtractor.GetTextFromPage(reader, page, its);
s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
strText = strText + s;
catch (Exception ex)
If you are using Visual Studio , you can add reference to ItextSharp using Manage Nuget Packages.To open Manage Nuget Packages, go to your solution explorer and right-click on your project name then scroll down for Manager Nuget Packages. To search for ItextSharp, simply search for ItextSharp then if the search result appears select the first option and click the install button on the right side of the result.
Below is the image of ItextSharp from Manage Nuget Packages option.
After successfully adding this reference you can now use it by adding this reference from your code.
- using iTextSharp.text.pdf;
- using iTextSharp.text.pdf.parser;
And now, you can already use iTextSharp from your code.
Thank you for reading!
Hopes that this simple solution can help you.