Life and code.
RSS icon Home icon
  • Useful PDF ImageMagick Recipes

    Posted on May 6th, 2009 Brian No comments

    It turns out that ImageMagick is really quite good at reading, writing, re-arranging, and otherwise mucking with PDFs.  Unfortunately, you need to know the proper incantation, which can take much trial and error to figure out.  So, for my own future reference:

    Split A PDF Into Parts

    $ convert -quality 100 -density 300x300 multipage.pdf single%d.jpg

    The quality parameter is the quality of the written JPEGs, and the density is the DPI (in this case, 300 DPI in both X and Y).

    Join JPEG Parts Into A PDF

    $ convert -adjoin file*.jpg doc.pdf

    Rotate a PDF

    $ convert -rotate 270 -density 300x300 -compress lzw in.pdf out.pdf

    This assumes a TIFF-backed PDF. The density parameter is important because otherwise ImageMagick down-samples the image (for some reason). Adding in the compression option helps keep the overall size of the PDF smaller, with no loss in quality.

    Now, if I can just figure out how to make future me remember to look here…