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

查看:392
本文介绍了将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.

我们合并的所有文件均为一页,因此想知道以后是否还有其他实用程序可以添加书签吗?

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 Primer .

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页创建一个目录(因为您保证成分文件对于合并的输出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 (some string you want)东西确定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

'nother

哦,顺便说一句:当您使用Ghostscript将两个PDF文件合并为一个文件时, 会保留书签,而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:使用Ghostscript,但告诉它不会重新处理图像". .

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天全站免登陆