iTextSharp的V5 GetTextFromPage()抛出IndexOutOfRangeException抛出、iTextSharp、IndexOutOfRangeException、GetT

2023-09-03 08:01:36 作者:蹲在墙头等红杏、

试图提取PDF文件的文本内容与下面的code:

Trying to extract the textual content of a pdf with the following code:

PdfReader reader = new PdfReader(path);
string strText = string.Empty;

for (int page = 1; page <= reader.NumberOfPages; page++)
{
    string s = PdfTextExtractor.GetTextFromPage(reader, page);
    strText += " " + s;                
}
reader.Close();

NumberOfPages返回257,但227页,GetTextFromPage()抛出一个IndexOutOfRangeException。

NumberOfPages returns 257, but at page 227, GetTextFromPage() throws a IndexOutOfRangeException.

任何帮助是AP preciated。

Any help is appreciated.

hofnarwillie

hofnarwillie

推荐答案

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

I resolved this issue by updating my version of iTextSharp from 5.1 to 5.2.