Ghostscript Converting PDF to PNG With Wrong Output Size

Ghostscript Converting PDF to PNG With Wrong Output Size,pdf,png,ghostscript,image-conversion,Pdf,Png,Ghostscript,Image Conversion,I'm using the following Ghostscript command to convert an 8.5" x 17.00" (2:1) PDF to a PNG: gswin32c.exe -sDEVICE=png16m -sNOPAUSE -sOutputFile="C:\output.png" -r120 -q -dBATCH "C:\input.pdf" This command has worked well for me in the past, but with a given set of input PDFs it is adding whitespace to the bottom of the outputted PNG. The PNGs are coming out at 1080x2460 (18:41). I also tried sDEVICE=pngalpha and it had the same result. The image below shows the source PDF on the left, and t

I'm using the following Ghostscript command to convert an 8.5" x 17.00" (2:1) PDF to a PNG:

gswin32c.exe -sDEVICE=png16m -sNOPAUSE -sOutputFile="C:\output.png" -r120 -q -dBATCH "C:\input.pdf"

This command has worked well for me in the past, but with a given set of input PDFs it is adding whitespace to the bottom of the outputted PNG. The PNGs are coming out at 1080x2460 (18:41).

I also tried sDEVICE=pngalpha and it had the same result.

The image below shows the source PDF on the left, and the output PNG on the right:

enter image description here

Can anyone tell me what might cause this?


#1

Thanks the comments by @KenS, and this SO question, I learned of these Ghostscript flags:

-dUseTrimBox
-dUseCropBox
-dUseArtBox
-dPDFFitPage

When I include -dUseCropBox in the command, it works correctly:

gswin32c.exe -sDEVICE=png16m -dUseCropBox -sNOPAUSE -sOutputFile="C:\output.png" -r120 -q -dBATCH "C:\input.pdf"

Source: Obey the MediaBox/CropBox in PDF when using Ghostscript to render a PDF to a PNG


#2

Most likely the PDF has a TrimBox or CropBox and you have not asked GS to use it. Its impossible to say wihtout seeing the PDF file, the PNG doesn't help.

#3

Thank you @KenS. I will check with the folks who prepared the PDFs.

#4

You can't use both of them, they are mutually exclusive, you can use either the TrimBox (-dUseTrimBox) or the CropBox (-dUseCropBox). You shouldn't set both.....