如何找到预告片词典?

Rah*_*hly 5 pdf parsing

通过PDF规范,它说trailer先于startxref.对我而言,说xref可以出现在文档的任何地方,但trailer仍然出现在之前startxref.这是有道理的,直到你必须解析它,因为你必须反过来解析你不能考虑注释或字符串.让我们变得更加古怪.

trailer<< %\
  /Size 4 %\
  /Root 1 0 R %\
  /Info 4 0 R %\
  /Key (\
trailer<< %\
  /Size 4 %\
  /Root 2 0 R %\
  /Info 3 0 R %\
>>%)
>>&)
% test test )
startxref
 15
%%EOF
Run Code Online (Sandbox Code Playgroud)

这是一个非常有效的预告片.第一个是真正的预告片,但第二个是"字符串".在这种情况下,反向解析将无法捕获注释.如果它的注释或字符串分开,寻找字符串预告片将会失败.我想知道找出预告片开始位置的最佳方法是什么?

更新 - 此预告片似乎在Acrobat Reader中打开

%PDF-1.3
%âãÏÓ
xref
0 4
00000000 65535 f
00000110 00000 n
00000250 00000 n
00000315 00000 n
00000576 00000 n

1 0 obj <<
  /Type /Catalog
  /Pages 2 0 R
  /OpenAction [ 3 0 R /XYZ null null null ]
  /PageLabels << /Nums [0 << /S /D >> ] >>
>>
endobj
2 0 obj <<
  /Type /Pages
  /Kids [ 3 0 R ]
  /Count 1
>>
endobj
3 0 obj <<
  /Type /Page
  /Parent 2 0 R
  /Resources << >>
  /MediaBox [ 0 0 612 792 ]
>>
endobj
4 0 obj <<
  /Producer (Me)
  /CreationDate (D:20110626000000Z)
>>
endobj

trailer<< %\
  /Size 4 %\
  /Root 1 0 R %\
  /Info 4 0 R %\
  /Key (\
trailer<< %\
  /Size 4 %\
  /Root 2 0 R %\
  /Info 3 0 R %\
>>%)
>>%)
% test test )
startxref
 15
%%EOF
Run Code Online (Sandbox Code Playgroud)

就语法而言,这符合规范.不知何故,他们似乎能够知道他们是在评论中还是在字符串中.解析LR,第二个预告片是一个%尾部的字符串,后面有一个评论.但RL解析,你不知道第一个)是注释的一部分,还是字符串定义的结尾.

另一个例子:

%PDF-1.3
%âãÏÓ
xref
0 8
0000000000 65535 f
0000000210 00000 n
0000000357 00000 n
0000000428 00000 n
0000000533 00000 n
0000000612 00000 n
0000000759 00000 n
0000000830 00000 n
0000000935 00000 n

1 0 obj <<
  /Type /Catalog
  /Pages 2 0 R
  /OpenAction [ 3 0 R /XYZ null null null ]
  /PageLabels << /Nums [0 << /S /D >> ] >>
>>
endobj
2 0 obj <<
  /Type /Pages
  /Kids [ 3 0 R ]
  /Count 1
>>
endobj
3 0 obj <<
  /Type /Page
  /Parent 2 0 R
  /Resources << >>
  /MediaBox [ 0 0 612 792 ]
>>
endobj
4 0 obj <<
  /Producer (Me)
  /CreationDate (D:20110626000000Z)
>>
endobj
5 0 obj <<
  /Type /Catalog
  /Pages 6 0 R
  /OpenAction [ 7 0 R /XYZ null null null ]
  /PageLabels << /Nums [0 << /S /D >> ] >>
>>
endobj
6 0 obj <<
  /Type /Pages
  /Kids [ 7 0 R ]
  /Count 1
>>
endobj
7 0 obj <<
  /Type /Page
  /Parent 6 0 R
  /Resources << >>
  /MediaBox [ 0 0 100 100 ]
>>
endobj
8 0 obj <<
  /Producer (Me)
  /CreationDate (D:20110626000000Z)
>>
endobj

trailer<< %\
  /Size 8 %\
  /Root 1 0 R %\
  /Info 4 0 R %\
  /Key (\
trailer<< %\
  /Size 8 %\
  /Root 5 0 R %\
  /Info 8 0 R %\
>>%)
>>%)
% test test )
startxref
 17
%%EOF
Run Code Online (Sandbox Code Playgroud)

此示例在Adobe中正确显示.在我的上一个案例中,你声称它会失败,因为"root"节点是无效的,但是这个新的样本,root是有效的,但它从未实际使用过.那么它不应该显示100x100窗口,而不是8.5"x11"?

关于资源

  (Required; inheritable) A dictionary containing any resources required by the page 
(see Section 3.7.2, “Resource Dictionaries”). If the page requires no resources, the 
value of this entry should be an empty dictionary. Omitting the entry entirely
indicates that the resources are to be inherited from an ancestor node in the page 
tree.
Run Code Online (Sandbox Code Playgroud)

iPD*_*dev 1

预告片字典位于外部参照部分之后。根据起始外部参照值,您可以跳转到外部参照部分的开头。阅读外部参照部分后,您将到达预告片词典。Trailer 关键字始终位于该行的第一个(前面允许有空格)。PDF 文件允许增量更新,因此您可能会遇到具有多个外部参照部分和预告片的 PDF 文件,但处理规则是相同的,首先处理外部参照部分,然后处理预告片。如果文件包含增量更新,预告片部分将包含对先前外部参照部分的引用。