Ghostscript to the Rescue ========================= Ghostscript is a powerful command-line tool for manipulating PDF documents. Here are a few useful commands that come in handy for everyday work. Append a Single PDF to an Existing PDF -------------------------------------- #!/bin/bash gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \ -sOutputFile=final.tmp.pdf \ original.pdf single.pdf \ && mv final.tmp.pdf final.pdf Compress a PDF Using the "ebook" Output Profile ----------------------------------------------- #!/bin/bash gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dPDFSETTINGS=/ebook \ -dNOPAUSE -dQUIET -dBATCH \ -sOutputFile=compressed.pdf \ original.pdf Sort PDF Files Alphabetically and Merge Them -------------------------------------------- #!/bin/bash gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite \ -sOutputFile=merge_all.pdf \ $(printf "%s\n" *.pdf | sort) Notes ----- The first example appends a PDF to an existing document. The second example reduces the file size by using Ghostscript's "ebook" profile, which provides a good compromise between image quality and compression. The third example sorts all PDF files in the current directory alphabetically before merging them into a single document.