PDF Manipulation in GhostScript

GhostScript is incredibly powerful tool for manipulating many different document formats, among others also PDF.

Yet, its cryptic command format makes it sometimes hard to get something done; but most of the operations can be simply done by template.

Merging PDF Files

Most often, I need to merge few PDF files into a single file.

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH file1.pdf file2.pdf ...

This merges files file1.pdf, file2.pdf, … into a single output.pdf.

-dNOPAUSE means that gs won’t stop along the way to ask you questions, like “do you want to continue?”.

Cutting PDF Files

Are you interested only pages 50 through 60 of the my_file.pdf document?

gs -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=my_cut_file.pdf \
    -dFirstPage=50 -dLastPage=60 -dBATCH my_file.pdf

Converting PostScript (or anything else) to PDF

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH my_file.ps

GhostScript actually supports incredible array of formats; to check what all you can work with, just run

echo 'devicenames == ' | gs -q | tr " " "\n" | sort

2 responses to “PDF Manipulation in GhostScript

  1. Pingback: Manipulasi dokumen PDF dengan Ghostscript (1) « [go2n@buglink:~] $

  2. Pingback: Manipulasi dokumen PDF dengan Ghostscript (2) « [go2n@buglink:~] $

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s