Trouble Converting Transparent PDFs to Transparent PNGs

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jon@techvalidate.com

Trouble Converting Transparent PDFs to Transparent PNGs

Post by jon@techvalidate.com »

Hi all. I'm hoping for some help with something I've spent several hours trying to figure out to no avail...

I need to convert PDF files with a transparent background to PNG files with a transparent background, but no matter what I do, ImageMagick (using ghostscript) rasterizes my PDFs with a white background color.

Unfortunately, I can't simply use a command like "convert -transparent white test.pdf test.png" to make all the white pixels in the converted image transparent, even if I use a fuzz factor, since the graphics in the PDFs have drop shadows that I need to preserve. I have also been unsuccessful using -background transparent and -alpha on, while -alpha transparent gives me a blank image, 100% transparent.

My feeling is that somehow I need to tell Ghostscript (either directly on the command line or through ImageMagick) to rasterize the PDF with a transparent background before it gets to ImageMagick.

Perhaps the problem is somewhere in the PDF file, since when I run "identify -verbose test.pdf", IM tells me that the pdf has "background color: white". Howerver, I suspect that this is just the default background color and that a background color is actually not defined in the PDF -- when I open the PDF in Photoshop, it shows up with a transparent background.

Trying to convert the file directly with Ghostscript, the closest I can get is to use this command:

Code: Select all

gs -q -dNOPAUSE -dBATCH -sDEVICE=pngalpha -sOutputFile=test.png test.pdf
With this command, any pixel totally outside one of the bounding box of the artwork is set to transparent, but the drop shadows and everything else inside of the artwork's bounding box is rasterized against a white background.

Can anybody help me out, or point me to a better forum to post my question? (I lookef for a forum for Ghostscript questions after learning that IM uses GS for PDF rasterization, but all the ghostscript advice related to this issue was either here on this forum or posted on other ImageMagick discussion areas.)

The sample PDF that I'm trying to convert to a transparent PNG can be found here: http://www.kolossus.com/files/test.pdf

Finally, I am running ImageMagick 6.5.2-9 and Ghostscript 8.64 on Mac OS 10.5.7.

Thank you in advance for any pointers or advice.

-Jon Wolfe
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Trouble Converting Transparent PDFs to Transparent PNGs

Post by magick »

Post your question to a Ghostscript mailing list or forum.
jon@techvalidate.com

Re: Trouble Converting Transparent PDFs to Transparent PNGs

Post by jon@techvalidate.com »

Will do. I asked here because I've seen other people asking about the same problem in this forum, and many of the replies have suggested specific ImageMagick commands to try, without resorting to calling Ghostscript directly. Some have replied with Ghostscript commands, on this forum.

I had hoped to find a solution using ImageMagick, but I guess this is something that cannot be done with ImageMagick.

Perhaps this can be accomplished by calling Ghostscript directly, perhaps not...
Post Reply