Free Support Forum - aspose.com

Apply security settings in a PDF converted from DOCX/DOC

I am converting a docx in pdf format but I do not know how to apply security settings in the pdf, e.g. not allowing “Document assembly” etc.

The code I am using is similar to the following:
Aspose.Words.Document aspose_docx = new Aspose.Words.Document(filepath + filename);
aspose_docx.Save(filepath + filename + “.pdf”, Aspose.Words.SaveFormat.Pdf);

Hi,

Thank you very much for your inquiry.

You can apply security settings in a PDF using Aspose.Words.Saving.PdfSaveOptions class. Following code snippet should help you understand it in a better way:

// Create PDF save options and PDF Encryption Details PdfSaveOptions sOptions = new PdfSaveOptions(); PdfEncryptionDetails pdfSecurityDetails = new PdfEncryptionDetails("1234",
"test", PdfEncryptionAlgorithm.RC4_128);

// Just to check, disable all security options first.
pdfSecurityDetails.Permissions = PdfPermissions.DisallowAll;
// Now enable only Document Assembly. pdfSecurityDetails.Permissions = PdfPermissions.DocumentAssembly;
// Set security details specified by us. sOptions.EncryptionDetails = pdfSecurityDetails;

// Open a word document and Save it using PDF Save Options.
Aspose.Words.Document doc = new Aspose.Words.Document(csPath + "input.docx"); doc.Save(csPath + "saved.pdf", sOptions);

Please explore the documentation available here for PDFSaveOptions reference. Hope this helps. Please feel free to ask if you have any more queries.

Thanks for replying.

I changed it into the following:
PdfEncryptionDetails pdfSecurityDetails = new PdfEncryptionDetails("", “test”, PdfEncryptionAlgorithm.RC4_128);
so that everyone can open it, but I fail to create a PDF document, where printing will be allowed for everyone.

Hi,


Thanks for your inquiry and sorry for replying late.

You can use following approach to create a PDF dcument which could be opened/printed by anyone:
// Create PDF save options and PDF Encryption Details
PdfSaveOptions sOptions = new PdfSaveOptions();
PdfEncryptionDetails pdfSecurityDetails = new PdfEncryptionDetails("", “test”, PdfEncryptionAlgorithm.RC4_128);

// Just to check, disable all security options first.
pdfSecurityDetails.Permissions = PdfPermissions.DisallowAll;
// Now enable only Document Assembly.
pdfSecurityDetails.Permissions = PdfPermissions.Printing | PdfPermissions.HighResolutionPrinting;

// Set security details specified by us.
sOptions.EncryptionDetails = pdfSecurityDetails;

// Open a word document and Save it using PDF Save Options.
doc1.Save(csPath + “saved.pdf”, sOptions);


Hope this helps. Please feel free to ask if you have any other question.