Hi,
I don't know if this is the expected behaviour, so please correct me if I'm wrong with expecting the following to work:
We want to encrypt a PDF and supply both user and owner password. Afterwards the PDF shall be signed. This works as long as I omit the user password (=set it to null). As soon as I specify a user password, the bookmarks get screwed up and the signature check of Acrobat fails complaining about an invalid attribute.
Code:
String inFile = "docobfuscated.pdf";
String outFile = "docobfuscated.out.pdf";
String outFile2 = "docobfuscated.out2.pdf";
PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);
int priv=0;
priv|=PdfPrivilege.Copy;
priv|=PdfPrivilege.ScreenReaders;
priv|=PdfPrivilege.DegradedPrinting;
priv|=PdfPrivilege.Print;
fileSecurity.encryptFile("userpassword", "testpassword", priv, true);
PdfFileSignature pFileSignature = new PdfFileSignature();
Signature sgn = new Signature();
sgn.setRect(new java.awt.Rectangle(10, 10, 70, 70));
pFileSignature.bindPdf(outFile);
pFileSignature.setCertificateFile("test.pfx");
pFileSignature.setMultiSignature(true);
pFileSignature.setSignModel(PdfFileSignature.SELF);
pFileSignature.setPageNumber(1);
pFileSignature.setPassword("xxxxxxxxx");
pFileSignature.setSignature(sgn);
pFileSignature.setKeyStoreType("pkcs12");
pFileSignature.setCertificationLevel(PdfFileSignature.CERTIFIED_NO_CHANGES_ALLOWED);
pFileSignature.save(outFile2);
I'll attach the sample files (you'll need to add your own certificate and change the password accordingly).
Regards,
Mathias