pdfbox-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1764001&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/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1764001&r1=1764000&r2=1764001&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Oct  9
19:10:26 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;
@@ -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