Top Description Fields Constructors Methods
org.apache.pdfbox.examples.util

public Class PDFMergerExample

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, org.apache.pdfbox.cos.COSStream, .COSName, org.apache.pdfbox.io.RandomAccessRead, .IOUtils, org.apache.pdfbox.multipdf.PDFMergerUtility, org.apache.pdfbox.pdmodel.PDDocumentInformation, org.apache.pdfbox.pdmodel.common.PDMetadata, org.apache.xmpbox.XMPMetadata, org.apache.xmpbox.schema.DublinCoreSchema, .PDFAIdentificationSchema, .XMPBasicSchema, org.apache.xmpbox.type.BadFieldValueException, org.apache.xmpbox.xml.XmpSerializer, java.util.Calendar, .List, javax.xml.transform.TransformerException, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.pdfwriter.compress.CompressParameters

This example demonstrates the use of the new methods PDFMergerUtility#setDestinationDocumentInformation(org.apache.pdfbox.pdmodel.PDDocumentInformation) and PDFMergerUtility#setDestinationMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) that were added in April 2016. These allow to control the meta data in a merge without having to reopen the result file.
Author
Alexander Kriegisch

Field Summary

Modifier and TypeField and Description
private static final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private PDDocumentInformation
createPDFDocumentInfo(String title, String creator, String subject)

private PDFMergerUtility
private PDMetadata
createXMPMetadata(COSStream cosStream, String title, String creator, String subject)

public InputStream

Returns:

compound PDF document as a readable input stream.
merge
(final List<RandomAccessRead>
list of source PDF documents as RandomAccessRead.
sources
)

Creates a compound PDF document from a list of input documents.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG

Constructor Detail

PDFMergerExampleback to summary
public PDFMergerExample()

Method Detail

createPDFDocumentInfoback to summary
private PDDocumentInformation createPDFDocumentInfo(String title, String creator, String subject)
createPDFMergerUtilityback to summary
private PDFMergerUtility createPDFMergerUtility(List<RandomAccessRead> sources, ByteArrayOutputStream mergedPDFOutputStream)
createXMPMetadataback to summary
private PDMetadata createXMPMetadata(COSStream cosStream, String title, String creator, String subject) throws BadFieldValueException, TransformerException, IOException
mergeback to summary
public InputStream merge(final List<RandomAccessRead> sources) throws IOException

Creates a compound PDF document from a list of input documents.

The merged document is PDF/A-1b compliant, provided the source documents are as well. It contains document properties title, creator and subject, currently hard-coded.

Parameters
sources:List<RandomAccessRead>

list of source PDF documents as RandomAccessRead.

Returns:InputStream

compound PDF document as a readable input stream.

Exceptions
IOException:
if anything goes wrong during PDF merge.