Index was outside the bounds of the array while reading a .Pdf using iTextSharp

天大地大妈咪最大 提交于 2019-12-08 12:17:39

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/8951408/index-was-outside-the-bounds-of-the-array-while-reading-a-pdf-using-itextsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!