How to check if file is encrypted

The encryption is used to protect the file, so the only people with an encryption key (such as a password) can open and view a file. In case you want to check if a file is encrypted, you can use GetFileInfo() method that returns file type and flag that indicates if the file is encrypted as it is shown in the next example (this example can be found in our examples at GitHub.)

using (Viewer viewer = new Viewer("encrypted.pdf"))
    FileInfo fileInfo = viewer.GetFileInfo();

    Console.WriteLine("File type is: " + fileInfo.FileType);
    Console.WriteLine("File encrypted: " + fileInfo.Encrypted);

After running the code above you will see an output like this:

File type is: Portable Document Format File (.pdf)
File encrypted: True

To learn how to open an encrypted file please refer to Load password-protected document documentation article.