合并 PDF、修复页码并压缩

合并 PDF、修复页码并压缩

假设有一本书被拆分成几个 PDF。我想做两件事:

  1. 合并 PDF 并减小生成的 PDF 的大小。
  2. 修正页码。

(1) 可以使用 或 Ghostscript 完成pdftk。对我来说,Ghostscript 创建的 PDF 要小得多,并且是我电脑上唯一可用的程序(两个程序中)。

例子:

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -q -sOutputFile=output.pdf input_1.pdf input_2.pdf [...] input_n.pdf

为什么 (2) 会成为问题?因为不同的书从不同的页面开始计算页码,而如果你什么都不做,你的 PDF 阅读器会从第 1 页开始计算。这个问题可以通过一个空文档、包pdfpages\setcounter和来修复\pagenumbering

例子:

\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref}
\begin{document}
\pagenumbering{Roman}
\setcounter{page}{4}
\includepdf[pages=-]{input_1_with_TOC.pdf}
\pagenumbering{arabic}
\includepdf[pages=-]{input_2.pdf}
\includepdf[pages=-]{input_3.pdf}
% ...
\end{document}

我现在的问题是:我想修复页码创建一个小型 PDF,但调用 pdflatex 然后 Ghostscript 创建的 PDF 比与 Ghostscript 合并的 PDF 大得多。

我如何使用 (2) 创建与 (1) 一样小的 PDF?

编辑:忘记添加hyperref到 LaTeX 代码。

答案1

  1. 与 Ghostscript 合并。
  2. pdfpages在 Ghostscript 输出上使用如下方式:
\documentclass{article}
\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}
\pagenumbering{Roman}
\setcounter{page}{4}
\includepdf[pages={1-17}]{gs-output.pdf} % contains table of contents
\pagenumbering{arabic}
\includepdf[pages={18-}]{gs-output.pdf} % Rest of the book
\end{document}

相关内容