Reading password protected PDF file

Q:

We are trying to use the security solution but we are having some issues about opening encrypted pdf files.
We understand that to encrypt the PDF we can use:

PDFDoc doc=new PDFDoc((“my.pdf”));
doc.initSecurityHandler();

SecurityHandler new_handler=new SecurityHandler();
new_handler.changeUserPassword(“mysecretpass”);
doc.setSecurityHandler(new_handler);
doc.save(“standard_security.pdf”, 0, null);
doc.close();

But we would like to know if we can use the same approach to read crypted files, without asking user filling the password. If not, how can we read encrypted pdfs ?

A:

You can open the password protected file as follows:

PDFDoc doc=new PDFDoc((“my.pdf”));

if (doc.initStdSecurityHandler(“mysecretpass”) {

// Ok :relaxed:

}

else {

// Bad pass

}

doc.close();

For the full sample code please refer to EncTest.java:

http://www.pdftron.com/pdfnet/samplecode.html#EncTest