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 new file mode 100644 index 0000000..971e511 --- /dev/null +++ b/tests/LDEV2736.cfc @@ -0,0 +1,45 @@ +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 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(); + + 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