【问题标题】:Index was outside the bounds of the array while reading a .Pdf using iTextSharp使用 iTextSharp 读取 .Pdf 时,索引超出了数组的范围
【发布时间】:2012-02-15 14:36:29
【问题描述】:

我正在使用开源工具 iTextSharp 在我的 Asp.Net MVC3 应用程序中读取一个 .Pdf 文件,该应用程序是用 c#.Net 编码的。

以下是我的代码。

   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();
                    }

我收到错误就行了

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

错误是索引超出了数组的范围。
问候。

【问题讨论】:

标签: c# itextsharp


【解决方案1】:

我通过将 iTextSharp 版本从 5.1 更新到 5.2 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 2015-11-06
    • 2010-11-17
    相关资源
    最近更新 更多