How can I save an editable pdf as Non-Editable after adding some text to it using Aspose PDF?
Asked
Active
Viewed 1,045 times
1 Answers
2
After adding some text to a PDF file, you can set Document Privileges by using the code snippet below:
//Open 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);
This will forbid all document privileges and the PDF file would not be editable anymore. I hope this will be helpful. Please let us know if you need any further assistance.
I work with Aspose as Developer Evangelist.

Farhan Raza
- 392
- 1
- 8
-
1Thanks! Worked fine. It's also working with doc.flatten(). – intruder Jan 18 '18 at 21:58
-
With above approach, user could still unlock pdf for editing using external pdf tools like -smallpdf.com. Any other ways through which ASPOSE can make the file completely uneditable. One way I can think of is - convert each pdf page to image and then to pdf. – Sandy Mar 20 '20 at 10:28