Q: When trying to open a protected document using PDFViewCtrl for Android, a dialog is presented so the user can enter the password. How can I avoid this dialog and use my own custom dialog?
----
A: In order to check if a password dialog should be presented to the user, you can use the following code before setting the doc in PDFViewCtrl:
1. To identify if a dialog should be presented (ie, the document is protected):
PDFDoc doc = new PDFDoc(...);
boolean prompt = false;
SecurityHandler sh = doc.getSecurityHandler();
if (sh != null) {
if (sh.getPermission(SecurityHandler.e_doc_open)) {
PDFViewCtrl.setDoc(doc);
} else {
prompt = true;
}
} else {
prompt = !doc.initSecurityHandler();
if (!prompt) {
PDFViewCtrl.setDoc(doc);
}
}
if (prompt) {
// Show password dialog
}
2. Once you get the password from the user, you can do the following:
String password = "get_password_from_dialog";
if (doc.initStdSecurityHandler(password) ) {
// Password correct, open document.
PDFViewCtrl.setDoc(doc);
} else {
// Password incorrect
}