Q:
We need a function that can determine if a PDF is password-protected.
- Do you have a function that can just tell us if a PDF has password protection set?
- Do you have a function that can determine if the metadata packet is encrypted or not?
A:
PDFDoc.InitSecurityHandler() returns false if you need a password to open the document ( document is protected using so called ‘open’ password).
https://www.pdftron.com/api/PDFNet/html/M_pdftron_PDF_PDFDoc_InitSecurityHandler.htm
A couple of asks:
- Do you have a function that can just tell us if a PDF has password protection set?
Yes, you can use InitSecurityHandler() to determine if a PDF requires an ‘open’ password.
If InitSecurityHandler() returns true, it means you do not need a password to open a document ( keep in mind that the file may still be encrypted, but this is weak encryption and it can be easily removed ).
- Do you have a function that can determine if the metadata packet is encrypted or not?
Yes, you can find out whether metadata packet is encrypted or not as follows:
Obj o = doc.GetTrailer().FindObj(“Encrypt”);
bool metadata_encrypted = false;
if (o != null) {
if (o.FindObj(“EncryptMetadata”) != null)
metadata_encrypted = o.FindObj(“EncryptMetadata”).GetBool();
}
This is C# pseudocode, however the same API works in all languages/platforms.