Add margin to PDF file when merging using PDFTK or similar
Asked Answered
E

3

14

I have a large collection of half-page sized PDF cut-sheets that are held in a folder on my Linux server. A user to the site will want to create a booklet from a subset of these. The booklet will be bound therefore the even pages of the collection will want more margin on the right side and the odd pages will want more margin on the left side. There can be up to 200 pages in a collection out of a universe of 500 pages so I don't want to regenerate each page to set the margin of it. It would take too much of the servers time to run the content through the DOMPDF. Just building the document using PDFTK is fast.

I'd like to merge the document with PDFTK from a centered PDF file and add the appropriate margin for the odd or even page.

If not PDFTK then is there another tool that might do the job?

Enamel answered 22/4, 2013 at 23:32 Comment(0)
R
24

If you use ubuntu, you can install pdfcrop:

sudo apt-get install -y pdfcrop

Despite its name, pdfcrop has the option to add margins:

pdfcrop --margin '29 0 29 0' input.pdf output.pdf

(Note: the unit is bp. 72 bp = 1 inch. 29 bp is approximately 1 cm.)

Then, use pdfjam to do the offset trick for the right and left pages.

pdfjam --twoside --offset '1cm 0cm' file.pdf

Note: pdfcrop does have problems with some pdf files. (!!! Error: Ghostscript exited with error code 139!).

Rizo answered 23/7, 2015 at 9:45 Comment(3)
On Ubuntu 14.04: Unable to locate package pdfcropPetronilapetronilla
@Petronilapetronilla I'm probably late to this party, but pdfcrop, pdfjoin etc. are in the pdfjam package, which actually needs pdflatex along with the pdfpages latex package to be installed. Installing the pdfjam ubuntu package (with dependencies) should suffice.Paige
On Ubuntu 16.04 LTS, pdfcrop is in texlive-extra-utils.Etienne
L
6

If you are still interested in this, you should have a look at pdfjam which allows you to offset and clip pdfs. With respect to your particular question you might do something like

pdfjam --twoside --offset '2cm 0cm' file.pdf

This shifts the even pages 2cm to the right and the odd one to the left.
pdfjam is a front end to the pdfpages package of pdflatex.

Lobotomy answered 28/11, 2013 at 14:36 Comment(1)
If you encounter: "pdfjam ERROR: LaTeX package pdfpages.sty is not installed" - use "sudo apt-get install texlive-extra-utils " together with "apt-get install texlive-latex-recommended".Dinghy
C
2

Even if it is a bit late, but it might help someone. In response to @ElkeSpaak comment, it's the package texlive-extra-utils:

dpkg-query -S /usr/bin/pdfcrop 
texlive-extra-utils: /usr/bin/pdfcrop
Celia answered 5/4, 2016 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.