PDF with an external image using XObject

荒凉一梦 提交于 2021-02-07 06:58:09

问题


I'm trying to build a PDF file with a link to an external file.

I'm using the spec https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

On page 348 there is an example of image with an alternate image loaded remotely. When I create a document with the example from the doc, the reader (using acrobat reader XI) doesn't fetch the image. There is no error message but no request is being made (checked using wireshark).

  1. Can I have only a remote image (ie no "normal" image and alternate image).
  2. Is there an example somewhere of a full document using that /FS /URL syntax (ie not just the objects)? I couldn't find any that actually does the request.

Thanks

Edit: I used LibreOffice to create the base document with a single 1x1 pixel. http://pastebin.com/5GqCYgMp

I initially created my test document with Acrobat but the output was really messy.

Then replaced the stream with the example from the pdf spec, and tried to fix the startxref offset, but not sure it's correct. http://pastebin.com/BT42g02P

This document is currently not opening correctly, but I tried to get a minimum test case. My previous attempts were displayed with no errors only by luck (but the remote image didn't work anyway).

Is there any tool that actually allows the creation of XObject with /URL? I don't know the file format enough to create them reliably by hand.


回答1:


First of all,

I'm using the spec https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

I would recommend not using a PDF reference but instead the ISO standard. The Adobe PDF references are not normative in nature while the ISO standard is. (The actual content differences are minute but if there is a normative spec, one should use it.) Adobe also publishes a copy of the ISO standard with merely the header exchanged.

Then, please don't treat PDFs as text documents. E.g. by sharing them on pastebin, you make them subject to treatment as text which essentially destroys the content.

That all been said, let's look at your actual issue:

In your sample PDF you have:

4 0 obj
<</Type/XObject/Subtype/Image/Width 1/Height 1/BitsPerComponent 8/Length 0/F << /FS /URL
/F ( https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png )
>>/Filter/FlateDecode/ColorSpace/DeviceRGB
>>
stream
endstream
endobj

This indicates that the PDF viewer shall find at the URL https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png a file containing an array of 1 (/Width 1/Height 1) RGB (/ColorSpace/DeviceRGB) sample with 1 byte per color (/BitsPerComponent 8), cf. section 8.9.5 Image Dictionaries of ISO 32000-1.

I doubt your file fulfills that, I assume it actually is a PNG file in particular with a PNG structure, not the structure explained above.

PDF does not support the PNG format as is, you have to transform the data. It does support, though, the JPEG format using the /FFilter /DCTDecode which is why the sample from the specification

16 0 obj
  << /Type /XObject
     /Subtype /Image
     /Width 1000
     /Height 2000
     /ColorSpace /DeviceRGB
     /BitsPerComponent 8
     /Length 0 % This is an external stream
     /F << /FS /URL
           /F (http://www.myserver.mycorp.com/images/exttest.jpg)
        >>
     /FFilter /DCTDecode
  >>
stream
endstream
endobj

makes it look so easy.



来源:https://stackoverflow.com/questions/36318312/pdf-with-an-external-image-using-xobject

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!