0

Im using the Open Source Tool iTextSharp to read a .Pdf file in my Asp.Net MVC3 application which is coded in c#.Net.

Below is my Code.

   filePath = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory,
                    Path.GetFileName(Infile.FileName));
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }
                    Infile.SaveAs(filePath);
                    var pdfdoc = new iTextSharp.text.Document();
                    PdfReader reader2 = new PdfReader((string)filePath);
                    string strText = string.Empty;

                    for (int page = 1; page <= reader2.NumberOfPages; page++)
                    {
                        iTextSharp.text.pdf.parser.ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.SimpleTextExtractionStrategy();
                        PdfReader reader = new PdfReader((string)filePath);
                        String s = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page,its);

                        s = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(s)));
                        strText = strText + s;
                        reader.Close();
                    }

Im getting the Error on the line

  String s = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page,its);

The error is Index was outside the bounds of the array.
Regards.

Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902
Sam M
  • 1,067
  • 2
  • 19
  • 42

1 Answers1

0

I resolved this issue by updating my version of iTextSharp from 5.1 to 5.2.

Scott Scowden
  • 1,157
  • 2
  • 11
  • 18