How to Decrypt PDF File using C#

This short tutorial is designed to guide on how to decrypt PDF file using C#. It contains crisp information to decrypt PDF using C# in the form of a step-wise process and a runnable sample code. The resultant unencrypted file can be saved on disk or to a stream in any desired format like PDF, HTML, DOCX, etc.

Steps to Decrypt Password Protected PDF using C#

  1. Establish the environment to add Aspose.PDF using the NuGet package manager
  2. Load the encrypted PDF file into the Document class object using the file name and password
  3. Call the Document.Decrypt method to unencrypt the PDF file
  4. Save the unencrypted file on disk with a new name

These steps describe a simple process to unencrypt PDF using C# such that first the environment configuration is provided. In the next step the source PDF file is loaded along with the password and then decrypted by calling the Decrypt() method in the Document class. You can provide either the owner password or user password based on the application requirement as with the owner password you have full control over the decrypted file whereas, with the user password, it can be read-only.

Code to Decrypt PDF File using C#

This simple code demonstrates how to unencrypt PDF using C#. We have used the constructor overload that takes file name and password as the argument while loading the source PDF file. We have a number of options to save the output PDF file to different formats provided by the SaveFormat enumerator along with the option to set a warning handler while saving the file and setting the flag to close the response object once the document is saved to response object in a web-based application.

This article has taught us to save an encrypted PDF as unencrypted using C#. If you want to learn to protect a PDF file with a password, refer to the article on how to protect PDF file with password in C#.

 English