pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Problem Setting Security
Date Mon, 27 Jul 2015 20:19:53 GMT
Am 27.07.2015 um 21:46 schrieb William Heckle:
> I am trying to construct a document that everyone can read and it is 
> not modifiable.  I have tried many combinations with no success. Using 
> passwords and not using passwords; encrypting and not encrypting, 
> every combination doesn’t matter. I am setting can modify equals 
> false. The original pdf is generated from a birt report, it doesn’t 
> add a security handler if that is of issue. Below is the code that I 
> thought would set the document to disable modification and not allow 
> anyone to modify it; however, Acrobat version 10.0.3 has no issue with 
> writing in the file then printing the modifications. I am using 
> version 1.8.9 pdfBox.
> PDDocument documentToProtect= PDDocument.load(document);
> AccessPermission ap = new AccessPermission();
> ap.setCanModify(false);
> ap.setReadOnly();
> StandardProtectionPolicy policy = new 
> StandardProtectionPolicy("StandardProtectionPolicy","", ap);
> policy.setEncryptionKeyLength(128);
> documentToProtect.protect(policy);
> documentToProtect.save(document);
> documentToProtect.close();

I tested your code; setCanModify() works as described, however the 
dialog is hard to find in Adobe Reader, i.e. one has to click on 
security, then on details.

setReadOnly() either has no effect, or I can't see it because I don't 
have Acrobat Professional.

However... the javadoc tells:

      * Locks the access permission read only (ie, the setters will have 
no effects).
      * After that, the object cannot be unlocked.
      * This method is used for the currentAccessPermssion of a document 
to avoid
      * users to change access permission.


View raw message