开发者

How can you specify the description of the attachment with `pdftk`?

In the documentation of PDFTK is not mentioned how to do it. The command:

pdftk file.pdf attach_files attachDoc.pdf to_page 2 output -

will attach a file to page 2 of the original file.pdf and output the result to <开发者_StackOverflow社区stdout>.

attachDoc.pdf is the file name of the filesystem. But I can not specify any description for this to show the attachment in the final file with an appropriate notation-description.

This would be especially useful, as in the automatic generation operations, the attachments often have temporary names assigned by the server and a description would be necessary

Is there any way to do this?


Short answer:

You cannot (currently) add the description of a file attachment when using pdftk.
(However, it should be not too complicated to add this feature, because it only requires an additional key entry /Desc to the file attachment dictionary... Maybe you should submit a feature request to the pdftk developers?)

Longer answer:

You may be able to achieve what you want with the help of (a very recent version of) Ghostscript. But be warned, it is quite complicated!

It requires the usage of the special PostScript extension that defines the pdfmark operator. This operator was created to insert advanced features into a PDF file which cannot be used within PostScript itself.

I'll demonstrate it with the help of a separate file which uses a series of pdfmark operations to insert a text file into a PDF. This is the content of text file, mypdfmark-for-attachments.ps:

 [                                           /NamespacePush  pdfmark
 [ /_objdef {fstream} /type /stream          /OBJ            pdfmark
 [ {fstream} << /Type /EmbeddedFile >>       /PUT            pdfmark

 [ {fstream} (I only simulate text file content here...)
                                             /PUT            pdfmark
 [ /Name <feff 0044 005a 005a 005a 005a 005a>
   /FS<<
      /Desc  (dEsCrIpTiOn)
      /Type  /Filespec
      /F     (my.txt)
      /EF    <<
             /F {fstream}
             >>
      >>                                     /EMBED          pdfmark
 [ {fstream}                                 /CLOSE          pdfmark
 [                                           /NamespacePop   pdfmark

As you can see, the /Desc key holds my description text dEsCrIpTiOn.

Now run this Ghostscript command:

gs -o emb.pdf -sDEVICE=pdfwrite mypdfmark-for-attachments.ps -f some.pdf 

Here is a screenshot of the resulting PDF file as shown by Acrobat:

How can you specify the description of the attachment with `pdftk`?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