Some ghostscript snippets
PDF Conversion
Merge PDF Files
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="merged_file.pdf" -dBATCH file1.pdf file2.pdf ... fileN.pdf
Split PDF Files
yes | gs -dBATCH -sOutputFile="output.pdf" -dFirstPage=100 -dLastPage=105 -sDEVICE=pdfwrite "INPUT.pdf" >& /dev/null
Alternative ‘convert‘
Using convert it is easier to extract multiple page ranges from the PDF. But it had a really bad output quality the at least last time I tried it out.
convert file1.pdf[0] file2.pdf[0-1,3] output.pdf
Strip Down Size/Quality
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Where -dPDFSETTINGS can be one of
-dPDFSETTINGS=/screen --> low quality
-dPDFSETTINGS=/ebook --> medium quality
-dPDFSETTINGS=/prepress --> full quality