Change the permissions on a generated PDF to Read only

Hi,

I want to change the permissions of a pdf file to read only so that no one else can modify it, can you let me know how to do this using aspose-pdf java library

@nsingireddy

Thank you for contacting support.

You may set different privileges of DocumentPrivilege to false one by one, or ForbidAll at once as per your requirements. Please try using below code snippet in your environment and then share your kind feedback with us.

// Load source document
Document document = new Document(inputFile);

// Forbid all privileges on the document
DocumentPrivilege privilege = DocumentPrivilege.getForbidAll();

// Set the desired privileges
PdfFileSecurity fileSecurity = new PdfFileSecurity(document);
fileSecurity.setPrivilege(privilege);

// Save resulting PDF document
document.save(outputFile);

We hope this will be helpful. Please feel free to contact us if you need any further assistance.