Author: tilman Date: Fri Apr 22 15:42:32 2016 New Revision: 1740546 URL: http://svn.apache.org/viewvc?rev=1740546&view=rev Log: PDFBOX-3323: add possibility to set info and xmp after merge
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=1740546&r1=1740545&r2=1740546&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 Fri Apr 22 15:42:32 2016 @@ -45,6 +45,7 @@ import org.apache.pdfbox.pdmodel.PDDocum import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDResources; import org.apache.pdfbox.pdmodel.PageMode; +import org.apache.pdfbox.pdmodel.common.PDMetadata; import org.apache.pdfbox.pdmodel.common.PDNumberTreeNode; import org.apache.pdfbox.pdmodel.common.PDStream; import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDMarkInfo; @@ -71,6 +72,8 @@ public class PDFMergerUtility private String destinationFileName; private OutputStream destinationStream; private boolean ignoreAcroFormErrors = false; + private PDDocumentInformation destinationDocumentInformation = null; + private PDMetadata destinationMetadata = null; /** * Instantiate a new PDFMergerUtility. @@ -122,6 +125,50 @@ public class PDFMergerUtility } /** + * Get the destination document information that is to be set in {@link #mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) + * }. The default is null, which means that it is ignored. + * + * @return The destination document information. + */ + public PDDocumentInformation getDestinationDocumentInformation() + { + return destinationDocumentInformation; + } + + /** + * Set the destination document information that is to be set in {@link #mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) + * }. The default is null, which means that it is ignored. + * + * @param info The destination document information. + */ + public void setDestinationDocumentInformation(PDDocumentInformation info) + { + destinationDocumentInformation = info; + } + + /** + * Set the destination metadata that is to be set in {@link #mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) + * }. The default is null, which means that it is ignored. + * + * @return The destination metadata. + */ + public PDMetadata getDestinationMetadata() + { + return destinationMetadata; + } + + /** + * Set the destination metadata that is to be set in {@link #mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) + * }. The default is null, which means that it is ignored. + * + * @param meta The destination metadata. + */ + public void setDestinationMetadata(PDMetadata meta) + { + destinationMetadata = meta; + } + + /** * Add a source file to the list of files to merge. * * @param source Full path and file name of source document. @@ -213,6 +260,17 @@ public class PDFMergerUtility tobeclosed.add(source); appendDocument(destination, source); } + + // optionally set meta data + if (destinationDocumentInformation != null) + { + destination.setDocumentInformation(destinationDocumentInformation); + } + if (destinationMetadata != null) + { + destination.getDocumentCatalog().setMetadata(destinationMetadata); + } + if (destinationStream == null) { destination.save(destinationFileName);