简体   繁体   English

PDF 根 object 中的错误

[英]Error in PDF root object

This PDF root object will get Adobe Reader to fail.此 PDF 根 object 将使 Adobe Reader 失败。 Other PDF readers like Foxit, Nuance, Evince, SumatraPDF will open the PDF file without problems.其他 PDF 阅读器,如 Foxit、Nuance、Evince、SumatraPDF 将毫无问题地打开 PDF 文件。 The problem is /Dests which reguires an indirect object (PDF reference).问题是 /Dests 需要间接 object(PDF 参考)。 Deleting the /Dests << >> will get Adobe Reader to open the file, but fail on printing.删除 /Dests << >> 将使 Adobe Reader 打开文件,但打印失败。 All the other readers work OK without the /Dests.没有/Dests,所有其他阅读器都可以正常工作。 Any ideas how to correct the syntax in the following root object example?任何想法如何更正以下根 object 示例中的语法?

  17 0 obj
  <<
    /Type /Catalog
    /Pages 2 0 R
    /Outlines 15 0 R
    /PageMode /UseOutlines
    /Dests <<
             /__WKANCHOR_2 8 0 R
             /#8d#c2#ca#ebs#e4#60#00#9e#97l#b9#80#1b#cb#86sQR#83 9 0 R
           >>
  >>
  endobj

OK, found a few spare minutes...好的,找到了几分钟的空闲时间...

So the first thing I noticed is that * all other readers indeed may open the file (I only tested a few).所以我注意到的第一件事是 *所有其他读者确实可以打开文件(我只测试了几个)。 But these do spit out lots and lots of warnings and error messages... (Try Ghostscript: gs virkerikke.pdf , or try evince...) There is at least a damaged xref table in the PDF as well (or at least this is one of the complaints).但是这些确实会吐出很多警告和错误消息...(尝试 Ghostscript: gs virkerikke.pdf ,或尝试 evince...) PDF 中至少有一个损坏的xref表(或至少这个是投诉之一)。

xpdf complains: xpdf抱怨:

[....]
Error: Invalid XRef entry
Error: Invalid XRef entry
Error: Invalid XRef entry
Error (157): Unterminated string
Error (159): End of file inside dictionary

gv complains: gv抱怨:

Warning: translation table syntax error: Unknown keysym name:  apLineDel
Warning: ... found while parsing '<Key>apLineDel:   GV_Page(page+5)     '
Warning: String to TranslationTable conversion encountered errors

evince complains: evince抱怨:

[....]
Error: Invalid XRef entry
Error: Invalid XRef entry
Error: Invalid XRef entry
Error (157): Unterminated string
Error (159): End of file inside dictionary
Error (157): Unterminated string
Error (159): End of file inside dictionary
Error (157): Unterminated string
Error (159): End of file inside dictionary
[....]
Error (1918): Unterminated string
Error (1920): End of file inside dictionary

gs complains: gs抱怨:

**** Warning: File has a corrupted %%EOF marker, or garbage after %%EOF.

mupdf complains: mupdf抱怨:

+ pdf/pdf_xref.c:60: pdf_read_start_xref(): cannot find startxref
| pdf/pdf_xref.c:477: pdf_load_xref(): cannot read startxref
\ pdf/pdf_xref.c:532: pdf_open_xref_with_stream(): trying to repair
warning: ignoring invalid character in hex string: '!'
warning: ignoring invalid character in hex string: 'O'
warning: ignoring invalid character in hex string: 'T'
warning: ignoring invalid character in hex string: 'Y'
[....]

qpdf --qdf complains: qpdf --qdf抱怨:

virkerikke.pdf (object 17 0, file position 2234): null character not allowed in name token

OK, now opening this crappy file in a text editor, trying to repair it.好的,现在在文本编辑器中打开这个糟糕的文件,尝试修复它。 What I find is this that this file (32746 Bytes in size) has some serious syntax problems:我发现这个文件(大小为 32746 字节)有一些严重的语法问题:

  1. Garbage after %%EOF : There is a complete and syntax-correct HTML-File glued to the PDF after its %%EOF marker with the title "Wkhtmltopdf - Teknisk regelverk" . %%EOF之后的垃圾:在 PDF 的%%EOF标记之后,有一个完整且语法正确的 HTML 文件,其标题为"Wkhtmltopdf - Teknisk regelverk" Its size is 11878 Bytes.它的大小是 11878 字节。 Delete this part, and you'll have a 'better' PDF with a size of only 20868 Bytes left... though Acrobat/Adobe Reader still doesn't open it after you saved the edited file.删除此部分,您将拥有一个“更好”的 PDF,其大小仅剩 20868 字节......尽管在保存编辑后的文件后 Acrobat/Adobe Reader 仍然无法打开它。
  2. Invalid character in name token: This is inside the name token /#8d#c2#ca#ebs#e4#60#00#9e#97l#b9#80#1b#cb#86sQR#83 .名称标记中的无效字符:这是在名称标记/#8d#c2#ca#ebs#e4#60#00#9e#97l#b9#80#1b#cb#86sQR#83 It appears 2x in this file.它在此文件中显示为 2x。 Already in my first comments I told you that this key didn't look trustworthy to me, because it contains only very few ASCII characters, but lots of binary Bytes (using their hexadecimal representation. (What I had overlooked was that it even contained a #00 which is the PDF representation for a nul character... the use of which is illegal for name tokens in PDF.) Replace that name token with another (phantasy) one of exactly the same length (on both occurrences). I did choose /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa . Save the edited file.在我的第一条评论中,我已经告诉过你,这个密钥对我来说看起来不可信,因为它只包含很少的 ASCII 字符,但有很多二进制字节(使用它们的十六进制表示。(我忽略的是它甚至包含一个#00是一个nul字符的 PDF 表示形式......对于 PDF 中的名称标记,使用它是非法的。)用另一个(幻想)长度完全相同的名称标记替换该名称标记(两次出现)。我做了选择/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa保存编辑的文件。

