Skip to main content
Participating Frequently
June 24, 2009
Question

cfdocument produces white rectangle

  • June 24, 2009
  • 2 replies
  • 3574 views

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?

This topic has been closed for replies.

2 replies

pfurrerAuthor
Participating Frequently
August 20, 2009

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>

Inspiring
August 20, 2009

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.
pfurrerAuthor
Participating Frequently
August 21, 2009

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

Inspiring
June 24, 2009

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.

pfurrerAuthor
Participating Frequently
June 25, 2009

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).

Inspiring
June 25, 2009

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.