Package org.apache.pdfbox.multipdf
Class PDFMergerUtility
java.lang.Object
org.apache.pdfbox.multipdf.PDFMergerUtility
This class will take a list of pdf documents and merge them, saving the
result in a new document.
- Author:
- Ben Litchfield
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe mode to use when merging AcroForm between documents:PDFMergerUtility.AcroFormMergeMode.JOIN_FORM_FIELDS_MODEfields with the same fully qualified name will be merged into one with the widget annotations of the merged fields becoming part of the same field.
Although the API is finalized processing of different form field types is still in development. Currently only (nested) text fields do work with intermediate nodes being existent.static enumThe mode to use when merging documents:PDFMergerUtility.DocumentMergeMode.OPTIMIZE_RESOURCES_MODEOptimizes resource handling such as closing documents early. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a source file to the list of files to merge.voidaddSource(InputStream source) Add a source to the list of documents to merge.voidAdd a source file to the list of files to merge.voidaddSources(List<InputStream> sourcesList) Add a list of sources to the list of documents to merge.voidappendDocument(PDDocument destination, PDDocument source) append all pages from source to destination.Get the merge mode to be used for merging AcroForms between documentsPDFMergerUtility.AcroFormMergeModeGet the destination document information that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).Get the name of the destination file.Set the destination metadata that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).Get the destination OutputStream.Get the merge mode to be used for merging documentsPDFMergerUtility.DocumentMergeModebooleanIndicates if acroform errors are ignored or not.voidDeprecated.voidmergeDocuments(MemoryUsageSetting memUsageSetting) Merge the list of source documents, saving the result in the destination file.voidsetAcroFormMergeMode(PDFMergerUtility.AcroFormMergeMode theAcroFormMergeMode) Set the merge mode to be used for merging AcroForms between documentsPDFMergerUtility.AcroFormMergeModevoidSet the destination document information that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).voidsetDestinationFileName(String destination) Set the name of the destination file.voidSet the destination metadata that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).voidsetDestinationStream(OutputStream destStream) Set the destination OutputStream.voidsetDocumentMergeMode(PDFMergerUtility.DocumentMergeMode theDocumentMergeMode) Set the merge mode to be used for merging documentsPDFMergerUtility.DocumentMergeModevoidsetIgnoreAcroFormErrors(boolean ignoreAcroFormErrorsValue) Set to true to ignore acroform errors.
-
Constructor Details
-
PDFMergerUtility
public PDFMergerUtility()Instantiate a new PDFMergerUtility.
-
-
Method Details
-
getAcroFormMergeMode
Get the merge mode to be used for merging AcroForms between documentsPDFMergerUtility.AcroFormMergeMode -
setAcroFormMergeMode
Set the merge mode to be used for merging AcroForms between documentsPDFMergerUtility.AcroFormMergeMode -
setDocumentMergeMode
Set the merge mode to be used for merging documentsPDFMergerUtility.DocumentMergeMode -
getDocumentMergeMode
Get the merge mode to be used for merging documentsPDFMergerUtility.DocumentMergeMode -
getDestinationFileName
Get the name of the destination file.- Returns:
- Returns the destination.
-
setDestinationFileName
Set the name of the destination file.- Parameters:
destination- The destination to set.
-
getDestinationStream
Get the destination OutputStream.- Returns:
- Returns the destination OutputStream.
-
setDestinationStream
Set the destination OutputStream.- Parameters:
destStream- The destination to set.
-
getDestinationDocumentInformation
Get the destination document information that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting). The default is null, which means that it is ignored.- Returns:
- The destination document information.
-
setDestinationDocumentInformation
Set the destination document information that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting). The default is null, which means that it is ignored.- Parameters:
info- The destination document information.
-
getDestinationMetadata
Set the destination metadata that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting). The default is null, which means that it is ignored.- Returns:
- The destination metadata.
-
setDestinationMetadata
Set the destination metadata that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting). The default is null, which means that it is ignored.- Parameters:
meta- The destination metadata.
-
addSource
Add a source file to the list of files to merge.- Parameters:
source- Full path and file name of source document.- Throws:
FileNotFoundException- If the file doesn't exist
-
addSource
Add a source file to the list of files to merge.- Parameters:
source- File representing source document- Throws:
FileNotFoundException- If the file doesn't exist
-
addSource
Add a source to the list of documents to merge.- Parameters:
source- InputStream representing source document
-
addSources
Add a list of sources to the list of documents to merge.- Parameters:
sourcesList- List of InputStream objects representing source documents
-
mergeDocuments
Deprecated.Merge the list of source documents, saving the result in the destination file.- Throws:
IOException- If there is an error saving the document.
-
mergeDocuments
Merge the list of source documents, saving the result in the destination file. The source list is not reset after merge. If you want to merge one document at a time, then it's better to useappendDocument(org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.PDDocument).- Parameters:
memUsageSetting- defines how memory is used for buffering PDF streams; in case ofnullunrestricted main memory is used- Throws:
IOException- If there is an error saving the document.
-
appendDocument
append all pages from source to destination.- Parameters:
destination- the document to receive the pagessource- the document originating the new pages- Throws:
IOException- If there is an error accessing data from either document.
-
isIgnoreAcroFormErrors
public boolean isIgnoreAcroFormErrors()Indicates if acroform errors are ignored or not.- Returns:
- true if acroform errors are ignored
-
setIgnoreAcroFormErrors
public void setIgnoreAcroFormErrors(boolean ignoreAcroFormErrorsValue) Set to true to ignore acroform errors.- Parameters:
ignoreAcroFormErrorsValue- true if acroform errors should be ignored
-
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting)