CFPDF with PNG: transparency is black. With PDF it's white

508 Views Asked by At

I am trying to add a watermark to a PDF with a PNG file that has a transparent background.

Every time I create the watermark it comes out as black background. When it comes to using a PDF as the watermark I get a white background of the watermark. Also, the PDF watermark when turned into thumbnails becomes grayscale.

What is causing this? And what can I do to allow transparency?

I am using ColdFusion 11.

Here is the code for both:

Watermark by PNG:

<cfpdf
 action="addwatermark"
 foreground="true"
 opacity="6"
 source="PDFS/blankpage.pdf"
 destination="PDFS/watermarked/blankpage.pdf"
 image="PDFS/samplemusicpage2.png"
 overwrite="yes"
>

<cfpdf
 action="thumbnail"
 resolution="low"
 source="PDFS/watermarked/blankpage.pdf"
 destination="PDFS/_thumbnails"
 imageprefix="blankpage"
 overwrite="yes"
 scale="40"
>

Here is the code for using a PDF as a watermark:

<cfpdf
 action="addwatermark"
 foreground="true"
 opacity="6"
 source="PDFS/blankpage.pdf"
 destination="PDFS/watermarked/blankpage.pdf"
 copyfrom="PDFS/samplemusicpage.pdf"
 overwrite="yes"
>
<cfpdf
 action="thumbnail"
 resolution="low"
 source="PDFS/watermarked/blankpage.pdf"
 destination="PDFS/_thumbnails"
 imageprefix="blankpage"
 overwrite="yes"
 scale="40"
>

Here are the images that I am working with in this example: Here is the PNG File: PNG File

Here is the Read PDF File:PDF FIle

1

There are 1 best solutions below

0
Will On BEST ANSWER

I found a fix to my own issue. The best way that I found to accomplish this was to created the PDF's into images and then use Coldfusion's imaging to add the watermark to the images.

<cfloop query="jpgfiles">
<cfset theFile = directory & "/" & name>
<cfset imgFile = imageRead(theFile)>
<cfset imgInfo = imageInfo(imgFile)>
<cfset imagepaste(imgFile, watermark, imgInfo.width-watermarkinfo.width, imgInfo.height-watermarkinfo.height)>
<cfset imageWrite(imgFile, processedfolder & "/" & name, true)>
</cfloop>

Some of the terms are my variables, but the point is I no longer have the black background on the images like the above.