Now even Acrobat/Adobe Readers will open this repaired file without complaining.现在,即使是 Acrobat/Adobe Readers 也可以毫无怨言地打开这个修复过的文件。 Also, the 'other readers' will work now better with this file, spitting out less warnings and now being able to identify some metadata (such as creation date and producer == wkhtmltopdf) which they were unable to get to for the original file.此外, “其他阅读器”现在可以更好地使用此文件,发出更少的警告,并且现在能够识别他们无法获取原始文件的一些元数据(例如创建日期和生产者 == wkhtmltopdf)。

/Dests is supposed to be a dictionary (pairs of /Key value ) containing names (Keys) and corresponding destinations (values). /Dests应该是包含名称(键)和相应目的地(值)的字典( /Key value对)。 The /Dests keyword first appeared in PDF 1.1. /Dests关键字首次出现在 PDF 1.1 中。

PDF 1.1 allowed for the keys only to be a name object. PDF 1.1 允许键仅是名称 object。 PDF 1.2 allowed for keys to also be byte strings. PDF 1.2 允许键也是字节字符串。

So which PDF version does your file claim to be?那么您的文件声称是哪个 PDF 版本?

From the spec for PDF 1.7 ("ISO 32000-1"), describing the meaning of /Dests :来自 PDF 1.7(“ISO 32000-1”)的规范,描述了/Dests的含义:

In PDF 1.1, the correspondence between name objects and destinations shall be defined by the Dests entry in the document catalogue (see 7.7.2, “Document Catalog”).在 PDF 1.1 中,名称对象和目的地之间的对应关系应由文档目录中的 Dests 条目定义(参见 7.7.2,“文档目录”)。 The value of this entry shall be a dictionary in which each key is a destination name and the corresponding value is either an array defining the destination, using the syntax shown in Table 151, or a dictionary with a D entry whose value is such an array.这个条目的值应该是一个字典,其中每个键是一个目的地名称,并且对应的值是一个定义目的地的数组,使用表 151 中所示的语法,或者一个具有 D 条目的字典,其值是这样一个数组.

Seems pretty straightforward.看起来很简单。 Move the dests array into its own object.将 dests 数组移动到它自己的 object 中。

Rather than而不是

17 0 obj
<<
  /Type /Catalog
  /Pages 2 0 R
  /Outlines 15 0 R
  /PageMode /UseOutlines
  /Dests <<
    /__WKANCHOR_2 8 0 R
    /#8d#c2#ca#ebs#e4#60#00#9e#97l#b9#80#1b#cb#86sQR#83 9 0 R
  >>
>>
endobj

you should instead have:你应该有:

17 0 obj
<<
  /Type /Catalog
  /Pages 2 0 R
  /Outlines 15 0 R
  /PageMode /UseOutlines
  /Dests 1234 0 R
>>
endobj
1234 0 obj
<</__WKANCHOR_2 8 0 R/#8d#c2#ca#ebs#e4#60#00#9e#97l#b9#80#1b#cb#86sQR#83 9 0 R>>
endobj

The object number is going to be something pseudorandom. object 数字将是伪随机数。

And how to move the dest array out of the root into its own object going to be entirely dependent on what PDF software you're using.以及如何将 dest 数组从根目录移到它自己的 object 将完全取决于您使用的 PDF 软件。 "A Hex Editor" is an option, but then you're over on SuperUser instead of here on StackOverflow... technically. “十六进制编辑器”是一个选项,但是从技术上讲,您在 SuperUser 上而不是在 StackOverflow 上。 I suspect you might get a mulligan on that one.我怀疑你可能会在那个上得到一个调度。 I'd let it slide myself.我会让它自己滑动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python PDFMiner错误:“否/ Root对象! - 这真的是PDF吗?“ - Python PDFMiner error: “No /Root object! - Is this really a PDF?” Xfinium PDF:无法保存 pdf 文件。 接收错误根缺失条目 - Xfinium PDF: Unable to save pdf file. Receiving error root missing entry 创建 PDF 编译错误“Application: defined or object-defined error” - Create PDF compile error “Application: defined or object-defined error” PDF 使用工作站自定义在 iSeries 上创建时出现格式错误 Object (WCST) - PDF Format Error Creating On iSeries Using Workstation Customizing Object (WCST) 尝试退出 Acrobat 对象时,创建和关闭 pdf 会产生错误 - Creating and closing pdf generates error when trying to exit Acrobat object pdf错误:IE9和IE10上的“预期dict对象” - pdf error: “expected a dict object” on IE9 and IE10 'list' object 没有属性 'read' 在 pdf2image 中面临此错误 - 'list' object has no attribute 'read' facing this error in pdf2image 错误:当不在 object 上下文中时使用 $this - 使用 dompdf laravel 生成 pdf - Error: Using $this when not in object context - generate pdf using dompdf laravel 将 PDF 文件导入 XeLaTeX 会出现“pdf_link_obj():传递无效对象”错误 - Import PDF file into XeLaTeX gives "pdf_link_obj(): passed invalid object" error .htaccess重定向根文件夹中的.pdf / .doc文件 - .htaccess redirect for .pdf/.doc file in the root folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM