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.

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DecryptPDFFile()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
    
    using (var pdfFileInfo = new Aspose.Pdf.Facades.PdfFileInfo(dataDir + "sample_encrypted.pdf"))
    {
        if (pdfFileInfo.IsEncrypted)
        {
            using (var fileSecurity = new Aspose.Pdf.Facades.PdfFileSecurity())
            {
                // Bind PDF document
                fileSecurity.BindPdf(dataDir + "sample_encrypted.pdf");
                // Decrypt PDF document
                fileSecurity.DecryptFile("P@ssw0rd");
                // Save PDF document
                fileSecurity.Save(dataDir + "SampleDecrtypted_out.pdf");
            }
        }
    }
}