Package org.apache.pdfbox.examples.util
Class PDFMergerExample
- java.lang.Object
-
- org.apache.pdfbox.examples.util.PDFMergerExample
-
public class PDFMergerExample extends java.lang.ObjectThis example demonstrates the use of the new methodsPDFMergerUtility.setDestinationDocumentInformation(org.apache.pdfbox.pdmodel.PDDocumentInformation)andPDFMergerUtility.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.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.commons.logging.LogLOG
-
Constructor Summary
Constructors Constructor Description PDFMergerExample()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private PDDocumentInformationcreatePDFDocumentInfo(java.lang.String title, java.lang.String creator, java.lang.String subject)private PDFMergerUtilitycreatePDFMergerUtility(java.util.List<RandomAccessRead> sources, java.io.ByteArrayOutputStream mergedPDFOutputStream)private PDMetadatacreateXMPMetadata(COSStream cosStream, java.lang.String title, java.lang.String creator, java.lang.String subject)java.io.InputStreammerge(java.util.List<RandomAccessRead> sources)Creates a compound PDF document from a list of input documents.
-
-
-
Method Detail
-
merge
public java.io.InputStream merge(java.util.List<RandomAccessRead> sources) throws java.io.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 of source PDF documents as RandomAccessRead.- Returns:
- compound PDF document as a readable input stream.
- Throws:
java.io.IOException- if anything goes wrong during PDF merge.
-
createPDFMergerUtility
private PDFMergerUtility createPDFMergerUtility(java.util.List<RandomAccessRead> sources, java.io.ByteArrayOutputStream mergedPDFOutputStream)
-
createPDFDocumentInfo
private PDDocumentInformation createPDFDocumentInfo(java.lang.String title, java.lang.String creator, java.lang.String subject)
-
createXMPMetadata
private PDMetadata createXMPMetadata(COSStream cosStream, java.lang.String title, java.lang.String creator, java.lang.String subject) throws BadFieldValueException, javax.xml.transform.TransformerException, java.io.IOException
- Throws:
BadFieldValueExceptionjavax.xml.transform.TransformerExceptionjava.io.IOException
-
-