How to Convert a PDF into Jpg with Command Line in Linux

How to convert a PDF into JPG with command line in Linux?

You can try ImageMagick's convert utility.

On Ubuntu, you can install it with this command:

$ sudo apt-get install imagemagick

Use convert like this:

$ convert input.pdf output.jpg
# For good quality use these parameters
$ convert -density 300 -quality 100 in.pdf out.jpg

Convert PDF to image with high resolution

It appears that the following works:

convert           \
-verbose \
-density 150 \
-trim \
test.pdf \
-quality 100 \
-flatten \
-sharpen 0x1.0 \
24-18.jpg

It results in the left image. Compare this to the result of my original command (the image on the right):

  

(To really see and appreciate the differences between the two, right-click on each and select "Open Image in New Tab...".)

Also keep the following facts in mind:

  • The worse, blurry image on the right has a file size of 1.941.702 Bytes (1.85 MByte).
    Its resolution is 3060x3960 pixels, using 16-bit RGB color space.
  • The better, sharp image on the left has a file size of 337.879 Bytes (330 kByte).
    Its resolution is 758x996 pixels, using 8-bit Gray color space.

So, no need to resize; add the -density flag. The density value 150 is weird -- trying a range of values results in a worse looking image in both directions!

ImageMagick command line: converting PDF to high definition images

You probably want something like this - note that you put the -density before the PDF filename:

for f in *.pdf; do convert -density 144 "$f" "${f%pdf}jpg"; done

The tricky part is removing the pdf extension and replacing it with jpg, I used "bash Parameter Substitution" which is pretty well described here.


In long-hand, that is

for f in *.pdf; do 
convert -density 144 "$f" "${f%pdf}jpg"
done

Another option is with mogrify:

mogrify -density 144 -format jpg *pdf

If you have GNU Parallel installed, you can do it more readably and faster like this:

parallel convert -density 144 {} {.}.jpg ::: *pdf

Convert multi PDF document to several Image files

You should be able to convert multipage PDF files into multiple JPEGs (one file per page) easily when using convert.

Here is a command to process just pages 1--5:

convert PDF32000_2008.pdf[0-4] page-%d.jpg

([0-4] means pages 1--5. The page indexing is 0-based!)

However, this does not give you much control about the resulting quality. The only thing you can add is -density 150 or -density 300 to increase the resolution of your images. (convert by default uses -density 72 which is 72 PPI.)

Also, be aware that ImageMagick is not able to process PDFs all by itself. It employs Ghostscript as its 'delegate' to handle PDF files. You can see this if you add -verbose to your command line:

convert -verbose -density 200 ~/Downloads/PDF32000_2008.pdf[0-4] page-%d.jpg
[....]
[ghostscript library] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT \
-dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 \
"-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
"-r200x200" -dFirstPage=1 -dLastPage=5 \
"-sOutputFile=/var/tmp/magick-63898lc1DhZVuD6lu%d" \
"-f/var/tmp/magick-63898h8-BZJ59LyhQ" \
"-f/var/tmp/magick-638989MxSe0EALH5F"

So in many cases where you want to convert PDF pages to images it has advantages to run Ghostscript directly...

How can I convert a series of images to a PDF from the command line on Linux?

Using ImageMagick, you can try:

convert page.png page.pdf

For multiple images:

convert page*.png mydoc.pdf

Convert PDF to JPG or PNG using C# or Command Line

The convert tool (or magick since version 7) from the ImageMagick bundle can do this (and a whole lot more).

In its simplest form, it's just

convert myfile.pdf myfile.png

or

magick myfile.pdf myfile.png

Print PDF as image from command line?

Unfortunately for you, the answer is "No!". Printing PDF pages as an image is only available through the GUI in Acrobat Reader.

To see a list with all available options, run this:

acroread -help

To see an explanation for all the available options, run this:

man acroread

(I assume you are using acroread on Linux or Unix. Because on Windows, you'd have even less CLI options for it... and some incomplete documentation of which is here.)



Related Topics



Leave a reply



Submit