C# 使用iTextSharp读取.Pdf时,索引超出了数组的边界
我正在使用开源工具iTextSharp读取Asp.NETMVC3应用程序中的.Pdf文件,该应用程序是用c#.Net编写的 下面是我的代码C# 使用iTextSharp读取.Pdf时,索引超出了数组的边界,c#,itextsharp,C#,Itextsharp,我正在使用开源工具iTextSharp读取Asp.NETMVC3应用程序中的.Pdf文件,该应用程序是用c#.Net编写的 下面是我的代码 filePath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(Infile.FileName)); if (System.IO.Fil
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();
}
错误是索引超出了数组的界限。尊敬。我通过将我的iTextSharp版本从5.1更新到5.2解决了此问题。相关:
String s = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader, page,its);