I'm using GPL Ghostscript 9.07 (2013-02-14) on OS X (10.8.4) to convert many PDFs to PNGs.
It works fine except for one of the PDFs which turns into a PNG with jagged edges. In other words, Ghostscript turns off antialiasing for that particular PDF for some reason.
The PDF in question.
The output:
In other cases it works fine (sample: pdf -> png).
I use this command:
gs -dNOPAUSE -dBATCH -dPDFFitPage -sDEVICE=pngalpha -g200x150 -sOutputFile=01.png 01.pdf
Is it possible to force Ghostscript to use antialiasing for that PDF?
Any tips are appreciated.
This worked for me:
gs -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r150 -sOutputFile=foo-%d.jpg foo.pdf
Source: ImageMagick convert pdf to jpeg has poor text quality after upgrading ImageMagick version to 6.7.8
The above would work for a JPG; for PNG, replace the -sDEVICE
option with your choice, example: -sDEVICE=png16m
Source: http://ghostscript.com/doc/current/Devices.htm
You can try -dGraphicsAlphaBits= with values 1,2 or 4 which may or may not make a difference. It made some improvement for me, but its a small graphic at low resolution with an awkward curve, so not so much as might be expected.
Or you can use one of the anti-aliasing devices (eg tiffscaled) which are more flexible. There is no anti-aliased device for PNG output but it would be trivial to convert TIFF to PNG.
By the way, your PDF file specifically turns off anti-aliasing on the components:
8 0 obj
<</AntiAlias false/ColorSpace/DeviceCMYK/Coords[0.0 0.0 1.0 0.0]/Domain[0.0 1.0]/Extend[true true]/Function 10 0 R/ShadingType 2>>
You might like to try and see what happens if you change AntiAlias to true, though I doubt this will have an effect as I'm pretty sure the aniti-aliasing is applied to the internal rendering of the shading, not the edgses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With