How to remove password from the protected PDF using C# and VB.NET
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:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
- Include the following namespaces in Program.cs file.
C#
using Syncfusion.Pdf.Parsing;
VB.NET
Imports Syncfusion.Pdf.Parsing
- 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")
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.
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.
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.