Klanto Aguntuk
Klanto Aguntuk

Reputation: 719

Converting PDF files at a given density when page parameter is set - ImageMagick

If the page parameter is set, conversion of PDF files at a given density outputs blank pages.

"convert -units PixelsPerInch -density 300  $myfiles -page A4  -gravity center test.pdf"

If I omit page parameter from the command, I get appropriate output but at 72dpi default resolution.

Any idea?

Upvotes: 0

Views: 1102

Answers (2)

Klanto Aguntuk
Klanto Aguntuk

Reputation: 719

While I was trying to tweak the command I found that a set density (i.e, density 300) with a given page parameter actually sets the density of the -page A4 but not the converted object on page as the set density can't actually determine resolution of the -page A4 to which it shall be applicable. As a result, the command returns blurry or blank image on set page.

However, extent parameter is what, which actually outputs the appropriate image as it is possible to set the page resolution with this parameter at a predefined density. The following example will make it absolutely clear.

Resolution of A4 size page at 300 dpi is 2480x3508, thus correct command for a set density like 300 dpi shall be:

"convert -units PixelsPerInch -density 300 $myfiles -gravity center -extent 2480x3508 test.pdf"

Resolution of A4 size page at 72 dpi is 595x842, thus correct command for a set density like 72 dpi shall be:

"convert -units PixelsPerInch -density 72 $myfiles -gravity center -extent 595x842 test.pdf"

Upvotes: 0

fmw42
fmw42

Reputation: 53091

A4 page size is 595 x 842. So in ImageMagick you could try

convert -units PixelsPerInch -density 300 $myfiles +repage -resize 595x842  test.pdf

That will make an A4 pixel dimension image with 300 dpi. You could also do

convert -units PixelsPerInch -density 300 $myfiles +repage -resize 595x842  -density XX test.pdf

Where XX is the dpi you want when printing the image of that size.

I added +repage to remove any input image virtual canvas, since you did not specify what format images you are using for $myfiles. Without +repage, that could have caused a large bit of white space at the top of your result.

Note it is always best and most helpful to provide your ImageMagick version and platform when asking questions about its use.

Upvotes: 0

Related Questions