Decrypt PDF File

A PDF document encrypted with a password or certificate must be unlocked before another operation can be performed on it. If you try to operate on an encrypted PDF document, you will throw an exception. After unlocking an encrypted PDF, you can perform one or more operations on it.

Decrypt PDF File using Owner Password

In order to decrypt a PDF file, you need to create PdfFileSecurity object and then call the DecryptFile method. You also need to pass the owner password to DecryptFile method. The following code snippet shows you how to decrypt PDF file.

public static void DecryptPDFFile()
{
    PdfFileInfo pdfFileInfo = new PdfFileInfo(_dataDir + "sample_encrypted.pdf");
    // Create PdfFileSecurity object
    if (pdfFileInfo.IsEncrypted)
    {
        PdfFileSecurity fileSecurity = new PdfFileSecurity();
        fileSecurity.BindPdf(_dataDir + "sample_encrypted.pdf");
        // Decrypt PDF document
        fileSecurity.DecryptFile("P@ssw0rd");
        fileSecurity.Save(_dataDir + "sample_decrtypted.pdf");
    }
}