Search code examples
javapdfbox

Access Permissions not working properly when creating a PDF with Apache PDFBox


In my project, I have a funcionality that creates pdfs with certain permissions for diferent kind of usage for example not to print, not modify content, etc. At a certain point, this function is not working. I have this code for that purpose:

try (PDDocument document = new PDDocument()) {

document.setAllSecurityToBeRemoved(true);
            

AccessPermission accessPermissions = new AccessPermission();
accessPermissions.setCanModify(false);
accessPermissions.setCanExtractContent(true);
accessPermissions.setCanPrint(false);
accessPermissions.setCanPrintDegraded(false);
accessPermissions.setReadOnly();
//accessPermissions.setCanAssembleDocument(true);
            

StandardProtectionPolicy spp = new StandardProtectionPolicy(UUID.randomUUID().toString(), "", accessPermissions);
document.protect(spp);

In the end of the operation i save the document an return the file where destination variable is the filePath:

document.save(destination);
return new File(destination);

The ending result of this operation: enter image description here

As you can see when I open the pdf in adobe acrobat reader the only button disabled is the save button. What i am doing wrong is this process for not disable the print button?

The version of Apache PDFBox used is 1.8.10


Solution

  • Remove

    document.setAllSecurityToBeRemoved(true);
    

    and it works. Because that one tells not to encrypt.