我正在尝试手动制作 pdf。我掌握了基础知识,但我无法弄清楚的一件事是图像。
我现在正在尝试的事情,作为开始,是以二进制代码的形式添加一个简单的图像。二进制码的长度为9,应该可以表示一张3x3的黑白图像。代码是:111000111(这应该只是一条穿过中间的黑色水平线)。当然,这过于简化,没有压缩,不能用于更复杂的图像,但我很绝望,只想展示一些东西:)。
希望有人能帮助和教我更多关于这个话题的知识。
我的新 pdf(在 johnwhitington 评论之后,b 点除外)
%PDF-1.7
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog >>
endobj
2 0 obj
<<
/Type /Pages
/Count 1
/Kids [3 0 R] >>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Contents [4 0 R]
/MediaBox [500 500]
/Resources
<<
/XObject
<<
/Im1 5 0 R
>>
>>
>>
endobj
4 0 obj
<<
>>
stream
q
1 0 0 1 100 100 cm
/Im1 Do
Q
endstream
endobj
5 0 obj
<<
/Type /XObject
/Subtype /Image
/Height 3
/Width 3
/BitsPerComponent 1
/Length 9
/ColorSpace /DeviceGray
>>
stream111000111endstream
endobj
trailer
<< /Root 1 0 R
/Size 7
>>
%%EOF
我的旧PDF:
%PDF-1.7
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog >>
endobj
2 0 obj
<<
/Type /Pages
/Count 1
/Kids [3 0 R] >>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Contents [4 0 R]
/Resources
<<
/ProcSet [/PDF /ImageB]
/XObject
<<
/Im1 5 0 R
>>
>>
>>
endobj
4 0 obj
<<
>>
stream
q
1 0 0 1 0 0 cm
/Im1 DO
Q
endstream
endobj
5 0 obj
<<
/Type /XObject
/Subtype /Image
/Height 3
/Width 3
/BitsPerComponent 1
/Length 9
/ColorSpace /DeviceGray
>>
stream111000111endstream
endobj
trailer
<< /Root 1 0 R
/Size 7
>>
%%EOF
一些提示:
a)你需要不做。
b) 如果它是每个组件一位,九个像素,图像中将有两个字节(九位),而不是九个字节。 '1' 和 '0' 是 8 位字符,而不是位。
c) 这些天你不需要 ProcSet。
d) 要在屏幕上看到您的图像,您需要像 1 0 0 1 100 100 cm 这样的东西来放大它以便它可见。
e) 你的页面需要一个 /MediaBox