将 PDF 与带有书签的 PDFTK 合并? [英] Merge PDF's with PDFTK with Bookmarks?

查看:48
本文介绍了将 PDF 与带有书签的 PDFTK 合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 pdftk 合并多个 pdf 效果很好.但是,有什么简单的方法可以为每个合并的 pdf 制作书签?

Using pdftk to merge multiple pdf's is working well. However, any easy way to make a bookmark for each pdf merged?

我在 pdftk 文档上没有看到任何关于此的内容,所以我认为 pdftk 是不可能的.

I don't see anything on the pdftk docs regarding this so I don't think it's possible with pdftk.

我们合并的所有文件都是 1 页,所以想知道是否还有其他实用程序可以在之后添加书签?

All of our files merged will be 1 page, so wondering if there's any other utility that can add in bookmarks afterwards?

或另一个基于 linux 的 pdf 实用程序,它允许在为每个单独的 pdf 指定书签的同时进行合并.

Or another linux based pdf utility that will allow to merge while specifying a bookmark for each individual pdf.

推荐答案

您还可以使用 Ghostscript 合并多个 PDF.这条路线的一大优势是解决方案易于编写脚本,并且不需要真正的编程工作:

You can also merge multiple PDFs with Ghostscript. The big advantage of this route is that a solution is easily scriptable, and it does not require a real programming effort:

gswin32c.exe ^
          -dBATCH -dNOPAUSE ^
          -sDEVICE=pdfwrite ^
          -sOutputFile=merged.pdf ^
          [...more Ghostscript options as needed...] ^
          input1.pdf input2.pdf input3.pdf [....]

使用 Ghostscript,您将能够传递 pdfmark 语句,这些语句可以为进入生成的 PDF 的每个附加源文件添加目录和书签.例如:

With Ghostscript you'll be able to pass pdfmark statements which can add a Table of Content as well as bookmarks for each additional source file going into the resulting PDF. For example:

gswin32c.exe ^
          -dBATCH -dNOPAUSE ^
          -sDEVICE=pdfwrite ^
          -sOutputFile=merged.pdf ^
          [...more Ghostscript options as needed...] ^
          file-with-pdfmarks-to-generate-a-ToC.ps ^
          -f input1.pdf input2.pdf input3.pdf [....]

gswin32c.exe ^
          -dBATCH -dNOPAUSE ^
          -sDEVICE=pdfwrite ^
          -sOutputFile=merged.pdf ^
          [...more Ghostscript options as needed...] ^
          file-with-pdfmarks-to-generate-a-ToC.ps ^
          -f input1.pdf ^
             input2.pdf ^ 
             input3.pdf [....]

有关 pdfmark 主题的一些介绍,另请参阅 Thomas Merz 的 PDFmark入门.

For some introduction to the pdfmark topic, see also Thomas Merz's PDFmark Primer.


我本来想给你一个 file-with-pdfmarks-to-generate-a-ToC.ps 的例子,但不知为何忘记了.这是:


I had wanted to give you an example for file-with-pdfmarks-to-generate-a-ToC.ps, but somehow forgot it. Here it is:

