Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ghostscript: Quality and Size issue

I have a ghostscript command that converts a pdf into several PNG images (one for every page). The command arguments are as follows:

-dNOPAUSE -q -r300 -sPAPERSIZE=a4 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseTrimBox -sDEVICE=png16m -dBATCH -sOutputFile="C:\outputfile%d.png" -c \"30000000 setvmthreshold\" -f "C:\inputfile.pdf"

The pdf displays as regular A4 pages in Adobe Reader, but in the PNG images it becomes huge (2480 by 3507 pixels for instance).

if I change the resolution in the ghostscript command to -r110 the page size is correct but the image quality is very rastorized.

Is there another way to improve the quality of the image without affecting the image size?

Thanks

like image 913
hofnarwillie Avatar asked Jul 22 '13 14:07

hofnarwillie


2 Answers

Got it! Added the following parameter to my GS command:

-dDownScaleFactor=3

From the GS documentation:

This causes the internal rendering to be scaled down by the given (small integer) factor before being output. For example, the following will produce a 200dpi output png from a 300dpi internal rendering:

 gs -sDEVICE=png16m -r600 -dDownScaleFactor=3 -o tiger.png\
      examples/tiger.png
like image 158
hofnarwillie Avatar answered Sep 28 '22 06:09

hofnarwillie


I had a similar problem, where PDF conversion to PNG using ghostscript resulted in an image with much greater dimensions (including extra white space). I solved the issue by using

-dUseCropBox

... which sets the page size to the CropBox rather than the MediaBox

like image 24
Kappa Avatar answered Sep 28 '22 06:09

Kappa