Ghostscript is a suite of software based on an interpreter for Adobe Systems’ PostScript and Portable Document Format (PDF) page description languages.
It can be used to merge PDF files or extract specific pages from a PDF file from the command line in Linux (Ubuntu) without loosing the quality.
Install ghostscript by entering the following commands in the terminal:
$ sudo apt update $ sudo apt install ghostscript
Cool Tip: Merge PDF files in Linux using the convert command! Read more →
Merge PDF Files
Execute the following command to merge two PDF files FILE1.pdf and FILE2.pdf and save the result to OUTPUT.pdf:
$ gs -dBATCH \
-dNOPAUSE \
-q \
-sDEVICE=pdfwrite \
-sOutputFile=OUTPUT.pdf \
FILE1.pdf FILE2.pdf
Extract the first page from the FILE.pdf and save it to OUTPUT.pdf:
$ gs -dBATCH \
-dNOPAUSE \
-q \
-sDEVICE=pdfwrite \
-dFirstPage=1 \
-dLastPage=1 \
-sOutputFile=OUTPUT.pdf \
FILE.pdf
Extract the range of pages from 5 to 10:
$ gs -dBATCH \
-dNOPAUSE \
-q \
-sDEVICE=pdfwrite \
-dFirstPage=5 \
-dLastPage=10 \
-sOutputFile=OUTPUT.pdf \
FILE.pdf
Cool Tip: Split PDF files in Linux using the pdftk command! Read more →
It worked like a breeze. Thanks.