从头开始编写 PDF 文件的问题 [英] Issue writing a PDF file from scratch

查看:61
本文介绍了从头开始编写 PDF 文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式生成一个简单的 PDF 文件(仅限文本).对于大多数 PDF 阅读器,文件看起来与我想要的完全一样,但有些 PDF 阅读器不会打开文件并将其报告为已损坏.我已经从文件中删除了所有元素,只留下第一个空白页来调试代码并找到问题,但没有任何结果,它仍然被识别为损坏.

I'm trying to generate a simple PDF file (text only) programmatically. With most PDF reader the file looks exactly like I want but some PDF readers won't open the file and report it as damaged. I've removed every elements from the file leaving only the first void page to debug the code and found the problem but without any results, it's still recognized as damaged.

这是原始 PDF 数据:

This is the raw PDF data:

%PDF-1.4
1 0 obj
<< /Type /Catalog
   /Pages 2 0 R
>>
endobj
2 0 obj
<< /Type /Pages
   /Count 1
   /Kids [ 3 0 R ]
>>
endobj
3 0 obj
<< /Type /Page
   /Parent 2 0 R
   /Resources <<
   >>
   /MediaBox [ 0 0 595 842 ]
>>
endobj
xref
0 4
0000000000 65536 f 
0000000010 00000 n 
0000000067 00000 n 
0000000138 00000 n 
trailer
<< /Size 4
   /Root 1 0 R
>>
startxref
248
%%EOF

谁能告诉我这个 PDF 有什么问题?

Can anyone tell me what's wrong with this PDF?

提前致谢.

推荐答案

Per spec /Resources 是必需的,尽管它可以为空.将 /Resources <<>> 添加到对象 2 或 3 就足够了.

Per spec /Resources is required although it can be empty. Adding /Resources <<>> to object 2 or 3 should suffice.

编辑

下面带有更新的 /Resources 条目的 PDF 在我运行时通过了 Acrobat 的预检.您是否收到预检错误消息?

The PDF below with the updated /Resources entry passes Acrobat's preflight when I run it. Do you get a preflight error message?

%PDF-1.4
1 0 obj
<< /Type /Catalog
   /Pages 2 0 R
>>
endobj
2 0 obj
<< /Type /Pages
   /Count 1
   /Kids [ 3 0 R ]
>>
endobj
3 0 obj
<< /Type /Page
   /Parent 2 0 R
   /MediaBox [ 0 0 595 842 ]
   /Resources <<>>
>>
endobj
xref
0 4
0000000000 65536 f 
0000000010 00000 n 
0000000067 00000 n 
0000000138 00000 n 
trailer
<< /Size 4
   /Root 1 0 R
>>
startxref
243
%%EOF

这篇关于从头开始编写 PDF 文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