How to Remove Password in Protected WinForms 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 a password from an encrypted PDF document using C# and VB.NET.
Steps to remove a password from a 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 passwords
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 the 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 passwords
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 the default PDF Viewer
Process.Start("Output.pdf")
To remove only the open password in a 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 and decryption.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.