Ghostscript: quality and size issue

I have a ghostscript command that converts PDF to multiple PNG images (one for each page). The arguments of the command 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" 

PDF is displayed like regular A4 pages in Adobe Reader, but in PNG images it becomes huge (for example, 2480 by 3507 pixels).

if I changed the resolution in the ghostscript command to -r110 , the page size is correct, but the image quality is very rasterized.

Is there any other way to improve image quality without affecting image size?

thanks

+4
source share
4 answers

Got! The following parameter has been added to the GS command:

 -dDownScaleFactor=3 

From the GS documentation :

This leads to a decrease in the internal rendering (small integer) coefficient before the output. For example, the following will generate a 200ppi png output from 300dpi internal rendering:

  gs -sDEVICE=png16m -r600 -dDownScaleFactor=3 -o tiger.png\ examples/tiger.png 
+10
source

A compromise in quality is inevitable. You can choose another compression to keep the size down while maintaining reasonable quality. For instance. DCT (jpeg) or jpeg2000 if your content is mainly composed of photographic images or CCITT or JBIG2 if your content is mostly black and white.

+1
source

I had a similar problem when converting PDF to PNG using ghostscript resulted in a much larger image (including extra free space). I solved the problem using

 -dUseCropBox 

... which sets the page size in CropBox, not in MediaBox

+1
source
  • find the width and height in points (%% BounDingBox)
  • use them

     gs -sDEVICE=png16m -dDEVICEWIDTHPOINTS=$l -dDEVICEHEIGHTPOINTS=$h -r600 -dDownScaleFactor=3 -o tiger.png\ examples/tiger.png 

where $w is the width and $h height

+1
source

Source: https://habr.com/ru/post/1492725/


All Articles