Manipulation of .pdf files

Some useful command for manipulating .pdf files.

Compress

There are plenty of online pdf compressor. But for safety, it is better to perform it in our own PC. Here, I use Ghostscript. It is usually already included in the linux package, just to make sure, you can try installing:

$ sudo apt install ghostscript

And then run the following to compress your pdf file:

$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed_PDF_file.pdf input_PDF_file.pdf

Passwording

Sometimes, password has to be made for pdf files. Here, I use pdftk. For installation:

$ sudo apt-get install pdftk

Then use the following command to add a password to the existing input.pdf file and output it as ouput.pdf:

$ pdftk <input>.pdf output <output>.pdf userpw <password>

Merging

I use pdftk to merge multiple pdf files. Use the following command to merge existing input1.pdf and input2.pdf files and output it as ouput.pdf:

$ pdftk <input1>.pdf <input2>.pdf cat output <output>.pdf

Splitting

Using pdftk to split pdf file as follows:

$ pdftk <input1>.pdf cat <from page number>-<to page number> output <output>.pdf