Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"
>
Copy link to clipboard
Copied
catchme_dileep wrote:
Hi,
Please try this,
What is the difference between that and the original code?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks for the info...i'll look into iText then. As for the ddx, i am actually adding text as a watermark using ddx right before my cfpdf tag. Basically, i'm adding two separate watermarks to a pdf (one is a bunch of text that i add via ddx). The other is an image that i'm attempting to add via cfpdf. I didn't see an example of addng an image watermark via ddx -- i only saw examples of text. Would i just at an <img> tag in the ddx file like so:
<DDX xmlns="http://ns.adobe.com/DDX/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd">
<PDF result="DestinationFile">
<PDF source="SourceFile">
<Watermark rotation="0" opacity="100%" horizontalAnchor="#horzAnchor#" horizontalOffset="#horzOffset#" verticalAnchor="#vertAnchor#" verticalOffset="#vertOffset#">
<StyledText>
<img src="pathTowatermark.png" >
</StyledText>
</Watermark>
</PDF>
</PDF>
</DDX>
Copy link to clipboard
Copied
No, I believe the two options for ddx <Watermark> are <StyledText> and <Pdf Source="somePDFFile.pdf">. So the image would need to be placed inside a pdf file. Though given that CF does not support all of the ddx features I do not know if two watermarks will be allowed:
http://livedocs.adobe.com/livecycle/8.2/ddxRef/001162.html#1557141
Copy link to clipboard
Copied
Actually, i am able to add both watermarks. One via ddx and one via cfpdf. See the attached pdf that was created this way. The 3 lines of text in the blue area in the upper right was were added with ddx. The "new" logo in the lower left hand area was added to that pdf with cfpdf.
If i could only get that added logo to allow transparency i'd be set...
Thanks...
Copy link to clipboard
Copied
mjp420 wrote:
Actually, i am able to add both watermarks. One via ddx and one via cfpdf. See the attached pdf that was created this way. The 3 lines of text in the blue area in the upper right was were added with ddx. The "new" logo in the lower left hand area was added to that pdf with cfpdf.
If i could only get that added logo to allow transparency i'd be set...
Thanks...
No, what I meant was I did not know if you could do both _with ddx_. I do not know one way or the other. Just that the livecycle documentation suggested it might be an issue.
I have had zero luck with transparency in my tests of cfpdf/ddx. The only thing that worked for me was iText. If you are allowed to use createObject(...) try the attached. I tested it with the pdf you posted and it definitely works on CF8.
<!---
Adaptation of iText examples:
--->
<cfscript>
savedErrorMessage = "";
fullPathToInputFile = ExpandPath("sample_ddx_startburst-1.pdf");
fullPathToWatermark = "c:\myTransparentPng.png";
fullPathToOutputFile = ExpandPath("startburstWatermarked.pdf");
try {
// create PdfReader instance to read in source pdf
pdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(fullPathToInputFile);
totalPages = pdfReader.getNumberOfPages();
// create PdfStamper instance to create new watermarked file
outStream = createObject("java", "java.io.FileOutputStream").init(fullPathToOutputFile);
pdfStamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(pdfReader, outStream);
// Read in the watermark image
img = createObject("java", "com.lowagie.text.Image").getInstance(fullPathToWatermark);
// adding content to each page
i = 0;
while (i LT totalPages) {
i = i + 1;
content = pdfStamper.getOverContent( javacast("int", i) );
img.setAbsolutePosition(0, 0);
content.addImage(img);
WriteOutput("Watermarked page "& i &"<br>");
}
WriteOutput("Finished!");
}
catch (java.lang.Exception e) {
savedErrorMessage = e;
}
// closing PdfStamper will generate the new PDF file
if (IsDefined("pdfStamper")) {
pdfStamper.close();
}
if (IsDefined("outStream")) {
outStream.close();
}
</cfscript>
<!--- show any errors --->
<cfif len(savedErrorMessage) gt 0>
ERROR - Unable to create document
<cfdump var="#savedErrorMessage#">
</cfif>
Copy link to clipboard
Copied
Dude! That worked!!! Mucho thanks! It definitely take a lot longer to run that page (not exactly sure but was approx 10+ seconds for it to return but i think that'll work.
Thanks again for your help!
-Michael
Copy link to clipboard
Copied
I am surprised about a time increase. I ran it with the file you posted and it was pretty quick, as the input file is not that large. But in any event, I am glad it works for you.
Cheers
Copy link to clipboard
Copied
BTW, Did you submit a bug report on this? It is either a bug in the behavior or documentation.
Copy link to clipboard
Copied
@cfSearching
I didn't before but after your suggestion i did submit a bug report with Adobe. Hopefully we'll see that fixed -- or at least some updated documentation.
On another note, does the "remember me" option when logging into this forum actually do anything? Every time i come back to this thread to look at it i have to log back in. And i mean after a couple of hours or so...but i'd think that the "remember me" function would set a cookie that would actually REMEMBER ME 🙂
Thanks again for your help!
Copy link to clipboard
Copied
I do not know. I am just happy when the login option works. It seemed to malfunction a few posts back and now I cannot even go back and correct my awful typing as there is no "Edit" option on those posts 😉
Copy link to clipboard
Copied
mjp420,
BTW, this issue appears to be fixed in the CF9 beta.
-Leigh
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
CF_Ali wrote:
Umm.. how does that help with the watermarking and transparency issues?