pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1813335 - in /pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature: CreateSignature.java CreateSignatureBase.java CreateVisibleSignature.java
Date Wed, 25 Oct 2017 18:35:45 GMT
Author: tilman
Date: Wed Oct 25 18:35:44 2017
New Revision: 1813335

URL: http://svn.apache.org/viewvc?rev=1813335&view=rev
Log:
PDFBOX-1848: remove MDP methods from base class; adjust calls

Modified:
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java
    pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java?rev=1813335&r1=1813334&r2=1813335&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
(original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignature.java
Wed Oct 25 18:35:44 2017
@@ -115,7 +115,7 @@ public class CreateSignature extends Cre
     {
         setTsaClient(tsaClient);
 
-        int accessPermissions = getMDPPermission(document);
+        int accessPermissions = SigUtils.getMDPPermission(document);
         if (accessPermissions == 1)
         {
             throw new IllegalStateException("No changes to the document are permitted due
to DocMDP transform parameters dictionary");
@@ -136,7 +136,7 @@ public class CreateSignature extends Cre
         // Optional: certify 
         if (accessPermissions == 0)
         {
-            setMDPPermission(document, signature, 2);
+            SigUtils.setMDPPermission(document, signature, 2);
         }        
 
         if (isExternalSigning())

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java?rev=1813335&r1=1813334&r2=1813335&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java
(original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateSignatureBase.java
Wed Oct 25 18:35:44 2017
@@ -263,88 +263,4 @@ public abstract class CreateSignatureBas
     {
         return externalSigning;
     }
-
-    /**
-     * Get the access permissions granted for this document in the DocMDP transform parameters
-     * dictionary. Details are described in the table "Entries in the DocMDP transform parameters
-     * dictionary" in the PDF specification.
-     *
-     * @param doc document.
-     * @return the permission value. 0 means no DocMDP transform parameters dictionary exists.
Other
-     * return values are 1, 2 or 3. 2 is also returned if the DocMDP transform parameters
dictionary
-     * is found but did not contain a /P entry, or if the value is outside the valid range.
-     */
-    public int getMDPPermission(PDDocument doc)
-    {
-        COSBase base = doc.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PERMS);
-        if (base instanceof COSDictionary)
-        {
-            COSDictionary permsDict = (COSDictionary) base;
-            base = permsDict.getDictionaryObject(COSName.DOCMDP);
-            if (base instanceof COSDictionary)
-            {
-                COSDictionary signatureDict = (COSDictionary) base;
-                base = signatureDict.getDictionaryObject("Reference");
-                if (base instanceof COSArray)
-                {
-                    COSArray refArray = (COSArray) base;
-                    for (int i = 0; i < refArray.size(); ++i)
-                    {
-                        base = refArray.getObject(i);
-                        if (base instanceof COSDictionary)
-                        {
-                            COSDictionary sigRefDict = (COSDictionary) base;
-                            if (COSName.DOCMDP.equals(sigRefDict.getDictionaryObject("TransformMethod")))
-                            {
-                                base = sigRefDict.getDictionaryObject("TransformParams");
-                                if (base instanceof COSDictionary)
-                                {
-                                    COSDictionary transformDict = (COSDictionary) base;
-                                    int accessPermissions = transformDict.getInt(COSName.P,
2);
-                                    if (accessPermissions < 1 || accessPermissions >
3)
-                                    {
-                                        accessPermissions = 2;
-                                    }
-                                    return accessPermissions;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return 0;
-    }
-
-    public void setMDPPermission(PDDocument doc, PDSignature signature, int accessPermissions)
-    {
-        COSDictionary sigDict = signature.getCOSObject();
-
-        // DocMDP specific stuff
-        COSDictionary transformParameters = new COSDictionary();
-        transformParameters.setItem(COSName.TYPE, COSName.getPDFName("TransformParams"));
-        transformParameters.setInt(COSName.P, accessPermissions);
-        transformParameters.setName(COSName.V, "1.2");
-        transformParameters.setNeedToBeUpdated(true);
-
-        COSDictionary referenceDict = new COSDictionary();
-        referenceDict.setItem(COSName.TYPE, COSName.getPDFName("SigRef"));
-        referenceDict.setItem("TransformMethod", COSName.getPDFName("DocMDP"));
-        referenceDict.setItem("DigestMethod", COSName.getPDFName("SHA1"));
-        referenceDict.setItem("TransformParams", transformParameters);
-        referenceDict.setNeedToBeUpdated(true);
-
-        COSArray referenceArray = new COSArray();
-        referenceArray.add(referenceDict);
-        sigDict.setItem("Reference", referenceArray);
-        referenceArray.setNeedToBeUpdated(true);
-
-        // Catalog
-        COSDictionary catalogDict = doc.getDocumentCatalog().getCOSObject();
-        COSDictionary permsDict = new COSDictionary();
-        catalogDict.setItem(COSName.PERMS, permsDict);
-        permsDict.setItem(COSName.DOCMDP, signature);
-        catalogDict.setNeedToBeUpdated(true);
-        permsDict.setNeedToBeUpdated(true);
-    }
 }

Modified: pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java?rev=1813335&r1=1813334&r2=1813335&view=diff
==============================================================================
--- pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
(original)
+++ pdfbox/branches/2.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
Wed Oct 25 18:35:44 2017
@@ -196,7 +196,7 @@ public class CreateVisibleSignature exte
         // load document
         PDDocument doc = PDDocument.load(inputFile);
 
-        int accessPermissions = getMDPPermission(doc);
+        int accessPermissions = SigUtils.getMDPPermission(doc);
         if (accessPermissions == 1)
         {
             throw new IllegalStateException("No changes to the document are permitted due
to DocMDP transform parameters dictionary");
@@ -222,7 +222,7 @@ public class CreateVisibleSignature exte
         // PDF/A-1b requires PDF version 1.4 max, so don't increase the version on such files.
         if (doc.getVersion() >= 1.5f && accessPermissions == 0)
         {
-            setMDPPermission(doc, signature, 2);
+            SigUtils.setMDPPermission(doc, signature, 2);
         }
 
         PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();



Mime
View raw message