Reputation: 3660
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
Upvotes: 12
Views: 23880
Reputation: 349
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
Upvotes: 3
Reputation: 3660
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
Upvotes: 16
Reputation: 21
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
the height
Upvotes: 2
Reputation: 3738
The quality-size tradeoff is inevitable. You may choose a different compression to keep size down while maintaining reasonable quality. E.g. DCT (jpeg) or jpeg2000 if your content mainly consists of photographic images or CCITT or JBIG2 if your content is mainly black and white.
Upvotes: 2