Articles in this section
Category / Section

How to remove password from the protected PDF using C# and VB.NET

3 mins read

Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can remove password from the encrypted PDF document using C# and VB.NET.

Steps to remove password from protected PDF programmatically:

  1. Create a new C# console application project. Create a console application project
  2. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org. NuGet package reference
  3. Include the following namespaces in Program.cs file.

C#

using Syncfusion.Pdf.Parsing;

 

VB.NET

Imports Syncfusion.Pdf.Parsing

 

  1. Use the following code snippet to hide the signature field in a PDF document.

C#

//Load the password protected PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("ProtectedDocument.pdf","password");
//Setting permission flags to default
loadedDocument.Security.Permissions = PdfPermissionsFlags.Default;
//Change the user and owner password 
loadedDocument.Security.UserPassword = string.Empty;
loadedDocument.Security.OwnerPassword = string.Empty;
//Save the password removed PDF document
loadedDocument.Save("Output.pdf");
loadedDocument.Close(true);
//This will open the PDF file so, the result will be seen in default PDF Viewer
Process.Start("Output.pdf");

 

VB.NET

'Load the password protected PDF document
Dim loadedDocument As New PdfLoadedDocument("ProtectedDocument.pdf", "password")
'Setting permission flags to default
loadedDocument.Security.Permissions = PdfPermissionsFlags.Default
'Change the user and owner password 
loadedDocument.Security.UserPassword = String.Empty
loadedDocument.Security.OwnerPassword = String.Empty
'Save the password removed PDF document
loadedDocument.Save("Output.pdf")
loadedDocument.Close(True)
'This will open the PDF file so, the result will be seen in default PDF Viewer
Process.Start("Output.pdf")

 

Note:

To remove only the open password in protected PDF document, just empty the user password.

By executing the program, you will get the password removed PDF document as follows. Output document screenshot

A complete working sample can be downloaded from RemovePasswordSample.zip.

Take a moment to peruse the documentation, where you can find other options like encrypt PDF document, protect an existing PDF document, changing the password of the PDF document, change the permission of the PDF document and features like digitally sign a PDF document and redaction with code examples.

Refer here to learn more about PDF encryption an decryption.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.


 


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied