Jon Dehdari




PDF Logo




PDF Tricks

The Portable Document Format (PDF) is a nice, open standard for fixed-layout documents. The first thing to know about PDFs is you don't need Adobe software to create, modify, or read PDFs.

Since PDF is an open standard, there are many useful free software packages. Some of them are PDFtk, pdfjam, poppler-utils, and some LaTeX packages (hyperref, navigator).

How do I join/merge PDFs together?

pdftk input1.pdf input2.pdf input3.pdf  cat output  output.pdf
	

How do I split all the pages of a PDF?

pdftk input.pdf burst
	
The output by default is pg_0001.pdf, pg_0002.pdf, etc.

How do I remove or extract certain pages from a PDF?

To remove page 7:
pdftk input.pdf  cat '~7'  output  output.pdf 
	
To remove pages 7, 9, and 14:
pdftk input.pdf  cat '~7~9~14'  output output.pdf
	
To include only pages 3, 8-11, and 15:
pdftk input.pdf  cat 3 8-11 15  output output.pdf 
	

How do I reverse the pages of a PDF?

pdftk input.pdf  cat end-1  output output.pdf
	

How do I rotate a PDF?

To rotate an entire PDF by 180 degrees (=south):
pdftk input.pdf  cat 1-endsouth  output output.pdf
	
To rotate pages 3 and 8-11 by 270 degrees (=west):
pdftk input.pdf  cat 1-2 3west 4-7 8-11west 12-end  output output.pdf
	

How do I reformat a PDF to 2-up?

pdfnup input.pdf
	
The resulting output is input-nup.pdf. The commands pdfnup (and pdfjam) use pdflatex, and have many more formatting options.

How do I password-protect and encrypt a PDF?

pdftk input.pdf  output output.pdf  user_pw PROMPT
	
You will then be prompted for a password. By default, the password-protected file doesn't allow printing. You can allow printing thus:
pdftk input.pdf  output  output.pdf  user_pw PROMPT  allow printing
	

How do I convert a PDF to plaintext?

Use the command pdftotext from the poppler-utils package
pdftotext input.pdf output.txt
	

How do I convert a plaintext file to PDF?

Paps is a small program that can handle UTF-8 text, including source code. The command ps2pdf comes from the ghostscript package.
paps input.txt | ps2pdf - output.pdf
	

How do I convert a PDF to HTML?

Don't do it.

How do I convert a color PDF to grayscale or black-and-white?

This is useful to see if color graphics in your paper are still readable when printed.
Grayscale:
gs -dNOPAUSE -dBATCH -q -sOutputFile=- -sDEVICE=psgray  input.pdf | ps2pdf - output.pdf
	
Monochrome / black-and-white:
gs -dNOPAUSE -dBATCH -q -sOutputFile=- -sDEVICE=psmono  input.pdf | ps2pdf - output.pdf
	

How do I convert a grayscale or black-and-white PDF to color?

Nice try :-P


(Although see this)

How do I view PDF metadata (author, subject, keywords, etc)?

Use the command pdfinfo from the poppler-utils package
pdfinfo input.pdf
	

How do I edit PDF metadata?

You can use your favorite text editor. Search in the file for /Author, /Title, /Producer , etc.
sensible-editor input.pdf
	
The general format is, for example /Title (The Title Goes Here), where keys start with a slash, and the values are surrounded by parentheses. Keys include /Author, /Title, /Keywords, /Subject, and a few others.

How do I annotate/draw on a PDF?

Xournal or Okular (Tools->Review)

How do I manually edit a PDF?

First convert your binary PDF to a text-based PDF:
qpdf -qdf input.pdf input_text.pdf
	
Now you can edit it with your favorite text editor:
sensible-editor input_text.pdf
	

How do I rescale/resize a PDF?

For example, to convert from A0 to A1 size paper:
pdfjam --a1paper poster_a0.pdf -o poster_a1.pdf
	
The command pdfjam uses pdflatex. You can manually specify the target size as well.

Another option is to use pdfposter, which is in the standard Debian/Ubuntu repositories:

pdfposter -mA1 poster_a0.pdf poster_a1.pdf
	
PDFPoster also allows you to easily print out a large poster onto smaller sheets.

Lastly, you can also use GhostScript, which isn't very user friendly, but has many options:

gs -sPAPERSIZE=a1 -sDEVICE=pdfwrite -dFIXEDMEDIA -dPDFFitPage \
 -dCompatibilityLevel=1.4 -o poster_a1.pdf  poster_a0.pdf