Forcing Ghostscript to use anti-aliasing when converting PDF to PNG?

I am using GPL Ghostscript 9.07 (2013-02-14) for OS X (10.8.4) to convert many PDF files to PNG.

It works great, with the exception of one of the PDF files, which turns into PNG with jagged edges. In other words, Ghostscript for some reason disables anti-aliasing for this particular PDF file.

This pdf file .

Exit:

enter image description here

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 anti-aliasing for this PDF?

Any advice is appreciated.

+7
image-processing pdf ghostscript antialiasing
source share
3 answers

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 to 6.7.8

The above will work for JPG; for PNG, replace the -sDEVICE option of your choice, for example: -sDEVICE=png16m

Source: http://ghostscript.com/doc/current/Devices.htm

+6
source share

You can try -dDOINTERPOLATE , which uses the Mitchell filter function to scale the contributions for each output pixel.

+2
source share

You can try -dGraphicsAlphaBits = with values ​​of 1,2 or 4, which may or may not matter. This made some improvement for me, but its small graphics with low resolution with an uncomfortable curve, so not as much as you might expect.

Or you can use one of the smoothing devices (e.g. tiffscaled), which are more flexible. There is no smoothed device for PNG output, but it would be trivial to convert TIFF to PNG.

By the way, your PDF specifically disables component anti-aliasing:

 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 want to try and see what happens if you change AntiAlias ​​to true, although I doubt it will have an effect, as I am sure that the anti-aliasing applies to the internal rendering of the shader, not the edges.

+1
source share

All Articles