Help save net neutrality! Learn more.

How to set AccessPermissions on doc?

  • Kurt Kellner

    Kurt Kellner - 2008-08-07

    I can see the existing permissions on a PDF file via this:

      PDDocument doc = basicOpen("c://example_pdf_doc.pdf");
      IAccessPermissions perms = doc.getAccessPermissions();
      System.out.println("May Print:"+perms.mayPrint());
      System.out.println("May Copy:"+perms.mayCopy());

    How do you change the access permissions?  I want to remove the ability to copy and print (or to put it another way, I want to add the permission restriction to prevent copy and print).

    I thinking it might be something like this, but I don't know what values to put in the attribute.  Maybe this isn't even the correct way to do this.

      COSDictionary cosDict = COSDictionary.create();
      cosDict.setAttribute("somekey", "somevalue");

    • mtraut

      mtraut - 2008-08-07

      Setting permissions on a document is not just a one liner.

      you must
      - set up a dictionary for use as /Encrypt in the trailer
      - set the new permissions in the dict
      - provide a SecurityHandler
      - compute NEW keys from the passwords
      - write the complete document from scratch

      This is a rough overview, involving some more or less difficult steps (well documented in the PDF spec).

      While everything you need is in place with jPod, there is currently no example available. I will change this with release 5.0 (this month).

      • Kurt Kellner

        Kurt Kellner - 2008-08-07

        Ok, more complex then I thought.  Are you saying that in release 5.0 that you will have an example of modifying these attributes (copy/print allowed)?  If so, then it would be worth me waiting for your example.


        • mtraut

          mtraut - 2008-08-07

          I will try my best.


Log in to post a comment.