0
使用開源工具iTextSharp讀取我的Asp.Net MVC3應用程序中用.c#.Net編碼的.Pdf文件。使用iTextSharp讀取.Pdf時,索引超出了數組範圍邊界
以下是我的代碼。
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);
的誤差指數陣列的邊界之外的錯誤。
此致敬禮。
相關:http://stackoverflow.com/q/8578793/60761 –