A quick way to determine if a PDF document requires a passoword?


I'm trying to determine if a PDF document requires a password to be
viewed. I don't want to prompt for a password if one is needed, simple
return out of my function.

Right now I am deriving a class from SecurityHandler (similar to
EncTest sample project: http://www.pdftron.com/net/samplecode.html#EncTest),
however I am finding it a bit confusing.

Is there a way to quickly find out if the document requires open
password (and to possibly provide the required password)?

A quick way to check is the document requires password is to check the
return value from pdfdoc.InitSecurityHandler(). If the return value is
false, the document requires the password.

For example:

pdfdoc = new PDFDoc(filename);
if (!pdfdoc.InitSecurityHandler()) { // In case pdfdoc requires open
  !pdfdoc.InitStdSecurityHandler("my password")) {
  return false;
... start using 'pdfdoc'

This approach is simpler than deriving a new SecurityHandler.