title: Protecting PDF using PDFBox
body: <p>Im really struggling with the documentation for PDFBox. For such a popular library info seems to be a little thin on the ground (for me!).</p>
  
  <p>Anyway the problem Im having relates to protecting the PDF. At the moment all I want is to control the access permissions of the users. specifically I want to prevent the user from being able to modify the PDF.</p>
  
  <p>If I omit the access permission code everything works perfectly. I am reading in a PDF from an external resource. I am then reading and populating the fields, adding some images before saving the new PDF. That all works perfectly.</p>
  
  <p>The problem comes when I add the following code to manage the access:</p>
  
  <pre><code>/* Secure the PDF so that it cannot be edited */
  try {
      String ownerPassword = "DSTE$gewRges43";
      String userPassword = "";
  
      AccessPermission ap = new AccessPermission();
      ap.setCanModify(false);
  
      StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword, userPassword, ap);
      pdf.protect(spp);
  } catch (BadSecurityHandlerException ex) {
      Logger.getLogger(PDFManager.class.getName()).log(Level.SEVERE, null, ex);
  }
  </code></pre>
  
  <p>When I add this code, all the text and images are striped from the outgoing pdf. The fields are still present in the document but they are all empty and all the text and images that where part of the original PDF and that were added dynamically in the code are gone.</p>
  
  <p>UPDATE:
  Ok, as best as I can tell the problem is coming from a bug relating to the form fields. I'm going to try a different approach without the form fields and see what it gives.</p>