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?

2
  • 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. Commented Jul 3, 2016 at 16:08
  • Thank you @KenS. I will check with the folks who prepared the PDFs. Commented Jul 3, 2016 at 17:02

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.