* IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. *** 
  Dec 14 2014 8:25AM     Rohan
  0 Comments    2206 Views  
Here Rohan provided a short tutorial with example, how to read PDF Document text in ASP.Net C#/VB.
For that, we have to use a DLL called iTextSharp. Click Here to download iTextSharp DLL file.
Using iTextSharp DLL, we can read the PDF text in efficient manner.
Adding dll to the Project
Steps: Image given below show Add Reference option
  1. Right click the project
  2. Select Add Reference from the options
  3. From the Add Reference PopUp window, Select Browse tab and Select iTextSharp dll file
  4. then, Click Ok. The iTextSharp dll file can be loaded to the project
You will need to import the following namespace.

using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;


Imports iTextSharp.text.pdf
Imports iTextSharp.text.pdf.parser

In Page load Event, ReadPdfFile() method is called with parameter file path.

protected void Page_Load(object sender, EventArgs e)
            // Read PDF Text
            string PdfData = ReadPdfFile(@"C:\Test.pdf");            


Protected  Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs)

            ' Read PDF Text
            Dim PdfData As String =  ReadPdfFile("C:\Test.pdf"

End Sub

Code for Reading PDF file
Below is the sample code for Reading PDF file in ASP.Net C#/VB.
ReadPdfFile() method takes the parameter, file name and Reads the content finally PDF Document text will return as String.

public string ReadPdfFile(string fileName)
            string currentText = "";
            StringBuilder PDFText = new StringBuilder();
            PdfReader pdfReader = new PdfReader(fileName);

            for (int page = 1; page <= pdfReader.NumberOfPages; page++)
                ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
                currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);

                currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)));
                PDFText = PDFText.Append(currentText);
            return PDFText.ToString();


Public Function ReadPdfFile(ByVal fileName As StringAs String

            Dim currentText As String =  "" 
            Dim PDFText  StringBuilder =  New () 
            Dim pdfReader  PdfReader =  New (fileName) 
            Dim page As Integer
            For  page = 1 To  pdfReader.NumberOfPages Step  page + 1
                Dim strategy  ITextExtractionStrategy =  New () 
                currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy)
                currentText = Encoding.UTF8.GetString(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.UTF8.GetBytes(currentText)))
                PDFText = PDFText.Append(currentText)
            Return PDFText.ToString()

End Function

The ReadPdfFile() method will read more than one pages in PDF document.
I hope this page will helps to read PDF Document text in ASP.Net application. Thanks.

Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Oct 29 2018 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Oct 28 2018 12:09PM Posted By Pranav
Google URL Shortener in C#
Oct 20 2018 12:09PM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Oct 5 2018 12:09PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Sep 26 2018 12:09PM Posted By John
Gridview custom CSS in ASP.Net
Sep 14 2018 12:09PM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Sep 10 2018 12:09PM Posted By Micheal
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: