背景
一直没有找到Debian中给PDF做书签的GUI程序。今天找了一下命令行解决方案。所需软件:ghostscript和pdftk。
做标签
-
撰写
index.info文件,格式示例如下:[/Count 3 /Page 4 /Title (Introduction) /OUT pdfmark [/Page 4 /Title (Features) /OUT pdfmark [/Page 6 /Title (Mailing lists and IRC channel) /OUT pdfmark [/Page 6 /Title (Virus submitting) /OUT pdfmark [/Count 2 /Page 6 /Title (Base package) /OUT pdfmark [/Count 2 /Page 6 /Title (Supported platforms) /OUT pdfmark [/Page 6 /Title (UNIX) /OUT pdfmark [/Page 7 /Title (Windows) /OUT pdfmark [/Page 7 /Title (Binary packages) /OUT pdfmark [/Count 7 /Page 7 /Title (Installation) /OUT pdfmark [/Page 7 /Title (Requirements) /OUT pdfmark [/Page 8 /Title (Installing on shell account) /OUT pdfmark [/Page 8 /Title (Adding new system user and group) /OUT pdfmark [/Page 9 /Title (Compilation of base package) /OUT pdfmark [/Page 9 /Title (Compilation with clamav-milter enabled) /OUT pdfmark [/Page 9 /Title (Running unit tests) /OUT pdfmark [/Page 10 /Title (Reporting a unit test failure bug) /OUT pdfmark对应的标签形式如图:
index.info格式解释:-
/Count nnn: 标签后子标签数为nnn -
/Page nnn: 标签对应的PDF文件页码为nnn -
/Title (xxx): 标签名称
-
-
命令行:
gs -sDEVICE=pdfwrite -q -dBATCH -dNOPAUSE -sOutputFile=output.pdf -dPDFSETTINGS=/prepress index.info -f input.pdf
去除标签
如果index.info文件不小心弄错了或者原文件中已经有标签,会需要修改文件中的标签。这时去除标签重做是最高效的。但没有查到gs命令去除标签的命令选项,找到了pdftk的解决方案。
- 命令行:
pdftk A=example_input.pdf cat A1-end output example_output.pdf
