You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2015/02/06 17:18:26 UTC

pdfbox-docs git commit: PDFBOX-1450: encryption in cookbook

Repository: pdfbox-docs
Updated Branches:
  refs/heads/master 0df2cb09d -> 281369ec9


PDFBOX-1450: encryption in cookbook

Project: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/repo
Commit: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/commit/281369ec
Tree: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/tree/281369ec
Diff: http://git-wip-us.apache.org/repos/asf/pdfbox-docs/diff/281369ec

Branch: refs/heads/master
Commit: 281369ec90648c05a069235c7feff537610e53e2
Parents: 0df2cb0
Author: tilman <>
Authored: Fri Feb 6 17:17:15 2015 +0100
Committer: tilman <>
Committed: Fri Feb 6 17:17:15 2015 +0100

----------------------------------------------------------------------
 docs/1.8/cookbook/encrypt/encrypt.md | 50 +++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/pdfbox-docs/blob/281369ec/docs/1.8/cookbook/encrypt/encrypt.md
----------------------------------------------------------------------
diff --git a/docs/1.8/cookbook/encrypt/encrypt.md b/docs/1.8/cookbook/encrypt/encrypt.md
new file mode 100644
index 0000000..c610150
--- /dev/null
+++ b/docs/1.8/cookbook/encrypt/encrypt.md
@@ -0,0 +1,50 @@
+---
+license: Licensed to the Apache Software Foundation (ASF) under one
+         or more contributor license agreements.  See the NOTICE file
+         distributed with this work for additional information
+         regarding copyright ownership.  The ASF licenses this file
+         to you under the Apache License, Version 2.0 (the
+         "License"); you may not use this file except in compliance
+         with the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+         Unless required by applicable law or agreed to in writing,
+         software distributed under the License is distributed on an
+         "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+         KIND, either express or implied.  See the License for the
+         specific language governing permissions and limitations
+         under the License.
+         
+title: Cookbook - Encrypting a file
+---
+
+Encrypting a file
+=================
+
+PDF encryption requires two passwords: the "user password" to open and view the file with restricted permissions, the "owner password" to access the file with all permission.
+
+
+Load and save encrypted
+-----------------------
+
+This small sample shows how to encrypt a file so that it can be viewed, but not printed..
+
+	:::java
+        PDDocument doc = PDDocument.load("filename.pdf");
+
+        int keyLength = 128; // 40 or 128; 256 will be available in version 2.0
+        AccessPermission ap = new AccessPermission();
+        
+        // disable printing, everything else is allowed
+        ap.setCanPrint(false);
+        
+        // owner password (to open the file with all permissions) is "12345"
+        // user password (to open the file but with restricted permissions, is empty here) 
+        StandardProtectionPolicy spp = new StandardProtectionPolicy("12345", "", ap);
+        spp.setEncryptionKeyLength(keyLength);
+        spp.setPermissions(ap);
+        doc.protect(spp);
+        
+        doc.save("filename-encrypted.pdf");
+        doc.close();