1

I am using the following command to convert the first page of a pdf to a png:

convert -density 200 "somePdf.pdf[0]" -size 500 "newImage.png" But the output image size is not 500 pixels wide (it comes to over a 1000 pixels wide).

How do I define a specific output size?

RobKohr
  • 6,611
  • 7
  • 48
  • 69

3 Answers3

2

You just use -density. In your Imagemagick command, don't use -size, and don't use -geometry. The density is what controls the output. Default PDF will use 72 dpi. So that is natural size for the dimensions converted from inches. If you want a specific size, make the density larger than needed and then use -resize.

convert  -density 288 "somePdf.pdf[0]" -resize 500x "newImage.png"
fmw42
  • 46,825
  • 10
  • 62
  • 80
0

You don't use size. You use geometry:

convert -density 200 "somePdf.pdf[0]" -geometry 500 "newImage.png"

This will specify the output width. You can also use -geometry 500x1000 to specify a specific width and height.

RobKohr
  • 6,611
  • 7
  • 48
  • 69
0

PDF does not concern itself with density or resolution just width and height. So to extract a page as image you say extract 594 wide page as 594 points 210 mm or 8.25 inches and its as perfect as the source ratios. ImageMagick does not convert PDF it passes the command on and its easier to use GS and several methods including GS support answer https://stackoverflow.com/a/10024458/10802527

If you wish to modify the returned pdf output as a different image you use IM convert to suite your taste but its not as accurate or clear as using pdftopng or better extract scanned pages as source dimensions then rescale

K J
  • 8,045
  • 3
  • 14
  • 36