pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1601490 - /pdfbox/branches/1.8/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java
Date Mon, 09 Jun 2014 19:35:55 GMT
Author: tilman
Date: Mon Jun  9 19:35:55 2014
New Revision: 1601490

URL: http://svn.apache.org/r1601490
Log:
PDFBOX-54: error message if document is encrypted

Modified:
    pdfbox/branches/1.8/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java

Modified: pdfbox/branches/1.8/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java?rev=1601490&r1=1601489&r2=1601490&view=diff
==============================================================================
--- pdfbox/branches/1.8/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java
(original)
+++ pdfbox/branches/1.8/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java
Mon Jun  9 19:35:55 2014
@@ -27,6 +27,8 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.exceptions.COSVisitorException;
 
 import org.apache.pdfbox.examples.AbstractExample;
+import org.apache.pdfbox.exceptions.CryptographyException;
+import org.apache.pdfbox.exceptions.InvalidPasswordException;
 
 /**
  * This example will take a PDF document and set a FDF field in it.
@@ -72,13 +74,15 @@ public class SetField extends AbstractEx
      * @throws IOException If there is an error importing the FDF document.
      * @throws COSVisitorException If there is an error writing the PDF.
      */
-    public static void main(String[] args) throws IOException, COSVisitorException
+    public static void main(String[] args) 
+            throws IOException, COSVisitorException, CryptographyException
     {
         SetField setter = new SetField();
         setter.setField( args );
     }
 
-    private void setField( String[] args ) throws IOException, COSVisitorException
+    private void setField( String[] args ) 
+            throws IOException, COSVisitorException, CryptographyException
     {
         PDDocument pdf = null;
         try
@@ -92,6 +96,18 @@ public class SetField extends AbstractEx
                 SetField example = new SetField();
 
                 pdf = PDDocument.load( args[0] );
+                if (pdf.isEncrypted())
+                {
+                    try
+                    {
+                        pdf.decrypt("");
+                    }
+                    catch (InvalidPasswordException e)
+                    {
+                        System.err.println("Error: The document is encrypted.");
+                        usage();
+                    }
+                }
                 example.setField( pdf, args[1], args[2] );
                 pdf.save( args[0] );
             }



Mime
View raw message