Hello,
I would like to fill a form in a pdf, then to avoid people to change this
form.
To test it I have change the class SetField in such away:
pdf = PDDocument.load( args[0] );
example.setField( pdf, args[1], args[2] );
AccessPermission permission = new AccessPermission();
permission.setCanFillInForm(false);
permission.setCanModify(false);
StandardProtectionPolicy pp = new
StandardProtectionPolicy("test","test1",permission);
pdf.protect(pp);
pdf.save(
args[0].substring(0,args[0].length()-4).concat("2.pdf") );
Main problem is that the new pdf generated can be modify and the form can be
edit even if I enter the password "test1" for user. May be I do something
wrong. If someone can help, I will enjoy the answer.
Also I notice that if I add the following code after saving the pdf, it print
true all time that means no permission is set. It seems that there is already a
bug in jira for this.
try {
pdf =
PDDocument.load(args[0].substring(0,args[0].length()-4).concat("2.pdf") );
AccessPermission permission=pdf.getCurrentAccessPermission();
System.out.println(permission.isOwnerPermission());//print true (do
not know what is expected)
System.out.println(permission.canFillInForm());//print true (do not
know what is expected)
pdf.decrypt("test1");
System.out.println(permission.isOwnerPermission());//print true
(expected false)
System.out.println(permission.canFillInForm());// print true
(expected false)
pdf.close();
}catch (Exception e) {
e.printStackTrace();
}
Thank you.
<em>Sylvain</em>