PDFtk has a command-line tool for working with PDFs. It's fantastic for saving out single pages or combining files.
Ghostscript also has good features for PDFs, including being able to reduce the file size while preserving links and bookmarks.
# Combine several PDFs into 1
pdftk first.pdf second.pdf third.pdf fourth.pdf cat output combined.pdf
The burst
option will save pages individually. Use %d
to include the page number.
# Save as burst
pdftk full.pdf burst output about-%d.pdf
# Save a single page
pdftk infile.pdf cat 7 output page7.pdf
The following script will save 1 page and convert it to a PNG.
It requires the convert
command from ImageMagick.
# Set variables
in=infile.pdf
out=outfile
page=123
# Select out PDF page
pdftk ${in} cat ${page} output ${out}.pdf
# Create a high-res PNG with correct coloration on white background
# Remove '-flatten' for transparent image
convert -density 600 -colorspace sRGB -flatten \
${out}.pdf ${out}.png
This single ghostscript command brought my dissertation from 339.3 MB to 76.2 MB without sacrificing quality.
# Reduce PDF size
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH \
-sOutputFile=outfile.pdf infile.pdf