From 2486efd100a7ece734f753849c301ecd37fe8045 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Thu, 23 May 2024 11:25:53 +0200 Subject: [PATCH 1/2] LDEV-2736 testcase for cfpdf - removewatermark didn't work https://luceeserver.atlassian.net/browse/LDEV-2736 --- tests/LDEV2736.cfc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/LDEV2736.cfc diff --git a/tests/LDEV2736.cfc b/tests/LDEV2736.cfc new file mode 100644 index 0000000..d23ea8d --- /dev/null +++ b/tests/LDEV2736.cfc @@ -0,0 +1,40 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="pdf" { + + function beforeAll() { + variables.dir = getTempDirectory() & "/LDEV2256"; + if (!directoryExists(variables.dir)) directoryCreate(variables.dir); + + document filename="#variables.dir#/main.pdf",overwrite="true",format="pdf" { + writeoutput("test main pdf"); + } + + document filename="#variables.dir#/copyFrom.pdf" overwrite="true" format="pdf" name="copyFrom" { + writeoutput("test watermark pdf
"); + writeoutput(''); + } + } + + function run( testResults , testBox ) { + describe( "Testcase for LDEV-2736", function() { + it( title="cfpdf - removewatermark didn't work", body = function( currentSpec ) { + pdf action="addwatermark" source="#variables.dir#/main.pdf" copyFrom="#variables.dir#/copyFrom.pdf" name="local.name"; + + expect( function(){ + pdf action="removewatermark" source="#variables.dir#/main.pdf"; //needs name or destination + }).toThrow(); + + pdf action="removewatermark" source="#variables.dir#/main.pdf" name="local.out"; + expect( isPDFObject( out ) ).toBeTrue(); + + var dest = "#variables.dir#/removed.pdf"; + pdf action="removewatermark" source="#variables.dir#/main.pdf" destination="#dest#"; + + expect( isPDFObject(dest)).toBeTrue(); + }); + }); + } + + function afterAll() { + if (directoryExists(variables.dir)) directoryDelete(variables.dir, true); + } +} \ No newline at end of file From 396affb61a0328da1f61cebd9528c3cdfebe660d Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Thu, 23 May 2024 11:32:58 +0200 Subject: [PATCH 2/2] LDEV-2736 add removewatermark parameter validation --- source/java/src/org/lucee/extension/pdf/tag/PDF.java | 5 +++++ tests/LDEV2736.cfc | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/source/java/src/org/lucee/extension/pdf/tag/PDF.java b/source/java/src/org/lucee/extension/pdf/tag/PDF.java index 46158e5..1bc49a5 100644 --- a/source/java/src/org/lucee/extension/pdf/tag/PDF.java +++ b/source/java/src/org/lucee/extension/pdf/tag/PDF.java @@ -1070,6 +1070,11 @@ private void doActionRemoveWatermark() throws PageException, IOException, Docume if (destination != null && destination.exists() && !overwrite) throw engine.getExceptionUtil().createApplicationException("Destination PDF file [" + destination + "] already exists"); + + if (destination == null && name == null) throw engine.getExceptionUtil().createApplicationException("One of the following attributes [destination, name] is required"); + + if (destination != null && name != null) throw engine.getExceptionUtil().createApplicationException("Both attributes [destination, name] cannot be defined at the same time"); + BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setBackground(Color.BLACK); diff --git a/tests/LDEV2736.cfc b/tests/LDEV2736.cfc index d23ea8d..971e511 100644 --- a/tests/LDEV2736.cfc +++ b/tests/LDEV2736.cfc @@ -16,13 +16,18 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="pdf" { function run( testResults , testBox ) { describe( "Testcase for LDEV-2736", function() { - it( title="cfpdf - removewatermark didn't work", body = function( currentSpec ) { + it( title="cfpdf - removewatermark check required params", body = function( currentSpec ) { pdf action="addwatermark" source="#variables.dir#/main.pdf" copyFrom="#variables.dir#/copyFrom.pdf" name="local.name"; expect( function(){ pdf action="removewatermark" source="#variables.dir#/main.pdf"; //needs name or destination }).toThrow(); + }); + + it( title="cfpdf - removewatermark didn't work", body = function( currentSpec ) { + pdf action="addwatermark" source="#variables.dir#/main.pdf" copyFrom="#variables.dir#/copyFrom.pdf" name="local.name"; + pdf action="removewatermark" source="#variables.dir#/main.pdf" name="local.out"; expect( isPDFObject( out ) ).toBeTrue();