1

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?

Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
  • 1
    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. – KenS Jul 03 '16 at 16:08
  • Thank you @KenS. I will check with the folks who prepared the PDFs. – Chris Schiffhauer Jul 03 '16 at 17:02

1 Answers1

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

Community
  • 1
  • 1
Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
  • 1
    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..... – KenS Jul 03 '16 at 20:19