You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2015/03/04 08:47:13 UTC

svn commit: r1663874 - in /pdfbox/cmssite/trunk: content/1.8/cookbook/encryption.mdtext templates/skeleton.html

Author: msahyoun
Date: Wed Mar  4 07:47:12 2015
New Revision: 1663874

URL: http://svn.apache.org/r1663874
Log:
PDFBOX-1450 document encryption

Added:
    pdfbox/cmssite/trunk/content/1.8/cookbook/encryption.mdtext   (with props)
Modified:
    pdfbox/cmssite/trunk/templates/skeleton.html

Added: pdfbox/cmssite/trunk/content/1.8/cookbook/encryption.mdtext
URL: http://svn.apache.org/viewvc/pdfbox/cmssite/trunk/content/1.8/cookbook/encryption.mdtext?rev=1663874&view=auto
==============================================================================
--- pdfbox/cmssite/trunk/content/1.8/cookbook/encryption.mdtext (added)
+++ pdfbox/cmssite/trunk/content/1.8/cookbook/encryption.mdtext Wed Mar  4 07:47:12 2015
@@ -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();
\ No newline at end of file

Propchange: pdfbox/cmssite/trunk/content/1.8/cookbook/encryption.mdtext
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/cmssite/trunk/templates/skeleton.html
URL: http://svn.apache.org/viewvc/pdfbox/cmssite/trunk/templates/skeleton.html?rev=1663874&r1=1663873&r2=1663874&view=diff
==============================================================================
--- pdfbox/cmssite/trunk/templates/skeleton.html (original)
+++ pdfbox/cmssite/trunk/templates/skeleton.html Wed Mar  4 07:47:12 2015
@@ -118,6 +118,7 @@
                                 <ul>
                                     <li><a href="/1.8/cookbook/documentcreation.html">Document Creation</a></li>
                                     <li><a href="/1.8/cookbook/textextraction.html">Text Extraction</a></li>
+                                    <li><a href="/1.8/cookbook/encryption.html">Document Encryption</a></li>
                                     <li><a href="/1.8/cookbook/workingwithfonts.html">Working with Fonts</a></li>
                                     <li><a href="/1.8/cookbook/workingwithmetadata.html">Working with Metadata</a></li>
                                     <li><a href="/1.8/cookbook/workingwithattachments.html">Working with Attachments</a></li>