Decrypt a PDF document

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Going Deeper > Document Engines > Working with PDF > Enhancement >

Decrypt a PDF document

In this section we present example code to decrypt an encrypted PDF document. Before proceeding further please make sure that the prerequisite steps as listed in the Document Engines parent topic are followed.

 

The example code below shows how to decrypt a password protect a PDF file so that the password is NOT required to open the document.

 

// Create a new document object
using (var pdfDoc = new PDF())
{
   // Load an existing PDF, password needs to be provided
   pdfDoc.LoadDocument(@"encrypted_statement.pdf", password: "owner");
 
   // Disable document encryption
   pdfDoc.Security.Enabled = false;
 
   // Write encrypted document to file stream
   pdfDoc.Save(@"decrypted_statement.pdf");
}