Say there is a book that has been split into several PDFs. I want to do two things:
- Merge the PDFs and reduce the size of the resulting PDF.
- Fix the page numbering.
(1) can be done with pdftk
or Ghostscript. For me, Ghostscript creates considerably smaller PDFs and is the only program (of the two) available on my PC.
Example:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -q -sOutputFile=output.pdf input_1.pdf input_2.pdf [...] input_n.pdf
Why is (2) a problem at all? Because different books start counting page numbers on different pages whereas your PDF reader starts counting at page 1 if you don't do anything. This can be fixed with an empty document, the package pdfpages
, \setcounter
, and \pagenumbering
.
Example:
\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}
My problem is now: I want to fix the page numbering and create a small PDF but calling pdflatex and then Ghostscript creates a PDF that is considerably bigger than a PDF that has been merged with Ghostscript.
How do I create PDFs as small as with (1) while having (2)?
EDIT: Forgot to add hyperref
to the LaTeX code.