Convert PDF to Images

When I wanted to read a PDF on my old cell phone, I always had to convert the files to images. The same commands I used back then also proved useful for converting scanned book PDFs into lighter images and creating a new PDF to read on the iPhone.

Here I show how to do the conversion in 4 different ways. I prefer using imagemagick.

PDF to Image

Imagemagick

Install imagemagick.

julio@julio-acer ~> convert document.pdf image.jpg

High definition: convert -density 400 file.pdf -scale 2000x1000 hi-res%03d.jpg

For iPhone: convert book.pdf -density 72 -quality 75 -scale 640x960 -colors 96 book%03d.jpg

For each page, it generates an image and names it as book001.jpg, book002, and so on.

PPM

Install pdftoppm and ppmtojpeg.

ppm document.pdf image.ppm

You can use -f start_page -l end_page to convert only a range.

PPM = portable pixmap file format

To convert, we use:

for file in *.ppm; do ppmtojpeg $file > ${file/.ppm/.jpg}; rm $file; done

Ghostscript

gs -sDEVICE=jpeg -sOutputFile=image.jpg document.pdf

Gimp

The best result I achieved for the old cell phone was to open the PDF as images in Gimp and save as .bmp. I need to figure out how to automate this process.

Image to PDF

convert *jpg book.pdf

If the file becomes too large, try using the -compress option

convert -compress jpeg *jpg book.pdf

Julio Batista Silva
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus