Websupergoo ABCPDF.NET - check if the pdf is encrypted/password protected before calling doc.Read()

522 views Asked by At

doc.Read(filePath) will error out if the pdf file is encrypted and a password is not passed. I haven't been able to find a way to check to see if the pdf document is encrypted before calling doc.Read() so I can better handle this occurrence. Anyone know of a way?

1

There are 1 answers

2
Clinton Ward On

check the doc encrption type to be 2?

bool encrypted = false;
using (Doc theDoc = new Doc())
{
    XReadOptions options = new XReadOptions { ReadModule = MyPDF.Pdf };
    theDoc.Read(inputbytearray, options);
    if (theDoc.Encryption.Type == 2)
      encrypted = true;
}