Manipulating pdf with Linux commandline tools

Few useful tips for manipulating pdf files. Useful if you just want to change few files without installing fancy software with GUI or if you want to make batch jobs.

  • Merge multiple pdf files into one pdf file

Can be done with pdfunite tool (package: poppler-utils)

pdfunite inputfileX.pdf inputfileY.pdf inputfileZ.pdf Outputfile.pdf

Merging can be done also with pdftk (package: pdftk )

pdftk inputfileX.pdf inputfileY.pdf inputfileZ.pdf output Outputfile.pdf
  • Split pdf file into pages

This will split input pdf – stores each page into separate file named pg_0001.pdf, pg_0002.pdf, etc.

pdftk inputfileX.pdf burst

This will split input pdf – stores each page into separate file named page_0001.pdf, page_0002.pdf, etc.

pdftk inputfileX.pdf burst output page_%04d.pdf

This will split input pdf and stores only specific pages into single new file.

pdftk inputfileX.pdf cat 1 2 3 4 9 10 output Outputfile.pdf
or
pdftk inputfileX.pdf cat 1-4 9-10 output Outputfile.pdf
  • Rotate pdf file

Use pdftk. From pdftk man page: Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page’s rotation.

This will rotate only page one 90 degrees, page two 270 degrees and leaves all other pages unchanged.

pdftk inputfileX.pdf rotate 1east 2west output Outputfile.pdf

This will extract specific pages, rotates them and stores them in different order (4-3-2-1) into single new file.

pdftk inputfileX.pdf cat 4east 3south 2west 1left output Outputfile.pdf

This will rotate entire input document 90 degrees clockwise .

pdftk inputfileX.pdf cat 1-endright output Outputfile.pdf
or
pdftk inputfileX.pdf rotate 1-endright output Outputfile.pdf

 

If you found this useful, say thanks, click on some banners or donate, I can always use some beer money.

Leave a Reply

Your email address will not be published. Required fields are marked *