Add gutter (binding margin) to existing PDF file
How can I add a gutter margin (different for odd and even pages) to a PDF document so that there is room to hole-punch it after I print it? I am familiar with Ghostscript and the Linux Terminal but have been unable to find commands to fulfil this specific need.
Currently some content is too close to the edge. I could use scaling in the print dialog box to create room for the binding, but this would reduce the size more than absolutely necessary and leave a gap on both sides of the page.
A solution that simply adds an extra centimetre to either side of the page (left for odd pages and right for even) would be adequate here since I can then choose "scale to fit" feature when I print it.
My question was initially marked as a duplicate of this, but neither answer solves my problem. I tried using both Briss and PDF Scissors, but they are PDF cropping tools and can only make the pages smaller, not larger. My question is also different because I need to resize differently on odd and even pages. The asker of the original question did not have this requirement.
Solution 1:
I intend to expand this into a proper answer when I have time, but here is the solution I found, in case anyone needs it in the meantime. The idea is to use Ghostscript with the -c
option to modify the PDF file using custom PostScript.
Firstly, you need to know the height and width of the original PDF in Points (there are 72 Points in an inch). You could use the tool "pdfinfo" to find this information:
pdfinfo "inputFile.pdf"
Let's say you have an A4 document - A4 is 595pts × 842pts (210mm × 297mm).
If you want to add a 10mm (= 1cm = 28pts) gutter to the A4 document, then you need to give the following information to Ghostscript:
-dDEVICEHEIGHTPOINTS=842
(height of A4)
-dDEVICEWIDTHPOINTS=623
(=595+28, i.e., width of A4 + the gutter to be added)
{28 0 translate} {}
({shift odd pages 28pts right & 0pts up} {do nothing to even pages})
Note: Specifying the increased width adds space to the right hand side of the page, so it is only the odd numbered pages that must be translated - the even pages are already laid out correctly.
Here is the full command for Linux:
gs -q -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=outputFile.pdf \
-dDEVICEWIDTHPOINTS=623 -dDEVICEHEIGHTPOINTS=842 -dFIXEDMEDIA \
-c "<< /CurrPageNum 1 def /Install { /CurrPageNum CurrPageNum 1 add def
CurrPageNum 2 mod 1 eq {28 0 translate} {} ifelse } bind >> setpagedevice" \
-f "inputFile.pdf"
Note: This command makes the PDF 1cm wider than A4. If you then print on A4 everything will be scaled down to fit and the gutter will actually be slightly thinner than 1cm (it will be 9.5mm). If that's not good enough then you will have to do a bit of algebra to get the correct offset. In this case it would be 29.8pts, instead of 28pts, to get a 10.0mm printed gutter (you would also need to set -dDEVICEWIDTHPOINTS=624.8
). However, if the gutter is less than ~2cm then it's probably not worth doing the calculation, especially considering the tolerances in printing and paper size.