Skip to main content
Participating Frequently
June 26, 2009
Question

CFPDF - adding watermark image with a transparent background (png or gif)

  • June 26, 2009
  • 3 replies
  • 8644 views

Hi,

I'm have trouble getting an added watermark with a transparent background to display properly when adding it to a pdf using <cfpdf>.  My code below:

<cfpdf
    action = "addwatermark"
    source = "sample_ddx.pdf"
    image = "starburst.png"
    foreground = "yes"
    isBase64 = "yes"
    overwrite = "yes"
    pages = "1"
    showonprint = "yes"
    position = "0,0"
    opacity = "10"
    destination = "sample_ddx_startburst.pdf"
>

I've tried changing isBase64, foreground, etc and it always changes the transparent part of the gif or png to white.  Has anybody ever been able to get this to work?  I haven't been able to find anthing in the doc's that say it isn't supported...

Thanks for any info anyone might have....

-Michael

This topic has been closed for replies.

3 replies

June 28, 2009

Hi Mike,

This might help you out, because im not sure where would you get your image, whether its uploaded, or its already on the server. But I will asume that you already have the photo.

Use the cfimage tag to write the photo in an empty photo variable in which you would just simply upload as it is with your file. Now, you can first read the image using cfimage into a variable then resize it, or manipulated using image() methods, finally read it with cfimage again and write it into a variable.

example:

<cfimage action="read" yada yada>

now that we have read the image as object

lets resize it:

<cfset ImageSetAnitialising(myImage, "on")>

<cfset ImageScaleToFit(myImage, 45, 45>

<cfif myImage.width GTE myImage.height>

<cfset x = 0>

<cfset y = ceiling((myImage.width - myImage.height)/2>

<cfelse>

<cfset x = ceiling((myImage.height - myImage.width) / 2>

</cfif>

<!-- below we will reset the images size AND BORDER so make sure that if you want to

have another color than WHITE to specify it -->

<cfset newimg = ImageNew("", 45, 45, "rgb", "FFFFFF")>

<cfset ImagePaste(newimg, myImage, x, y)>

<!-- here is where we write the image to the place holder image that we have which is pro#Number#>
<cfimage source="#newimg#" action="write" destination="images/Pro#randNum#.jpeg" overwrite="yes">

I hope that helps

Please let me know how that went for ya

Inspiring
June 28, 2009

CF_Ali wrote:

Umm.. how does that help with the watermarking and transparency issues?

Inspiring
June 26, 2009

I ran a few tests and did not have much luck with transparent images either.  If you cannot get it to work with cfpdf, you might consider trying to add the watermark with iText (used the hood for cfdocument).  See if it makes a difference.

<cfpdf

....
    opacity = "10"
>

I assume you just testing different settings, as "10" means totally opaque.

mjp420Author
Participating Frequently
June 26, 2009

@catchme_dileep:

Not sure what the difference is in your code as opposed to what it have.

@cfSearching:

Unfortunately i'm on a shared server so i can't do any tinkering by adding JAVA libraries -- so i assume that iText is out of the question.

And yes, i understand i set the opacity to 10 - tried lots of values for this but no difference in whether the watermark image keeps it's transparency or not.  I'm definitely not a expert to the underworkings of gif's and png's -- maybe they need to be built with a transparency in a certain way in order for it to work?!? ( alpha transparency as opposed to index transparency)  I did try that using Fireworks to create the watermark images but i really don't know the underliying difference's between the two are.

Inspiring
June 26, 2009

ColdFusion uses iText for cfdocument. So you do not need to add jars. It is already built in. But you do need access to createObject(..).  So that might eliminate this option for you.You might also try using ddx with <Watermark> to see if the results are any different.

Dileep_NR
Inspiring
June 26, 2009

Hi,

Please try this,

<cfpdf
        action="addwatermark"
        source="sample_ddx.pdf"   
        image="./test.jpg"
        destination="#expandpath("newpdf")#/watermarkforeground.pdf"
        overwrite="yes"
        pages ="1,3,6-8"
        rotation="45"          
        >

Inspiring
June 26, 2009

catchme_dileep wrote:

Hi,

Please try this,

What is the difference between that and the original code?