Decrypt PDF File
Contents
[
Hide
]
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
Try online
You can try to unlock document using Aspose.PDF and get the results online at this link: products.aspose.app/pdf/unlock
You can try to unlock document using Aspose.PDF and get the results online at this link: products.aspose.app/pdf/unlock
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");
}
}