4

I'm trying to convert a PDF file to images on the fly using imagemagick from command line. These PDFs are in very high definition and I would like to get correlated images (JPG).

Usually used Gimp, when I convert these PDF to 600dpi under this software the quality is super top. But I do not see myself convert more than 500 images one by one with Gimp ... that's why I turn to ImageMagick, especially since converting image files on the fly happens to me more and more often, I would like to master this type of tool.

Alas, with ImageMagick, by default I get very small images (type 468x705), despite the setting of a density at 600dpi:

convert *.pdf -density 600 -quality 100 *.jpg

So I added a resize command (I also tried scale), the image is much higher definition (type 4680x7050), but is pixelated as if I had remained at the default definition:

convert *.pdf -resize 1000% -density 600 -quality 100 *.jpg

I even thought it could come from the order of orders, but that does not change anything:

convert *.pdf -density 600 -resize 1000% -quality 100 *.jpg

An idea ?

Subsidiary (but less crucial) question: how to keep the same name for the destination file as the original one?

EDIT : In addition to the for loop proposed by Mark Setchell I just discovered that you can use mogrify. Example:

mogrify -format jpg -density 600 -blur 1x1 -quality 100 *.pdf

Olivier C
  • 899
  • 1
  • 13
  • 14

1 Answers1

6

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thank you very much. So I found a setting quite similar to that of Gimp by adding `-blur 1x1` – Olivier C Aug 03 '17 at 18:24
  • I had to use mogrify with -density 600 -blur 1x1 -quality 100 options to get a good quality output. The flags listed in this answer were not enough. – poleguy Aug 16 '21 at 14:13