我有下面的代码iTextSharp的PDF阅读错误
using (var reader = new PdfReader(pdfPath))
{
for (int pageIndex = 1; pageIndex <= reader.NumberOfPages; pageIndex++)
{
var text = PdfTextExtractor.GetTextFromPage(reader, pageIndex);
//my other logic goes here
}
}
我得到的值不能为空在行
using (var reader = new PdfReader(pdfPath))
我不知道为什么它失败了几个PDF文件。我能够读取100个PDF文件,但只能读取4个PDF文件,我收到了这个错误。
错误:
System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at System.util.collections.HashSet2`1.AddAndCheck(T item)
at iTextSharp.text.pdf.PdfReader.PageRefs.IteratePages(PRIndirectReference rpage)
at iTextSharp.text.pdf.PdfReader.PageRefs.IteratePages(PRIndirectReference rpage)
at iTextSharp.text.pdf.PdfReader.PageRefs.IteratePages(PRIndirectReference rpage)
at iTextSharp.text.pdf.PdfReader.PageRefs.IteratePages(PRIndirectReference rpage)
at iTextSharp.text.pdf.PdfReader.PageRefs.IteratePages(PRIndirectReference rpage)
at iTextSharp.text.pdf.PdfReader.PageRefs.ReadPages()
at iTextSharp.text.pdf.PdfReader.PageRefs..ctor(PdfReader reader)
at iTextSharp.text.pdf.PdfReader.ReadPages()
at iTextSharp.text.pdf.PdfReader.ReadPdf()
at iTextSharp.text.pdf.PdfReader..ctor(IRandomAccessSource byteSource, Boolean partialRead, Byte[] ownerPassword, X509Certificate certificate, ICipherParameters certificateKey, Boolean closeSourceOnConstructorError)
at iTextSharp.text.pdf.PdfReader..ctor(String filename)
我iTextSharp的版本是5.5.7.0
你能否提供引发异常的文件名? –
文件名:Bills_080415.pdf ...我有很多这样的文件使用相同的文件命名约定使用此代码进行处理。 – techspider
我看了异常,我似乎发生在'iTextSharp.text.pdf.PdfReader.ReadPages'方法调用期间。也许文件损坏或格式不正确。 –