Author: lehmi Date: Fri Mar 1 07:25:11 2024 New Revision: 1916065 URL: http://svn.apache.org/viewvc?rev=1916065&view=rev Log: PDFBOX-5752: eliminate overlapping object keys after importing some external content
Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/compress/COSWriterCompressionPool.java Modified: pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/compress/COSWriterCompressionPool.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/compress/COSWriterCompressionPool.java?rev=1916065&r1=1916064&r2=1916065&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/compress/COSWriterCompressionPool.java (original) +++ pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/compress/COSWriterCompressionPool.java Fri Mar 1 07:25:11 2024 @@ -127,6 +127,12 @@ public class COSWriterCompressionPool { return current; } + // check if the key of the indirect object matches the key of the referenced object + // otherwise update the key + if (!actualKey.equals(key) && base instanceof COSObject) + { + base.setKey(actualKey); + } topLevelObjects.add(actualKey); return current; } @@ -137,6 +143,12 @@ public class COSWriterCompressionPool { return current; } + // check if the key of the indirect object matches the key of the referenced object + // otherwise update the key + if (!actualKey.equals(key) && base instanceof COSObject) + { + base.setKey(actualKey); + } // Append it to an object stream. this.objectStreamObjects.add(actualKey); @@ -194,7 +206,13 @@ public class COSWriterCompressionPool COSObject cosObject = (COSObject) value; if (cosObject.getKey() != null && objectPool.contains(cosObject.getKey())) { - continue; + // check if the stored object matches the referenced object otherwise replace the key with a new one + // there may differences if some imported content uses the same object numbers than the target pdf + if (objectPool.getObject(cosObject.getKey()).equals(cosObject.getObject())) + { + continue; + } + cosObject.setKey(null); } if (cosObject.getObject() != null) {