cfpdf addwatermark error

Description

I'm trying to add a watermark to a pdf document using cfpdf tag:

<cfpdf action="addwatermark" source="LessonsLearned-Report-25-09-2017.pdf" image="Fanous.png" foreground="yes" overwrite="yes" />

and I'm receiving the below error:

java.lang.NullPointerException

Environment

Windows 10

Attachments

1
  • 20 Nov 2018, 05:31 am

Activity

Show:

Pothys - MitrahSoft 30 March 2022 at 12:08

I've checked this ticket with the latest PDF version 1.1.0.7-SNAPSHOT in lucee version 5.3.9.120-SNAPSHOT. Now the cfpdf addwatermark works fine.

Pothys - MitrahSoft 3 June 2021 at 15:08

I added a fix to this ticket

Pull request: https://github.com/lucee/extension-pdf/pull/29

Tom King 17 January 2021 at 14:47

Here’s a temp workaround if anyone needs it:

/** * Add a image as a watermark to a PDF using iText in Lucee 5.3 * * @source string, i.e Full path to Input File: expandPath("myFile.pdf") * @destination string i.e Full path to Output File: expandPath("myFile_Watermarked.pdf") * @image string i.e Full path to Watermark Image: expandPath("watermark.png") * @x Watermark image x offset, defaults to 0 * @y Watermark image y offset, defaults to 0 * @foreground Whether to add watermark on top or behind content */ function watermarkPDF( required string source, required string destination, required string image, numeric x = 0, numeric y = 0, boolean foreground = true ){ // Create PDF reader local.pdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader").init(arguments.source); // Fill form fields local.outputStream = createObject("java", "java.io.FileOutputStream").init(arguments.destination); local.pdfStamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(local.pdfReader, local.outputStream); // Create image object for watermark image local.imageObj = createobject("java", "com.lowagie.text.Image"); // Read watermark image local.img = local.imageObj.getInstance(arguments.image); // Add watermark image to every page local.i = 0; // Loop PDF pages while (local.i LT local.pdfReader.getNumberOfPages()) { local.i = local.i + 1; local.pdfContentByte = arguments.foreground? local.pdfStamper.getOverContent( javacast("int", local.i) ) : local.pdfStamper.getUnderContent( javacast("int", local.i) ); // Set position of image local.img.setAbsolutePosition(javacast("float", arguments.x),javacast("float", arguments.y)); // Add watermark image to looped page local.pdfContentByte.addImage(local.img); } // flattern form local.pdfStamper.setFormFlattening(true); // Close and create destination pdf file local.pdfStamper.close(); local.outputStream.close(); }
Fixed

Details

Assignee

Reporter

Priority

Labels

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 25 September 2017 at 09:06
Updated 30 March 2022 at 15:36
Resolved 30 March 2022 at 12:08

Flag notifications