Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-2736 testcase for cfpdf - removewatermark didn't work #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/java/src/org/lucee/extension/pdf/tag/PDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 45 additions & 0 deletions tests/LDEV2736.cfc
Original file line number Diff line number Diff line change
@@ -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 <br>");
writeoutput('<img src="https://raw.githubusercontent.com/lucee/Lucee/6.0/test/functions/images/lucee.png">');
}
}

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);
}
}
Loading