问题描述
我使用的是5.4.4版,我遇到了com.itextpdf.text.pdf.PdfReader的问题。
I am using version 5.4.4 and I have a problem with the com.itextpdf.text.pdf.PdfReader.
当我用
PdfReader reader = new PdfReader(„Test.pdf");
- 这是一张扫描表和我可以使用Adobe Reader打开它 - 发生以下错误:
com.lowagie.text.exceptions.InvalidPdfException:重建失败:字典键endstream不是名字。在文件指针3913220;原始消息:字典键endstream不是名称。在文件指针3913220
在com.lowagie.text.pdf.PdfReader.readPdf(PdfReader.java:668 )
at com.lowagie.text.pdf.PdfReader。(PdfReader.java:189)
at com.lowagie.text.pdf.PdfReader。(PdfReader.java:264 )
at com.lowagie.text.pdf.PdfReader。(PdfReader.java:247)
com.lowagie.text.exceptions.InvalidPdfException: Rebuild failed: Dictionary key endstream is not a name. at file pointer 3913220; Original message: Dictionary key endstream is not a name. at file pointer 3913220
at com.lowagie.text.pdf.PdfReader.readPdf(PdfReader.java:668)
at com.lowagie.text.pdf.PdfReader.(PdfReader.java:189)
at com.lowagie.text.pdf.PdfReader.(PdfReader.java:264)
at com.lowagie.text.pdf.PdfReader.(PdfReader.java:247)
我查看代码,因为itext 5.4 .4引发异常。在旧版本中,忽略此异常。
I look in the code and since itext 5.4.4 an exception is thrown. In older versions, this exception is ignored.
第1319行的itext 5.4.3中方法readDocObj()的代码:
Code from method readDocObj() in itext 5.4.3 on line 1319:
catch (Exception e) {
obj = null; // Exception ignored !!!!!!!!
}
第1319行的第5.4.4节中方法readDocObj()的代码:
Code from method readDocObj() in itext 5.4.4 on line 1319:
catch (IOException e) {
if (debugmode) {
e.printStackTrace();
obj = null;
}
else
throw e; // Exception thrown !!!!!!
}
在1346行的最新版本 - 版本5.5.1中:
In the newest itext-Version 5.5.1 on line 1346:
catch (IOException e) {
if (debugmode) {
if (LOGGER.isLogging(Level.ERROR))
LOGGER.error(e.getMessage(), e);
obj = null;
}
else
throw e; // Exception thrown !!!!!!
}
推荐答案
原始PDF包含错误并忽略该错误可能导致非常奇怪的结果(丢失对象,完全搞砸了PDF)。因此,我们应该抛出一个错误,告诉你文件有什么问题。您的PDF可能包含一个PDF流,其中的流字典不正确。
Your original PDF contains an error and ignoring that error can lead to very strange results (missing objects, completely screwed-up PDFs). Therefore, we should throw an error, informing you what is wrong with the file. Your PDF probably contains a PDF stream of which the stream dictionary is not correct.
认为该文件在Adobe Reader中打开良好是一个不好的论点:它并不意味着您的PDF遵循ISO-32000-1。 Adobe Reader会尽最大努力打开破坏的文件。如果您使用Adobe Acrobat打开它并使用Preflight,您会注意到Acrobat也会抱怨该错误。
Arguing that the file opens well in Adobe Reader is a poor argument: it doesn't mean that your PDF obeys ISO-32000-1. Adobe Reader does a best effort to open even files that are broken. If you would open it with Adobe Acrobat and use Preflight, you'll notice that Acrobat complains about that error too.
因为调试具有这样的文件非常困难错误,我们引入了 debugmode
常量。默认情况下,此常量为 false
,但在iText RUPS中设置为 true
。将此常量设置为 true
允许我们读取文件并忽略错误,以便我们可以在RUPS中检查文件。
As it was very hard to debug files with such an error, we introduced the debugmode
constant. This constant is false
by default, but set to true
in iText RUPS. Setting this constant to true
allows us to read the file and ignore the errors so that we can examine the file in RUPS.
如果您不关心输入PDF的质量,可以将 debugmode
设置为true,但我不建议这样做。我建议修复原始PDF。
If you don't care about the quality of your input PDFs, you can set debugmode
to true, but I wouldn't recommend doing that. I would recommend fixing the original PDF.
备注:我赞成评论。您显然没有告诉我们完整的事实,因为您声称您使用的是iText 5版本,但是您有错误消息提到我的名字(我是来自 com.lowagie $ c的Lowagie $ c>包)。
Remark: I upvoted the comment. You are clearly not telling us the full truth as you are claiming that you are using an iText 5 version, yet you have error messages mentioning my name (I am the Lowagie from the com.lowagie
packages).
这篇关于iText-PdfReader:重建失败:字典键endstream不是名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!