Index: PDFMergerUtility.java
===================================================================
--- PDFMergerUtility.java (revision 828085)
+++ PDFMergerUtility.java (working copy)
@@ -224,9 +224,17 @@
}
else
{
- //warning, potential for collision here!!
- destNames.getCOSDictionary().mergeInto( (COSDictionary)cloneForNewDocument( destination, srcNames ) );
- }
+// ### outcommented original code
+ //warning, potential for collision here!!
+// COSDictionary x = (COSDictionary)cloneForNewDocument( destination, srcNames );
+
+// destNames.getCOSDictionary().mergeInto( x ); // ### this will just keep the destNames and not add x's Kids
+// destNames.getCOSDictionary().addAll( x ); // ### alt: will will replace destNames Kids with x's
+
+ cloneMerge(destination, srcNames, destNames);
+
+ }
+
}
PDDocumentOutline destOutline = destCatalog.getDocumentOutline();
@@ -313,6 +321,14 @@
}
Map clonedVersion = new HashMap();
+
+ /**
+ *
+ * @param destination
+ * @param base
+ * @return
+ * @throws IOException
+ */
private COSBase cloneForNewDocument( PDDocument destination, Object base ) throws IOException
{
if( base == null )
@@ -389,6 +405,97 @@
return retval;
}
+
+ /**
+ * Deep clone and Merge from Base to Target.
+ * base and target must be instances of the same class.
+ * @param destination
+ * @param base
+ * @param target
+ * @throws IOException
+ */
+ private void cloneMerge( PDDocument destination, COSObjectable base, COSObjectable target) throws IOException
+ {
+ if( base == null )
+ {
+ return;
+ }
+ COSBase retval = (COSBase)clonedVersion.get( base );
+ if( retval != null )
+ {
+ return;
+ //we are done, it has already been converted. // ### Is that correct for cloneMerge???
+ }
+ else if( base instanceof List )
+ {
+ COSArray array = new COSArray();
+ List list = (List)base;
+ for( int i=0; i