如何生成可在文档查看器中使用的纯文本源代码PDF示例?

我刚刚发现规范中的文章Adobe论坛:简单文本字符串示例已损坏。,因此我对查找纯文本源PDF示例感兴趣。

因此,通过该帖子,我最终发现:

  • 网页PDF参考和PDF规范的Adobe扩展| Adobe开发人员连接;其中包含:

    • PDF 文档管理–便携式文档格式–第1部分:PDF 1.7,第一版(PDF32000_2008.pdf)

PDF 1.7规范在第699页上有附录“ _Annex H(参考)示例PDF文件”;从那开始,我想尝试“ H.3简单文本字符串示例”(“经典Hello

World”)。

因此,我尝试将其保存为hello.pdf(从PDF32000_2008.pdf复制时,请注意_except注释,您可能会得到“ %PDF-1.

4”-即在后面插入一个空格1.,必须将其删除_):

%PDF-1.4

1 0 obj

<< /Type /Catalog

/Outlines 2 0 R

/Pages 3 0 R

>>

endobj

2 0 obj

<< /Type /Outlines

/Count 0

>>

endobj

3 0 obj

<< /Type /Pages

/Kids [ 4 0 R ]

/Count 1

>>

endobj

4 0 obj

<< /Type /Page

/Parent 3 0 R

/MediaBox [ 0 0 612 792 ]

/Contents 5 0 R

/Resources << /ProcSet 6 0 R

/Font << /F1 7 0 R >>

>>

>>

endobj

5 0 obj

<< /Length 73 >>

stream

BT

/F1 24 Tf

100 100 Td

( Hello World ) Tj

ET

endstream

endobj

…并且我正在尝试打开它:

evince hello.pdf

…但是,evance无法打开它:“无法打开文档/ PDF文档已损坏”;并且:

Error: PDF file is damaged - attempting to reconstruct xref table...

Error: Couldn't find trailer dictionary

Error: Couldn't read xref table

我也检查qpdf

$ qpdf --check hello.pdf

WARNING: hello.pdf: file is damaged

WARNING: hello.pdf: can't find startxref

WARNING: hello.pdf: Attempting to reconstruct cross-reference table

hello.pdf: unable to find trailer dictionary while recovering damaged file

我在哪里错呢?

非常感谢您的任何回答,

干杯!

回答:

您应该在文件末尾附加一个(在语法上正确的)xreftrailer节。这意味着:即使未正确说明字节偏移量,PDF中的每个对象也需要在外部参照表中一行。然后,Ghostscript,pdftk或qpdf可以重新建立正确的外部参照并呈现文件:

[...]

endobj

xref

0 8

0000000000 65535 f

0000000010 00000 n

0000000020 00000 n

0000000030 00000 n

0000000040 00000 n

0000000050 00000 n

0000000060 00000 n

0000000070 00000 n

trailer

<</Size 8/Root 1 0 R>>

startxref

555

%%EOF

以上是 如何生成可在文档查看器中使用的纯文本源代码PDF示例? 的全部内容, 来源链接: utcz.com/qa/397750.html

回到顶部