Convert PDF to images

When I wanted to read a PDF on my old phone, I always had to convert the files to images. The same commands I used back then also turned out to be useful for converting PDFs of scanned books into lighter images and building a new PDF to read on the iPhone.
Here I show four different ways to do the conversion. I prefer imagemagick.
PDF to Image
Imagemagick
Install imagemagick.
julio@julio-acer ~> convert documento.pdf imagem.jpg
High definition: convert -density 400 file.pdf -scale 2000x1000 hi-res%03d.jpg
For the iPhone: convert livro.pdf -density 72 -quality 75 -scale 640x960 -colors 96 livro%03d.jpg
For each page it generates an image and names it livro001.jpg, livro002 and so on.
PPM
Install pdftoppm and ppmtojpeg.
ppm documento.pdf imagem.ppm
You can use -f first_page -l last_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=imagem.jpg documento.pdf
Gimp
The best result I got for the old phone was to open the PDF as images in gimp and save them as .bmp. I still need to work out how to automate this process.
Image to PDF
convert *jpg livro.pdf
If the file comes out too big, try the -compress option
convert -compress jpeg *jpg livro.pdf
Links

I’m a Brazilian-German computer engineer based in Germany, passionate about tech, science, photography, and languages.
I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.
I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, serving on the PSF D&I Work Group, mentoring, and contributing code and translations.
On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.
Browse my gallery for some of my photography.
Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.
Always happy to connect! 🙂