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 2017/05/20 15:30:53 UTC
svn commit: r1795668 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Author: tilman
Date: Sat May 20 15:30:53 2017
New Revision: 1795668
URL: http://svn.apache.org/viewvc?rev=1795668&view=rev
Log:
PDFBOX-3795: use private mergeInto instead of deprecated method
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1795668&r1=1795667&r2=1795668&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Sat May 20 15:30:53 2017
@@ -23,10 +23,14 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
@@ -328,9 +332,7 @@ public class PDFMergerUtility
PDDocumentInformation destInfo = destination.getDocumentInformation();
PDDocumentInformation srcInfo = source.getDocumentInformation();
- destInfo.getCOSObject().mergeInto(srcInfo.getCOSObject());
-
-
+ mergeInto(srcInfo.getCOSObject(), destInfo.getCOSObject(), Collections.<COSName>emptySet());
// use the highest version number for the resulting pdf
float destVersion = destination.getVersion();
@@ -490,9 +492,9 @@ public class PDFMergerUtility
COSStream srcMetadata = (COSStream) srcCatalog.getCOSObject().getDictionaryObject(COSName.METADATA);
if (destMetadata == null && srcMetadata != null)
{
- PDStream newStream = new PDStream(destination, srcMetadata.createInputStream(), (COSName) null);
- newStream.getCOSObject().mergeInto(srcMetadata);
- newStream.getCOSObject().removeItem(COSName.FILTER);
+ PDStream newStream = new PDStream(destination, srcMetadata.createInputStream(), (COSName) null);
+ mergeInto(srcMetadata, newStream.getCOSObject(),
+ new HashSet<COSName>(Arrays.asList(COSName.FILTER, COSName.LENGTH)));
destCatalog.getCOSObject().setItem(COSName.METADATA, newStream);
}
@@ -820,4 +822,24 @@ public class PDFMergerUtility
{
return acroForm != null && acroForm.xfaIsDynamic();
}
+
+ /**
+ * This will add all of the dictionarys keys/values to this dictionary, but only if they are not
+ * in an exclusion list and if they don't already exist. If a key already exists in this
+ * dictionary then nothing is changed.
+ *
+ * @param src The source dictionary to get the keys/values from.
+ * @param dst The destination dictionary to merge the keys/values into.
+ * @param exclude Names of keys that shall be skipped.
+ */
+ private void mergeInto(COSDictionary src, COSDictionary dst, Set<COSName> exclude)
+ {
+ for (Map.Entry<COSName, COSBase> entry : src.entrySet())
+ {
+ if (!exclude.contains(entry.getKey()) && !dst.containsKey(entry.getKey()))
+ {
+ dst.setItem(entry.getKey(), entry.getValue());
+ }
+ }
+ }
}