Save as PDF with password

Hi,

Sorry if this has been asked before. I tried to do a search in the forum but that generated a server error.

I’m using Aspose.Words for .NET and would like to know if it’s possible to save as a password-protected PDF.

I’m currently using this code to save as a Word document:

doc.Save(Response, fileName.Text + ".doc", ContentDisposition.Attachment, null);

Thanks,

Mark

Hi Mark,

Thanks for your inquiry. Sure, please try using the following code snippet:

Document doc = new Document(MyDir + "Rendering.doc");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Create encryption details and set owner password.
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128);
// Start by disallowing all permissions.
encryptionDetails.Permissions = PdfPermissions.DisallowAll;
saveOptions.EncryptionDetails = encryptionDetails;
// Render the document to PDF format with the specified permissions.
doc.Save(MyDir + "Rendering.SpecifyPermissions Out.pdf", saveOptions);

I hope, this will help.

Best Regards,

Works perfectly. Thanks very much.

Hi
Mark,

Thanks for your feedback. It is perfect that the code worked for you. Please let us know any time you have any further queries.

Best Regards,