You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2020/12/23 20:11:10 UTC

svn commit: r1884759 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Author: lehmi
Date: Wed Dec 23 20:11:09 2020
New Revision: 1884759

URL: http://svn.apache.org/viewvc?rev=1884759&view=rev
Log:
PDFBOX-4952: use COSObject to preserve origin object key

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1884759&r1=1884758&r2=1884759&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Wed Dec 23 20:11:09 2020
@@ -492,9 +492,10 @@ public class COSWriter implements ICOSVi
     protected void doWriteBody(COSDocument doc) throws IOException
     {
         COSDictionary trailer = doc.getTrailer();
-        COSDictionary root = trailer.getCOSDictionary(COSName.ROOT);
-        COSDictionary info = trailer.getCOSDictionary(COSName.INFO);
-        COSDictionary encrypt = trailer.getCOSDictionary(COSName.ENCRYPT);
+        // get the COSObjects to preserve the origin object numbers
+        COSBase root = trailer.getItem(COSName.ROOT);
+        COSBase info = trailer.getItem(COSName.INFO);
+        COSBase encrypt = trailer.getItem(COSName.ENCRYPT);
         if( root != null )
         {
             addObjectToWrite( root );
@@ -503,7 +504,6 @@ public class COSWriter implements ICOSVi
         {
             addObjectToWrite( info );
         }
-
         doWriteObjects();
         willEncrypt = false;
         if( encrypt != null )
@@ -523,11 +523,10 @@ public class COSWriter implements ICOSVi
     private void doWriteBodyCompressed(COSDocument document) throws IOException
     {
         COSDictionary trailer = document.getTrailer();
-        COSDictionary root = trailer.getCOSDictionary(COSName.ROOT);
         COSDictionary encrypt = trailer.getCOSDictionary(COSName.ENCRYPT);
         blockAddingObject = true;
         willEncrypt = encrypt != null;
-        if (root != null)
+        if (trailer.containsKey(COSName.ROOT))
         {
             COSWriterCompressionPool compressionPool = new COSWriterCompressionPool(pdDocument,
                     compressParameters);