我正在尝试使用基于 ISO 规范的 PDF-2.0 标准创建一个最小的 PDF 文件示例。我想避免使用外部参照表,而仅使用交叉引用流字典,而不使用预告片部分。
该文件在 Adobe 中打开,但当我想关闭它时,它会尝试保存它,我认为这是为了修复它所认为的损坏的文档结构。
所以我猜我的PDF不符合PDF-2.0。但为什么不呢?
这是我的 PDF-2.0 文件的代码:
%PDF-2.0
%Óëéá
1 0 obj
<</Type /Catalog
/Pages 2 0 R
/Metadata 5 0 R
>>
endobj
2 0 obj
<</Type /Pages
/Kids [3 0 R 4 0 R]
>>
endobj
3 0 obj
<</Type /Page
/Parent 2 0 R
/MediaBox [0 0 595 842]
>>
endobj
4 0 obj
<</Type /Page
/Parent 2 0 R
/MediaBox [0 0 595 842]
>>
endobj
5 0 obj
<</Type /Metadata
/Subtype /XML
/Length /2880
>>
stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
<pdf:Producer>PdfProd</pdf:Producer>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreateDate>2024-02-28T00:05:50+01:00</xmp:CreateDate>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:format>application/pdf</dc:format>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
<xmpMM:DocumentID>425eed68-3fad-4856-b0b0-1cd1d3a4fe84</xmpMM:DocumentID>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
endstream
endobj
6 0 obj
<</Type /XRef
/Index [0 7]
/Size 7
/W [1 2 1]
/Root 1 0 R
/ID [<cd1e8e8ec3cfb8b1a0df0d3cb2303e5d><cd1e8e8ec3cfb8b1a0df0d3cb2303e5d>]
>>
stream
00 0000 00
01 000F 01
01 004F 02
01 0084 03
01 00CA 04
01 0110 05
01 0CA2 06
endstream
endobj
startxref
3385
%%EOF
我正在展示您的文件的更常见的功能,这些功能将允许大多数(如果不是全部)版本 1 或 2 PDF 读者接受,而无需考虑在进入或退出时进行任何“修复”。
我已经更改了顺序,尽管每个对象的编号顺序并不重要,并且如果信息部分位于第一个位置,通常元数据将是第三个对象。 Acrobat 通常会通过首先添加重复的信息部分以及从元数据中选择的条目来“修复”。然而,对于符合 Acrobat 的读者来说,这里没有 /Info 部分。
值得注意的是,通常 /Type 是作为最后一个对象条目找到的,而我们在逻辑上可能期望或更喜欢首先找到它。与更改版本相关的评论在最后。
%PDF-2.0
%Óëéá
1 0 obj
<</Metadata 2 0 R/Pages 3 0 R/Type/Catalog>>
endobj
2 0 obj
<</Length 2791/Subtype/XML/Type/Metadata>>
stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
<pdf:Producer>PdfProd</pdf:Producer>
<xmp:CreateDate>2024-02-28T00:00:00+00:00</xmp:CreateDate>
<xmp:ModifyDate>2024-02-28T00:00</xmp:ModifyDate>
<dc:format>application/pdf</dc:format>
<xmpMM:DocumentID>425eed68-3fad-4856-b0b0-1cd1d3a4fe84</xmpMM:DocumentID>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
endstream
endobj
3 0 obj
<</Count 1/Kids[4 0 R]/Type/Pages>>
endobj
4 0 obj
<</Contents 5 0 R/MediaBox[0 0 595 842]/Parent 3 0 R/Resources<<>>/Type/Page>>
endobj
5 0 obj
<</Length 4>>
stream
q
Q
endstream
endobj
xref
0 6
0000000004 00256 f
0000000015 00000 n
0000000075 00000 n
0000002941 00000 n
0000002992 00000 n
0000003086 00000 n
trailer
<</Size 6/Root 1 0 R>>
startxref
3138
%%EOF
即使是单页 [0],页面也应包含 /Count
<</Count 1/Kids[4 0 R]/Type/Pages>>
页面应该推断出一些内容(即使我们声明它是空的)<</Contents 5 0 R/MediaBox[0 0 595 842]/Parent 3 0 R/Resources<<>>/Type/Page>>
最小的页面内容是可以接受的
# # obj
<</Length 0>>stream
endstream
endobj
其他人建议更改“外部参照”结构。然而,尽管标准建议您使用的类型(扩展文本流)。我还没有看到全面可接受的文档格式(我没有工作示例)。
因此,读者通常应该使用完全扁平化或完全扁平化,并且在进行编辑(增量添加、更改等)时切勿混合使用两者。
我使用了上面较小的版本。