[/Page 1 /View [/XYZ null null null] /Title (File 1) /OUT pdfmark
[/Page 2 /View [/XYZ null null null] /Title (File 2) /OUT pdfmark
[/Page 3 /View [/XYZ null null null] /Title (File 3) /OUT pdfmark
[/Page 4 /View [/XYZ null null null] /Title (File 4) /OUT pdfmark 

这将为前 4 个文件 == 前 4 页创建一个 ToC(因为您保证您的成分文件是合并输出 PDF 的每个 1 页).

This would create a ToC for the first 4 files == first 4 pages (since you guarantee your ingredient files are 1 page each for your merged output PDF).

  1. [/XYZ null null null] 部分确保您的页面视口和缩放级别在您点击链接时不会从当前的视图改变.(如果你想要一个任意的例子,你可以说 [/XYZ 222 111 2] 来做到这一点.)
  2. /Title(你想要的一些字符串) 决定了 ToC 中的文本.
  1. The [/XYZ null null null] part makes sure your page viewport and zoom level does not change from the current one when you follow the link. (You could say [/XYZ 222 111 2] to do this, if you want an arbitrary example.)
  2. The /Title (some string you want) thingie determines what text is in the ToC.

而且,您甚至可以直接将这些参数添加到 Ghostscript 命令行:

And, you could even add these parameters to the Ghostscript commandline directly:

gswin32c.exe ^
       -o merged.pdf ^
       [...more Ghostscript options as needed...] ^
       -c "[/Page 1 /View [/XYZ null null null] /Title (File 1) /OUT pdfmark" ^
       -c "[/Page 2 /View [/XYZ null null null] /Title (File 2) /OUT pdfmark" ^
       -c "[/Page 3 /View [/XYZ null null null] /Title (File 3) /OUT pdfmark" ^
       -c "[/Page 4 /View [/XYZ null null null] /Title (File 4) /OUT pdfmark" ^
       -f input1.pdf ^
          input2.pdf ^ 
          input3.pdf ^ 
          input4.pdf [....]


'nother Edit:

哦,顺便说一句:当您使用 Ghostscript 将两个 PDF 文件合并为一个文件时,Ghostscript 确实 会保留书签 -- pdftk.exe 不会.让我们使用我第一次编辑的命令生成的那个(有效地连接同一文件的 2 个副本):

Oh, and by the way: Ghostscript does preserve the bookmarks when you use it to merge two PDF files into one -- pdftk.exe does not. Let's use the one generated by the command of my first edit (effectively concatenating 2 copies of the same file):

 gswin32c ^
    -sDEVICE=pdfwrite ^
    -o doublemerged.pdf ^
     merged.pdf ^
     merged.pdf

文件 doublemerged.pdf 现在有 2*4 = 8 个书签.

The file doublemerged.pdf will now have 2*4 = 8 bookmarks.

  • 预期结果:书签 1、2、3 和 4 链接到第 1、2、3 和 4 页.
  • 问题是,书签 5、6、7 和 8 也链接到第 1、2、3 和 4 页.

原因是,预先存在的书签确实通过绝对页码解决了它们的链接目标.为了解决这个问题(书签在合并文件中工作),必须生成书签,这些书签确实指向指定目的地的链接目标(并确保这些书签在合并的文档中是唯一的).

The reason is, that the pre-existing bookmarks did address their link targets by absolute page numbers. To work around that (and bookmarks work in merged files), one would have to generate bookmarks which do point to link targets by named destinations (and make sure these are uniq across documents which are merged).

(此方法也适用于 linux,只需使用 gs 而不是 gswin32c.)

(This approach also works on linux, just use gs instead of gswin32c.)

上面的命令行使用 [...more Ghostscript options as needed...] 作为更多选项的占位符.

Above command line uses [...more Ghostscript options as needed...] as a place holder for more options.

如果您不使用其他选项,Ghostscript 将对各种参数应用其内置默认值.但是,这可能会给您带来您可能不喜欢的结果.由于 Ghostscript 会根据输入生成一个全新的 PDF,这意味着可能会更改某些原始对象.这适用于色彩空间和图像压缩级别.

If you do not use other options, Ghostscript will apply its built-in defaults for various parameters. However, this may give you results which may not to your liking. Since Ghostscript generates a completely new PDF based on the input, this means that some of the original objects may be changed. This is true for color spaces and for image compression levels.

如何应用保持原始嵌入图像不变的参数可以在 SuperUser: "Use Ghostscript, but tell它不重新处理图像".

How to apply parameters which leave the originally embedded images unchanged can be seen over at SuperUser: "Use Ghostscript, but tell it to not reprocess images".

这篇关于将 PDF 与带有书签的 PDFTK 合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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