pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1764000 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
Date Sun, 09 Oct 2016 19:10:21 GMT
Author: tilman
Date: Sun Oct  9 19:10:21 2016
New Revision: 1764000

URL: http://svn.apache.org/viewvc?rev=1764000&view=rev
Log:
PDFBOX-3525: set signature object for update when existing; add widget only if not already
in the annotation list or set for update

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1764000&r1=1763999&r2=1764000&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun
Oct  9 19:10:21 2016
@@ -55,6 +55,7 @@ import org.apache.pdfbox.pdmodel.encrypt
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.ExternalSigningSupport;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
@@ -74,7 +75,7 @@ import org.apache.pdfbox.pdmodel.interac
 public class PDDocument implements Closeable
 {
     private static final Log LOG = LogFactory.getLog(PDDocument.class);
-    
+
     /**
      * avoid concurrency issues with PDDeviceRGB
      */
@@ -82,7 +83,7 @@ public class PDDocument implements Close
     {
     	PDDeviceRGB.INSTANCE.toRGB(new float[]{1,1,1,1});
     }
-
+    
     private final COSDocument document;
 
     // cached values
@@ -108,7 +109,7 @@ public class PDDocument implements Close
     
     // fonts to subset before saving
     private final Set<PDFont> fontsToSubset = new HashSet<PDFont>();
-
+    
     // Signature interface
     private SignatureInterface signInterface;
 
@@ -117,7 +118,7 @@ public class PDDocument implements Close
 
     // document-wide cached resources
     private ResourceCache resourceCache = new DefaultResourceCache();
-
+    
     /**
      * Creates an empty PDF document.
      * You need to add at least one page for the document to be valid.
@@ -301,6 +302,11 @@ public class PDDocument implements Close
             // backward linking
             signatureField.getWidgets().get(0).setPage(page);
         }
+        else
+        {
+            sigObject.getCOSObject().setNeedToBeUpdated(true);
+        }
+
         // to conform PDF/A-1 requirement:
         // The /F key's Print flag bit shall be set to 1 and 
         // its Hidden, Invisible and NoView flag bits shall be set to 0
@@ -349,7 +355,16 @@ public class PDDocument implements Close
               ((COSArrayList<?>) annotations).toList().equals(((COSArrayList<?>)
acroFormFields).toList()) &&
               checkFields))
         {
-            annotations.add(signatureField.getWidgets().get(0));
+            PDAnnotationWidget widget = signatureField.getWidgets().get(0);
+            // use check to prevent the annotation widget from appearing twice
+            if (checkSignatureAnnotation(annotations, widget))
+            {
+                widget.getCOSObject().setNeedToBeUpdated(true);
+            }
+            else
+            {
+                annotations.add(widget);
+            }   
         }
         page.getCOSObject().setNeedToBeUpdated(true);
     }
@@ -392,6 +407,25 @@ public class PDDocument implements Close
         }
         return false;
     }
+
+    /**
+     * Check if the widget already exists in the annotation list
+     *
+     * @param acroFormFields the list of AcroForm fields.
+     * @param signatureField the signature field.
+     * @return true if the widget already existed in the annotation list, false if not.
+     */
+    private boolean checkSignatureAnnotation(List<PDAnnotation> annotations, PDAnnotationWidget
widget)
+    {
+        for (PDAnnotation annotation : annotations)
+        {
+            if (annotation.getCOSObject().equals(widget.getCOSObject()))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
 
     private void prepareVisibleSignature(PDSignatureField signatureField, PDAcroForm acroForm,

             COSDocument visualSignature)



Mime
View raw message