Pages

Thursday, November 28, 2013

Using Latex To Add Page Numbers and a Binding Offset to PDF Files

I spent the weekend getting my tax documents in order (yeah I know, I live a pretty extreme life).  I like to assemble them into a single PDF file of about 100 pages and keep a digital copy and a produce a bound printed copy.  The bound version is easy to make notes on and show to others.  That's all well and good, but sometimes when binding the printed version, the holes are punched through important information on the side of the pages.  Adding a binding offset solves this problem.

A binding offset is an area on the side of the page that's kept clear for the holes to be punched through.  Offsetting the pages isn't enough though, they also need to be scaled to fit into the smaller area available.  In my case I print on both sides of the paper, this complicates things further as well.  It means the binding offset needs to alternate between the left and right sides of the page on consecutive pages.

I thought that this was pretty much impossible unless you used professional tools, but I soon found out it's ridiculously easy in LaTeX.  While I was at it, I decided to add page numbering to the output file as well.

Below I'll go though a quick exaggerated demonstration of what I mean.  I've started by looking at the 2nd and 3rd pages of a 3 page document.  The page on the left covers the extents of the page.

PDF file capture
Example document
After being processed the output file now contains an area in the middle of the page to allow binding.  The page numbers are also added to the bottom of the page opposite the binding area.
PDF file capture
Binding offset and page numbers added
The LaTeX file I used to generate the output is below.  It by no means covers all possible situations, PDF files can get complex, and this could break one of the more esoteric features of the standard, so I recommend testing it first.  It worked perfectly for me though.

The code below is also just a starting point, you could also include pages from other PDF files or put multiple pages on one page, it's a highly customisable tool.  This however should be enough of a framework to get you started.  I'm still learning all the tricks myself.

% pdfbind.tex

\documentclass[10pt,a4paper,twoside]{report}
\usepackage[final]{pdfpages}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead{}                       % clear header
\fancyfoot{}                       % clear footer
\fancyfoot[LE,RO]{\Large\thepage}  % add page numbers to pages

% remove bars from top and bottom of page
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}
\includepdfset{offset=42mm 0cm, pagecommand=\thispagestyle{fancy}}
\includepdf[fitpaper=true,scale=0.6,pages=-]{PDFInputFile.pdf}
\end{document}



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.