I want to remove the existing PDF password protection and I tried the following code. I do have the current password...
Somehow the id.Save fails raising the error code: "Hash not valid for use in specified state".
It has something to do with setting the password on "string.Empty". If I remove these two lines, the save will succeed!
Am I doing something wrong? Can the passwords be set to string.Empty? Or is there another way?
Am I doing something wrong? Can the passwords be set to string.Empty? Or is there another way?
[code lang='c#']
PdfImportedDocument id = null;
id = new PdfImportedDocument(inputFilePath, password);
// Remove password
id.Security.OwnerPassword = string.Empty;
id.Security.UserPassword = string.Empty;
// Set print indicator to printable
if (!id.Security.Permissions.HasFlag(ComponentPro.Pdf.Security.PdfDocumentPermissions.Print))
{
id.Security.SetPermissions(ComponentPro.Pdf.Security.PdfDocumentPermissions.Print);
}
id.Save(outputFilePath);
[/code]