PDF files manipulation

1 minute read

To extract pages out of a PDF file, run the following command:

1user $ gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=<PAGE_NUMBER_START> -dLastPage=<PAGE_NUMBER_STOP> -sOutputFile=<OUTPUT_FILE> <INPUT_FILE>

How to merge PDF files?

Ghostscript

A simple Ghostscript command to merge several PDFs in a single file is shown below:

1user $ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=<OUTPUT_FILE.pdf> -dBATCH <INPUT_FILE_1.pdf> <INPUT_FILE_2.pdf> [<INPUT_FILE_3.pdf>] ...

How to split a PDF file in separate pages

To extract each page of a PDF file in a separate PDF file:

1user $ gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=assurance0%d.pdf 4242_001.pdf

How to add a pdf page at a give place in another pdf document

This example shows how a page (page.pdf) will be added right after the first page of the first document (document.pdf).

This means that if document.pdf was 6 pages, after this manipulation, it will be 7 pages, given that page.pdf is only one page long:

1pdftk A=document.pdf B=page.pdf cat A1 B A2-end output output.pdf