Posted By

markt22 on 10/12/17


Tagged

PDFBox


Versions (?)

PDFBox: Encrypting a PDF


 / Published in: Java
 

Creates a new document with a single page and adds standard encryption to it

  1. /**
  2.  * @param args the command line arguments
  3.  * @throws java.io.IOException
  4.  */
  5. public static void main(String[] args) throws IOException {
  6. PDDocument document = new PDDocument();
  7. PDPage page = new PDPage(PDRectangle.A4);
  8.  
  9. document.addPage(page);
  10.  
  11. AccessPermission permssion = new AccessPermission();
  12.  
  13. StandardProtectionPolicy policy = new StandardProtectionPolicy("ownerPassword", "userPassword", permssion);
  14.  
  15. policy.setEncryptionKeyLength(128);
  16.  
  17. policy.setPermissions(permssion);
  18.  
  19. document.protect(policy);
  20.  
  21. document.save("");
  22. document.close();
  23. }

Report this snippet  

You need to login to post a comment.