Modifying PDF Files with Command Line Tools

Miscellaneous

ad free blog

2008-04-25 by Thomas Fischer [en]

Thomas Fischer Sometimes it is neccessary to edit a pdf file e.g. by extracting selected pages, putting multiple pages on one page or changing the page margins. For all these problems there is a toolchain called PDFjam.

PDFjam is a collection of shell scripts that use pdfLaTeX to perform modifications on a (set of) pdf documents. Installing PDFjam is quite simple, as most Linux distributions offer packages.
PDFjam consists of three shell scripts:

pdfnup
Puts multiple pages on one pages, may perform additional operations such as scaling. The PostScript equivalent for this tool is psnup.
pdfjoin
Combines multiple pdf documents into one file, may perform additional operations.
pdf90
Rotates pages in 90 degree steps.

For PostScript documents, similar operations can be performed using the PSUtils or mpage.

I'm going to present some typical use cases where you want to use the PDFjam tools:

  1. You got slides from a lecture or presentation. Each slide is one page in the pdf document and it is a waste of paper (and trees ;-)) to print it this way. To put 2x4 pages on one page, use the following command:
    pdfnup --nup 2x4 slides.pdf
    The result file will be called slides-2x4.pdf. Now, you may want to have some margin around these eight slides on each page, e.g. to add personal notes or for punching. Simply scale the page's content:
    pdfnup --nup 2x4 --scale 0.9 slides.pdf
    Adapt the scale parameter to your personal needs. To have space between each of the eight slides, add the --delta parameter:
    pdfnup --nup 2x4 --scale 0.9 --delta "1cm 1cm" slides.pdf
    Here, between two slides one centimeter is added in horizontal and vertical direction. Of course, you can use this program not only for slides, but you can put two pages on one side of a sheet of paper, too. In this case, use --nup 2x1.
  2. You got a set of pdf documents from several sources and you want to combine them to one single document. E.g. from SpringerLink you can get whole books split into single files per chapter or section. To recombine a sequence of pdf files to one pdf file, use the following command:
    pdfjoin --outfile book.pdf  chapter1.pdf chapter2.pdf ...
    Parameter --outfile determines the resulting pdf file's name.

Both pdfjoin and pdfnup provide many more options to scale, rotate, or crop the files to be processed. Simply use the parameter --help to get an overview of all available options.

Next time, we will have a look on how to add text or any other content into existing pdf documents ...

Keywords: LaTeX, Linux
Trackback-URL: http://www.t-fischer.net/blog/20080425_Modifying_PDF_Files

Writing comments is currently not possible. Feel free to write me an email to the address shown on my homepage.

More social bookmarking links than anybody else ;-)
LinkARENAalltagzTechnoratiMister Wongdel.icio.usGoogle BookmarksYiGGsimpyfurlblogmarkstailranktektagoneviewdiggslashdotfolkdyahoo my web
Valid XHTML 1.0!Valid CSS!UTF-8 EncodedUse Metric & SIGentoo LinuxSession Initiation ProtocolAny BrowserWir wollen keine Softwarepatente!Coffee PoweredUnix-AGKDE Developer (KBibTeX)Hacker EmblemPlay OGGXING profileDANTE MemberThe content of this page is licensed under a Creative Commons Attribution-Share Alike 3.0 License, unless noted otherwise.Blog
Date of Modification: 2009-Feb-21 18:08Chuck Norris