如何使用“pdftk”指定附件的描述?

发布于 2024-12-01 17:36:08 字数 362 浏览 8 评论 0原文

PDFTK的文档中没有提到如何做到这一点。该命令:

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

将一个文件附加到原始 file.pdf 的第 2 页,并将结果输出到

attachDoc.pdf 是文件系统的文件名。但我无法为此指定任何描述,以使用适当的符号描述在最终文件中显示附件。

这将特别有用,因为在自动生成操作中,附件通常具有由服务器分配的临时名称,并且需要描述

有什么方法可以做到这一点吗?

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 <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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇到 2024-12-08 17:36:08

简短回答:

使用 pdftk 时,您(当前)无法添加文件附件的描述。
(但是,添加此功能应该不会太复杂,因为它只需要在文件附件字典中添加一个额外的键条目/Desc...也许您应该向pdftk 开发人员?)

更长的答案:

在(最近的一个的版本)Ghostscript。 但是请注意,它非常复杂!

它需要使用特殊的 PostScript 扩展来定义 pdfmark 运算符。创建此运算符的目的是将高级功能插入到 PDF 文件中,而这些功能不能在 PostScript 本身中使用。

我将借助一个单独的文件进行演示,该文件使用一系列 pdfmark 操作将文本文件插入 PDF。这是文本文件 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

如您所见,/Desc 键保存我的描述文本 dEsCrIpTiOn >。

现在运行此 Ghostscript 命令:

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

这是 Acrobat 显示的生成的 PDF 文件的屏幕截图:

Acrobat Screenshot

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:

Acrobat screenshot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文