JMM’s notes on

PDFs (Portable Document Format)

Command Line

Some common tasks I do with PDFs.

Selecting a range of pages

If you want to make a new PDF that only has some pages, this is how to do it with pdftk:

pdftk input.pdf cat 1-4 8 output out.pdf

This takes in an input.pdf, takes pages 1 through 4 and page 8 and makes a 5-page output called output.pdf.

Concatenating PDFs

pdftk is also useful for concatenating PDFs:

pdftk input1.pdf input2.pdf cat output out.pdf

You can also use the following format to select specific pages:

pdftk A=input1.pdf B=input2.pdf cat A1 B1 A1 B1 output out.pdf

This makes a four page PDF. This is sometimes useful when I want to print junior-sized PDFs on letter paper.

SVG to PDF

This is covered in my Inkscape notes, but repeated here:

inkscape --export-type=pdf --export-filename=output.pdf input.svg

Word Doc to PDF

unoconv -T 30 -f pdf input.docx

Here, -T 30 makes a 30 second timeout. This is just a workaround for me, since otherwise the first time I try to launch unoconv it’ll typically time out as it takes a while to start up a server (I think that’s what’s going on).

PDF booklets

I print out half-sized (or “junior”-sized) PDFs (like A5 vs A4) often. See junior-pdf.nix for a script that does this. It basically makes it easy to print a PDF that can be cut and bound easily.

Tools