convert a multi page pdf to a single image

July 12, 2010

Task at hand was to convert a 110 page PDF to an image format. JPEG or PNG would do. Solution was to use the powerful convert command from the imagemagick suite of tools. Here is how.

First install imagemagick $ sudo apt-get install imagemagick

Next convert your PDF to JPEG (1 PDF page per JPEG image) using %04d with the destination filename which will force convert to create filenames that contain 4 decimals with leading 0′s counting upwards from 0 (eg; document_0000,jpg, document_0001.jpg, document_0002.jpg)

$ convert document.pdf document_%04d.jpg

Finally use convert to append all JPEG images into a single image. $ convert document_0*.jpg -append document.jpg

If you get an error with the amount of pixels the final JPEG image contains, you will need to use another image format. JPEG only allows a maximum of 65500 pixels for width or height.

$ convert document_0* -append document.jpg convert: Maximum supported image dimension is 65500 pixels `document.jpg’ @ jpeg.c/EmitMessage/232.

Try using GIF or PNG if you do get this error though do keep in mind these are lossless image formats so the filesize of the final image can be quite large.

$ convert docuent_0* -append document.png

Previous post:

Next post: