Get text from PDF file with iTextSharp

string ReadPdfFile(string filename)
{
  var pdfText = new StringBuilder();
  var reader = new PdfReader(filename);
  var pages = reader.NumberOfPages;
  for (int page = 1; page <= pages; page++)
  {
    var tes = new SimpleTextExtractionStrategy();
    var pgText = PdfTextExtractor.GetTextFromPage(reader, page, tes);
    pdfText.Append(pgText);
  }
  reader.Close();
  return pdfText.ToString();
}
Advertisements

About Panos

My name is Panos Kokkinidis and I am R&D Manager in Relational S.A., Athens, Greece.
This entry was posted in .NET and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s