4

How can I save an editable pdf as Non-Editable after adding some text to it using Aspose PDF?

intruder
  • 417
  • 1
  • 3
  • 18

1 Answers1

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
  • 1
    Thanks! 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