How to convert pdf to image on Linux command line

There are several ways to convert a PDF to an image on the Linux command line. One popular tool is “ImageMagick”. You can install it by running the command:

sudo apt-get install imagemagick

Once ImageMagick is installed, you can use the “convert” command to convert a PDF to an image. Here’s an example command that converts a PDF called “example.pdf” to a JPEG image called “example.jpg”:

convert example.pdf example.jpg

You can also specify the format, resolution, and page range of the output image by using options like “-density”, “-quality”, and “-page”. For example, to convert the first page of a PDF to a PNG image with 300 DPI resolution, you can use the following command:

convert -density 300 -quality 100 -page 1 example.pdf example.png

You can also convert all pages of a pdf to multiple images by using a loop in a shell script.

for i in {1..10}; do convert -density 300 -quality 100 -page $i example.pdf example-$i.png; done

This command will convert all the pages of pdf “example.pdf” and save them with names example-1.png, example-2.png and so on.

You can also use other tools like “gs” (Ghostscript) to convert PDF to images as well.

gs -sDEVICE=jpeg -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1 -dLastPage=1 -sOutputFile=example.jpg example.pdf

This command will convert the first page of the pdf “example.pdf” to a jpeg image “example.jpg”

Leave a Comment