[gs-devel] Yet another problem converting transparent PDF to transparent PNG

Chris Liddell chris.liddell at artifex.com
Tue Aug 2 08:56:51 UTC 2011


You can't - it's that simple.

Note that there is really no such thing as a "transparent PDF", rather
there are PDF files which contain transparency operations. The PDF
imaging model is defined as rendering to an opaque back drop.


Having said that, the pngalpha device bends that slightly, but there is
an incompatibility between Ghostscript's implementation of PDF
transparency and pngalpha's implementation which means that "bending" of
the imaging model doesn't work.

Basically, each transparency group (including its backdrop) becomes a
single marking operation, so ultimately, the page group is the final
marking operation which, by implication, covers the entire page.

The marking operation representing the entire page group is what the
pngalpha device receives and writes to the output file.

Having said that, recent internal changes in Ghostscript should mean
that the "infrastructure" is in place to to have pngalpha work as you
want, but no time has been available (or looks like being available for
a while) to have the device take advantage of it.

BTW, I could find no way to get Acrobat to emit a png with a transparent
backdrop - the png Acrobat 9.x produces for me looks like the one
Ghostscript currently produces, so from that point of view, we currently
do match the de-facto PDF benchmark.


For what it's worth, a much better way to represent what you are trying
to create with that file would be to make your image a monochrome (1
bit) image, and draw it as an imagemask (not using PDF transparency at
all) - the rendering will be quicker, and you should get the png with
transparency backdrop that you want.

Chris


On 02/08/11 08:46, ansgar wrote:
> 
> Hi all,
> 
> I'm struggling with a imo correct transparent PDF (works pretty in Acrobat,
> PhotoShop...) converting in a hopefully equally transparent PNG, but the
> PNG-background still remains white. 
> 
> With "Dr. Googles" help i tripped over some interesting workarounds in order
> to convert the white background after GhostScript into real transparency
> with ImageMagik. But sadly those workarounds don't work for me, 'cause of
> ImageMagik dully converts all white pixels into transparency, whether
> formerly transparent in PDF or not.
> 
> So, I'm asking for help to convert my PDF effectively only with GhostScript
> into a transparent PNG.
> 
> The GhostScript command I'm using is:
> gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha -dFirstPage=1 -dLastPage=1 -r72x72
> -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseCIEColor
> -sOutputFile=output.png input.pdf
> 
> My input.PDF is located at:
> http://www.webknack.de/ghostscript/input.pdf
> 
> The output.PNG can be seen here:
> http://www.webknack.de/ghostscript/output.png
> 
> See also, proof of white background: 
> http://www.webknack.de/ghostscript/test.html
> 
> How can i tell GhostScript to handle the transparency correct??
> 
> Thanks in advance for all your help!
> 
> Regards
> ansgar



More information about the gs-devel mailing list