2 Ghostscript
Ghostscript is useful tool to manipulate PDFs, PostScript, and other file formats. Ghostscript needs to be installed in your system before using it. To check whether it is installed, issue this command from a Terminal
gs --version
There are several ways to install it (e.g., brew, from https://www.ghostscript.com/index.html, etc.) in case you need it.
2.1 Bounding box
Find the bounding box of a ps/pdf file
gs -sDEVICE=bbox -dNOPAUSE -dBATCH file
##Convert a batch of PDF to PS files
for f in *.pdf;
do
gs -sDEVICE=ps2write -dNOPAUSE -dBATCH -sOutputFile=./psFigures/$f.ps $f;
done
2.2 Convert a batch of PDFs into JPGs
for i in *.pdf;
do
gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r144
-sOutputFile=./converted/$(basename $i .pdf).jpg $i;
done
2.3 Merge and compress PDFs in a directory
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=out.pdf *.pdf
2.4 Make a smaller file (in kB)
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH
-sOutputFile=compressed.pdf input.pdf
Make the pdf even smaller at 150 DPI:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/ebook
-sOutputFile=compressed.pdf input.pdf