Package org.apache.pdfbox.multipdf
Class PDFMergerUtility
- java.lang.Object
-
- org.apache.pdfbox.multipdf.PDFMergerUtility
-
public class PDFMergerUtility extends java.lang.ObjectThis 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 Classes Modifier and Type Class Description static classPDFMergerUtility.DocumentMergeModeThe mode to use when merging documents:PDFMergerUtility.DocumentMergeMode.OPTIMIZE_RESOURCES_MODEOptimizes resource handling such as closing documents early.
-
Constructor Summary
Constructors Constructor Description PDFMergerUtility()Instantiate a new PDFMergerUtility.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddSource(java.io.File source)Add a source file to the list of files to merge.voidaddSource(java.io.InputStream source)Add a source to the list of documents to merge.voidaddSource(java.lang.String source)Add a source file to the list of files to merge.voidaddSources(java.util.List<java.io.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.PDDocumentInformationgetDestinationDocumentInformation()Get the destination document information that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).java.lang.StringgetDestinationFileName()Get the name of the destination file.PDMetadatagetDestinationMetadata()Set the destination metadata that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).java.io.OutputStreamgetDestinationStream()Get the destination OutputStream.booleanisIgnoreAcroFormErrors()Indicates if acroform errors are ignored or not.voidmergeDocuments()Deprecated.voidmergeDocuments(MemoryUsageSetting memUsageSetting)Merge the list of source documents, saving the result in the destination file.voidsetDestinationDocumentInformation(PDDocumentInformation info)Set the destination document information that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).voidsetDestinationFileName(java.lang.String destination)Set the name of the destination file.voidsetDestinationMetadata(PDMetadata meta)Set the destination metadata that is to be set inmergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting).voidsetDestinationStream(java.io.OutputStream destStream)Set the destination OutputStream.voidsetIgnoreAcroFormErrors(boolean ignoreAcroFormErrorsValue)Set to true to ignore acroform errors.
-
-
-
Method Detail
-
getDestinationFileName
public java.lang.String getDestinationFileName()
Get the name of the destination file.- Returns:
- Returns the destination.
-
setDestinationFileName
public void setDestinationFileName(java.lang.String destination)
Set the name of the destination file.- Parameters:
destination- The destination to set.
-
getDestinationStream
public java.io.OutputStream getDestinationStream()
Get the destination OutputStream.- Returns:
- Returns the destination OutputStream.
-
setDestinationStream
public void setDestinationStream(java.io.OutputStream destStream)
Set the destination OutputStream.- Parameters:
destStream- The destination to set.
-
getDestinationDocumentInformation
public PDDocumentInformation 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
public void setDestinationDocumentInformation(PDDocumentInformation info)
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
public PDMetadata 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
public void setDestinationMetadata(PDMetadata meta)
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
public void addSource(java.lang.String source) throws java.io.FileNotFoundExceptionAdd a source file to the list of files to merge.- Parameters:
source- Full path and file name of source document.- Throws:
java.io.FileNotFoundException- If the file doesn't exist
-
addSource
public void addSource(java.io.File source) throws java.io.FileNotFoundExceptionAdd a source file to the list of files to merge.- Parameters:
source- File representing source document- Throws:
java.io.FileNotFoundException- If the file doesn't exist
-
addSource
public void addSource(java.io.InputStream source)
Add a source to the list of documents to merge.- Parameters:
source- InputStream representing source document
-
addSources
public void addSources(java.util.List<java.io.InputStream> sourcesList)
Add a list of sources to the list of documents to merge.- Parameters:
sourcesList- List of InputStream objects representing source documents
-
mergeDocuments
@Deprecated public void mergeDocuments() throws java.io.IOExceptionDeprecated.Merge the list of source documents, saving the result in the destination file.- Throws:
java.io.IOException- If there is an error saving the document.
-
mergeDocuments
public void mergeDocuments(MemoryUsageSetting memUsageSetting) throws java.io.IOException
Merge the list of source documents, saving the result in the destination file.- Parameters:
memUsageSetting- defines how memory is used for buffering PDF streams; in case ofnullunrestricted main memory is used- Throws:
java.io.IOException- If there is an error saving the document.
-
appendDocument
public void appendDocument(PDDocument destination, PDDocument source) throws java.io.IOException
append all pages from source to destination.- Parameters:
destination- the document to receive the pagessource- the document originating the new pages- Throws:
java.io.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
-
-