Related blog post: Password Protection to PDF Files in C#
Last active
November 22, 2021 07:46
-
-
Save GroupDocsGists/cbb54ae36d531fd13a6bd3f5645c252f to your computer and use it in GitHub Desktop.
Protection of PDF Files by Adding, Removing, and Changing Password using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Add password protection to the PDF document using C# | |
*/ | |
string filePath = @"path/document.pdf"; | |
AddPasswordOptions addOptions = new AddPasswordOptions("mySECRETpassWORD"); | |
using (Merger merger = new Merger(filePath)) | |
{ | |
merger.AddPassword(addOptions); | |
merger.Save(@"path/protected-document.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Update password of the protected PDF document using C# | |
*/ | |
string filePath = @"path/protected-document.pdf"; | |
LoadOptions loadOptions = new LoadOptions("mySECRETpassWORD"); | |
UpdatePasswordOptions updateOptions = new UpdatePasswordOptions("TOPSECRET_pa22WORD"); | |
using (Merger merger = new Merger(filePath, loadOptions)) | |
{ | |
merger.UpdatePassword(updateOptions); | |
merger.Save(@"path/pwd-changed-document.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Remove password protection of PDF document using C# | |
*/ | |
string filePath = @"path/protected-document.pdf"; | |
LoadOptions loadOptions = new LoadOptions("mySECRETpassWORD"); | |
using (Merger merger = new Merger(filePath, loadOptions)) | |
{ | |
merger.RemovePassword(); | |
merger.Save(@"path/no-pwd-document.pdf"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment