Copy link to clipboard
Copied
Hello
If I try to create a PDF with <cfdocument> and want to add a watermark with <cfpdf> (on the background, not on the foreground!), there is always a white object (page size) which hides the watermark. Only after deleting the object with Acrobat the watermark gets visible.
I think this is a bug in <cfdocument>. I'm not able to produce a PDF without this white rectangle (tried with different HTML-Tags, Plain-Text etc.).
Example:
<cfdocument format="pdf" filename="test.pdf">test</cfdocument>
<cfpdf action="addwatermark" image="test.jpg" foreground="no" source="test.pdf">
System:
CF 8.0.1 (Update April 08)
Any ideas/similar experiences?
Copy link to clipboard
Copied
Is this happening with a licensed version of CF or the developer version? I am wondering if the standard watermark on the developer version is interfering with yours.
Copy link to clipboard
Copied
Thank you for your input. I work with a licensed ColdFusion Standard version.
The mentioned object is imho not a watermark. Otherwise I should be able to delete it with <cfpdf action="removeWatermark"> (doesn't work).
Copy link to clipboard
Copied
It sounds like a bug. The same code worked with a regular acrobat file. Just not with a pdf created by cfdocument.
Unfortunately, I cannot think of another workaround. Tests using ddx <Background> and using iText directly to apply the watermark (ie PdfStamper / getUnderContent()) produced the same result for me: ie watermark is not visible. I would submit a bug report.
Copy link to clipboard
Copied
I found a post on houseoffusion.com that suggested a work around using css. It is a bit of hack, but if you create an image of the right size (letter, landscape) it should do the trick:
ie
<style>
body { background-image: url(yourWatermarkLetterSize.gif);
</style>
http://www.mail-archive.com/cf-talk@houseoffusion.com/msg337518.html
Copy link to clipboard
Copied
Thank you for the valuable inputs.
The only way for me was to write it with itext, so i was also able to really embed the font (the embedding with cfdocument doesn't work, if you don't have the font on your local system).
If somebody is looking for a similar solution, I post here the code for putting text on a existing pdf with a watermark (in the background!):
// Path for the PDF-Documents (output.pdf must exist there)
<cfset variables.pfad = "[Absolute path]">
<cfscript>
fileIO=createObject("java","java.io.FileOutputStream");
fileIO.init(#variables.pfad# & "output.pdf");
reader = createObject("java","com.lowagie.text.pdf.PdfReader");
reader.init(#variables.pfad# & "original.pdf");basefont = createObject("java","com.lowagie.text.pdf.BaseFont");
//Sample with Font "Univers", Installed on the CF-Server
bfUnivers = BaseFont.createFont("c:\windows\fonts\unvr55w.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
pdfStamper = createObject("java","com.lowagie.text.pdf.PdfStamper").init(reader, fileIO);
// Place Text on Page 1
document = pdfStamper.getOverContent(1);
document.beginText();
document.setFontAndSize(bfUnivers, 18);document.setTextMatrix(90, 300);
document.showText("Test");document.endText();
pdfStamper.close();
</cfscript>
Copy link to clipboard
Copied
pfurrer wrote:
putting text on a existing pdf with a watermark (in the background!):
Oh. For some reason I thought you were using an image, not text 😕 But be aware getOverContent is the page foreground not background:
getOverContent(...) - Gets a PdfContentByte
to write over the page of the original document.
Copy link to clipboard
Copied
You understood everything correctly: I needed the image in the background, not the text. The watermark-image is now in the original pdf, with getOverContent I put the text in front of the image
Copy link to clipboard
Copied
Ah, okay. For anyone else, as of 8.0.1, you can use cfpdf for a foreground text watermark.
http://www.coldfusionjedi.com/index.cfm/2008/4/4/ColdFusion-801--Easier-to-add-PDF-Watermarks