You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/10/09 20:38:54 UTC

svn commit: r1764010 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Author: tilman
Date: Sun Oct  9 20:38:54 2016
New Revision: 1764010

URL: http://svn.apache.org/viewvc?rev=1764010&view=rev
Log:
PDFBOX-3525: move the signature check to visitFromDictionary(), because it didn't work when the signaturefield is a direct object

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1764010&r1=1764009&r2=1764010&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Sun Oct  9 20:38:54 2016
@@ -507,15 +507,6 @@ public class COSWriter implements ICOSVi
     public void doWriteObject( COSBase obj ) throws IOException
     {
         writtenObjects.add( obj );
-        if(obj instanceof COSDictionary)
-        {
-            COSBase itemType = ((COSDictionary) obj).getItem(COSName.TYPE);
-            if (COSName.SIG.equals(itemType) || COSName.DOC_TIME_STAMP.equals(itemType))
-            {
-                reachedSignature = true;
-            }
-        }
-
         // find the physical reference
         currentObjectKey = getObjectKey( obj );
         // add a x ref entry
@@ -743,7 +734,7 @@ public class COSWriter implements ICOSVi
      * signatures externally. {@link #write(PDDocument)} method should have been called prior.
      * The created signature should be set using {@link #writeExternalSignature(byte[])}.
      * <p>
-     * When {@link SignatureInterface} instance is used, COSWriter obtains and writes the signature itsef.
+     * When {@link SignatureInterface} instance is used, COSWriter obtains and writes the signature itself.
      * </p>
      *
      * @return data stream to be signed
@@ -978,6 +969,14 @@ public class COSWriter implements ICOSVi
     @Override
     public Object visitFromDictionary(COSDictionary obj) throws IOException
     {
+        if (!reachedSignature)
+        {
+            COSBase itemType = obj.getItem(COSName.TYPE);
+            if (COSName.SIG.equals(itemType) || COSName.DOC_TIME_STAMP.equals(itemType))
+            {
+                reachedSignature = true;
+            }
+        }        
         getStandardOutput().write(DICT_OPEN);
         getStandardOutput().writeEOL();
         for (Map.Entry<COSName, COSBase> entry : obj.entrySet())