Save Word doc as PDF with password

Is it possible to save a Word document such that it will require a password to open, and also set permissions so that the PDF cannot be printed, copied or edited?

hi @pmarangoni,
you can use PdfSaveOptions , like below codes…

string MyDir = @"C:\Docs\asposeWord\";
Document doc = new Aspose.Words.Document(MyDir + "OUTPUTX.doc");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Create encryption details and set user password  
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(password, string.Empty, PdfEncryptionAlgorithm.RC4_128);
// Disallow all
encryptionDetails.Permissions = PdfPermissions.DisallowAll;
// Allow printing
encryptionDetails.Permissions = PdfPermissions.Printing;
saveOptions.EncryptionDetails = encryptionDetails;
doc.Save(MyDir + "OUTPUTX.pdf", saveOptions);

@pmarangoni,

Thanks for your inquiry. Please use following code example to get the desired output.

Document doc = new Document(MyDir + "Rendering.doc");

PdfSaveOptions saveOptions = new PdfSaveOptions();

// Create encryption details and set owner password.
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails("mypassword", "password", PdfEncryptionAlgorithm.RC4_128);

// Start by disallowing all permissions.
encryptionDetails.Permissions = PdfPermissions.DisallowAll;

// Extend permissions to allow editing or modifying annotations.
encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
saveOptions.EncryptionDetails = encryptionDetails;

// Render the document to PDF format with the specified permissions.
doc.Save(MyDir + "Rendering.SpecifyPermissions Out.pdf", saveOptions);

Thanks guys! That worked perfectly.

Is there any way to alter or modify the password prompt which comes up in the PDF when first opening it?

@pmarangoni,

Thanks for your inquiry. Please note that password prompt is viewer (e.g. Adobe reader) level setting and does not store in the Word document that you are converting to PDF. Therefore it cannot be controlled by Aspose.Words. This is completely controlled by the viewer that opens the document.