我在 .net (c#) 项目中使用 iTextSharp 库时收到特定 pdf 文件的未处理异常。我无法理解我要上传的 pdf 有什么具体内容,尽管我可以看到使用从 Internet 下载的基本 pdf 功能有效。 以下部分代码:
string pdfTemplate ="特定 pdf 的 url"; var pdfReader = new PdfReader(pdfTemplate);
抛出异常: 重建失败:字典键 Z 不是名称。在文件指针 224 处;原始消息:字典键 Z 不是名称。在文件指针 224
请问有什么建议吗?我没有想法...
最佳答案
文档信息字典有错误:
%PDF-1.4
1 0 obj
<<
/Title (þÿ)
/Creator (þÿ)
/Producer (þÿ Q t 4 . 8 . 2 \( C \) 2 0 1 1 N o k i a C o r p o r a t i o n a n d / o r i t s s u b s i d i a r y \( - i e s \))
/CreationDate (D:20131111142910)Z)
>>
endobj
CreationDate 值有两个右括号。 iText 正确地假定第一个是正确的,即完成值,因此,将 Z 视为下一个条目的键。
但是key必须是名字,名字以斜线开头,但是这个名字没有斜线。 语法错误!!因此:
Dictionary key Z is not a name. at file pointer 224
PdfReader
作为尝试再次读取 PDF 失败后的最后手段,这次首先尝试重建交叉引用。由于问题与交叉引用根本无关,这显然再次失败。因此:
Rebuild failed: Dictionary key Z is not a name. at file pointer 224; Original message: Dictionary key Z is not a name. at file pointer 224
此语法错误的创建可能是 Qt 错误(Qt 4.8.2 在此被命名为创建者)。
PS:你试过用Adobe Reader打开这个文件的文档属性吗?此处不会弹出任何内容,这肯定是由于该问题造成的。
关于c# - ITextSharp 异常读取 pdf : Rebuild failed: Dictionary key "" is not a name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19909557/