Converting PNG to PDF (transparency issues)

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
Princess_Leia

Converting PNG to PDF (transparency issues)

Post by Princess_Leia »

Hello all,

I'm trying to create a PDF from a transparent PNG, the PNG was created with GD and is simple text with a transparent background. We then want to convert this to PDF keeping the transparency so we can overlay another document with this "watermark".

However using the convert command, it does not appear to retain the transparency. I have tried specifying a transparent color (white) and the fuzz parameters with no luck.

Can anyone help me with this?

Regards,

Princess_Leia
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PNG to PDF (transparency issues)

Post by fmw42 »

why not just overlay (or watermark) from the png? why go to pdf just to overlay it?

but to try to get to the bottom, what version of IM are you using and what exact command and can you provide a link to your images. at this point we do not have enough information to confirm your results

also see viewtopic.php?f=3&t=13770
Princess_Leia

Re: Converting PNG to PDF (transparency issues)

Post by Princess_Leia »

Thanks for the quick response fmw42.
fmw42 wrote:why not just overlay (or watermark) from the png? why go to pdf just to overlay it?
Because we are automating the process, at the time being we can manually do this without an issue using Acrobat - but as we have a large amount of documents, manually doing this every update/new document is very cumbersome!

We are using "pdftk" for merging the watermark, which requires another pdf document as the source of the watermark.
fmw42 wrote: but to try to get to the bottom, what version of IM are you using and what exact command and can you provide a link to your images. at this point we do not have enough information to confirm your results
I am using ImageMagick-6.2.8.0 on CentOS and the exact command I am using is as follows:

Code: Select all

convert draft.png -fuzz 100% -transparent white draft.pdf
also tried:

Code: Select all

convert draft.png -fuzz 100% -transparent white -background none draft.pdf
and other various combination's.

The PNG image generated by GD is here.
fmw42 wrote:also see viewtopic.php?f=3&t=13770
I'll have a read of this.

Thanks once again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PNG to PDF (transparency issues)

Post by fmw42 »

I am no expert of pdf and whether IM can produce a transparent pdf. Perhaps Anthony can illuminate us both about this.

But your command

convert draft.png -fuzz 100% -transparent white draft.pdf

if it were to work would make the whole image transparent due to the -fuzz 100%.

I tried (IM 6.5.2-4 Q16 Mac OSX Tiger)

convert draft.png draft.pdf

and

convert draft.png -colorspace rgb -channel rgba -alpha on draft.pdf


but the result had no alpha channel although the text was properly masked by the alpha channel, but the background was still white and not transparent. So again I am not sure IM produced pdfs save the alpha channel.

Perhaps there is some other option for setting the background color of the pdf. Maybe Anthony knows, but I could not find it at http://www.imagemagick.org/Usage/formats/#pdf

Also IM may rely upon Ghostscript to handle this and so may be out of IM's hands. But again I will defer to Anthony or Magick on this whole issue.
Princess_Leia

Re: Converting PNG to PDF (transparency issues)

Post by Princess_Leia »

Thanks for your efforts, I too noticed it shows a white background - apparently adobe reader will still show a white background when the document is transparent - I will try updating IM and giving it a shot with the command you tried.
Post Reply