【发布时间】: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