I want to generate PDF to Jpeg image with a width of 900px and 150 dpi with the help of Ghostscript rasterizer.
-
The problem you have is that the width and the density are dependent. One either specifies the width or the DPI. – user3344003 Mar 03 '19 at 02:26
-
@user3344003: Is there any way, In which we can define dpi along with height or width. – Dinesh Gouttam Mar 04 '19 at 10:06
1 Answers
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.

- 30,202
- 3
- 34
- 51