We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set read only property for pdf generated document

Hi,

I am using ReportingEngine to generate pdf files, but I wnat to make them read only (copy + paste functions disable). I used the following code, but it doesn’t work :

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, myData, “data”);
doc.Protect(ProtectionType.ReadOnly);
doc.Save(outputFile);

Can you please assist with this topic? Thank you!

@taia

Thanks for your inquiry. Please use PdfSaveOptions.EncryptionDetails property as shown below to set the detail for encrypting the output PDF document. Hope this helps you.

Document doc = new Document(MyDir + "input.docx");

//Your code...


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 + "18.11.pdf", saveOptions);

Hi,

thanks for your help, now it works fine.

@taia

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.