Csharp/C#教程:使用iTextSharp读取.Pdf时,索引超出了数组的范围分享


使用iTextSharp读取.Pdf时,索引超出了数组的范围

我使用开源工具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); 

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

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

上述就是C#学习教程:使用iTextSharp读取.Pdf时,索引超出了数组的范围分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/958586.html

(0)
上一篇 2021年11月22日
下一篇 2021年11月22日

精彩推荐