How to set dpi for Jpeg when converting ghostscript rasterizer

765 Views Asked by At

I want to generate PDF to Jpeg image with a width of 900px and 150 dpi with the help of Ghostscript rasterizer.

1

There are 1 best solutions below

0
On

You can set the size of the image in 2 ways; firstly if you know the size of the PDF media (the MediaBox), which is in the PDF file, and is in PostScript units (1/72 of an inch) then a simple calculation will give you the required rendering resolution:

target X resolution = output width in pixels / (Media width / 72)

target Y resolution = output height in pixels / (Media height / 72)

You can then set the resolution using the -r switch as described in the documentation here

Alternatively you can set the output media size in pixels using the -g switch, and then use the -dPDFFitPage switch to have Ghostscript scale the PDF content so that it fits into the output. Note that this method scales isomorphically. That is the same scale factor is applied to both the x and y directions.

The -g switch is described in the documentation here and the -dPDFFitPage switch is described here.