public class PDFMergerUtility
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PDFMergerUtility.AcroFormMergeMode
The mode to use when merging AcroForm between documents:
PDFMergerUtility.AcroFormMergeMode.JOIN_FORM_FIELDS_MODE fields 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 class |
PDFMergerUtility.DocumentMergeMode
The mode to use when merging documents:
PDFMergerUtility.DocumentMergeMode.OPTIMIZE_RESOURCES_MODE Optimizes resource handling such as
closing documents early. |
Modifier and Type | Field and Description |
---|---|
private PDFMergerUtility.AcroFormMergeMode |
acroFormMergeMode |
private PDDocumentInformation |
destinationDocumentInformation |
private java.lang.String |
destinationFileName |
private PDMetadata |
destinationMetadata |
private java.io.OutputStream |
destinationStream |
private PDFMergerUtility.DocumentMergeMode |
documentMergeMode |
private boolean |
ignoreAcroFormErrors |
private static org.apache.commons.logging.Log |
LOG
Log instance.
|
private int |
nextFieldNum |
private java.util.List<java.lang.Object> |
sources |
Constructor and Description |
---|
PDFMergerUtility()
Instantiate a new PDFMergerUtility.
|
Modifier and Type | Method and Description |
---|---|
private void |
acroFormJoinFieldsMode(PDFCloneUtility cloner,
PDAcroForm destAcroForm,
PDAcroForm srcAcroForm) |
private void |
acroFormLegacyMode(PDFCloneUtility cloner,
PDAcroForm destAcroForm,
PDAcroForm srcAcroForm) |
void |
addSource(java.io.File source)
Add a source file to the list of files to merge.
|
void |
addSource(java.io.InputStream source)
Add a source to the list of documents to merge.
|
void |
addSource(java.lang.String source)
Add a source file to the list of files to merge.
|
void |
addSources(java.util.List<java.io.InputStream> sourcesList)
Add a list of sources to the list of documents to merge.
|
void |
appendDocument(PDDocument destination,
PDDocument source)
append all pages from source to destination.
|
private void |
cleanupFieldCOSDictionary(COSDictionary fieldCos) |
private void |
cleanupWidgetCOSDictionary(COSDictionary widgetCos,
boolean removeDAEntry) |
PDFMergerUtility.AcroFormMergeMode |
getAcroFormMergeMode()
Get the merge mode to be used for merging AcroForms between documents
PDFMergerUtility.AcroFormMergeMode |
PDDocumentInformation |
getDestinationDocumentInformation()
Get the destination document information that is to be set in
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) . |
java.lang.String |
getDestinationFileName()
Get the name of the destination file.
|
PDMetadata |
getDestinationMetadata()
Set the destination metadata that is to be set in
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) . |
java.io.OutputStream |
getDestinationStream()
Get the destination OutputStream.
|
PDFMergerUtility.DocumentMergeMode |
getDocumentMergeMode()
Get the merge mode to be used for merging documents
PDFMergerUtility.DocumentMergeMode |
(package private) static java.util.Map<java.lang.String,PDStructureElement> |
getIDTreeAsMap(PDNameTreeNode<PDStructureElement> idTree) |
(package private) static java.util.Map<java.lang.Integer,COSObjectable> |
getNumberTreeAsMap(PDNumberTreeNode tree) |
private boolean |
isDynamicXfa(PDAcroForm acroForm)
Test for dynamic XFA content.
|
boolean |
isIgnoreAcroFormErrors()
Indicates if acroform errors are ignored or not.
|
private void |
legacyMergeDocuments(MemoryUsageSetting memUsageSetting)
Merge the list of source documents, saving the result in the destination
file.
|
private void |
mergeAcroForm(PDFCloneUtility cloner,
PDDocumentCatalog destCatalog,
PDDocumentCatalog srcCatalog)
Merge the contents of the source form into the destination form for the
destination file.
|
void |
mergeDocuments()
Deprecated.
|
void |
mergeDocuments(MemoryUsageSetting memUsageSetting)
Merge the list of source documents, saving the result in the destination
file.
|
private void |
mergeFields(PDFCloneUtility cloner,
PDField destField,
PDField srcField) |
private void |
mergeIDTree(PDFCloneUtility cloner,
PDStructureTreeRoot srcStructTree,
PDStructureTreeRoot destStructTree) |
private void |
mergeInto(COSDictionary src,
COSDictionary dst,
java.util.Set<COSName> exclude)
This will add all of the dictionaries keys/values to this dictionary, but
only if they are not in an exclusion list and if they don't already
exist.
|
private void |
mergeKEntries(PDFCloneUtility cloner,
PDStructureTreeRoot srcStructTree,
PDStructureTreeRoot destStructTree) |
private void |
mergeLanguage(PDDocumentCatalog destCatalog,
PDDocumentCatalog srcCatalog) |
private void |
mergeMarkInfo(PDDocumentCatalog destCatalog,
PDDocumentCatalog srcCatalog) |
private void |
mergeOutputIntents(PDFCloneUtility cloner,
PDDocumentCatalog srcCatalog,
PDDocumentCatalog destCatalog) |
private void |
mergeRoleMap(PDStructureTreeRoot srcStructTree,
PDStructureTreeRoot destStructTree) |
private void |
mergeViewerPreferences(PDDocumentCatalog destCatalog,
PDDocumentCatalog srcCatalog) |
private void |
optimizedMergeDocuments(MemoryUsageSetting memUsageSetting) |
void |
setAcroFormMergeMode(PDFMergerUtility.AcroFormMergeMode theAcroFormMergeMode)
Set the merge mode to be used for merging AcroForms between documents
PDFMergerUtility.AcroFormMergeMode |
void |
setDestinationDocumentInformation(PDDocumentInformation info)
Set the destination document information that is to be set in
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) . |
void |
setDestinationFileName(java.lang.String destination)
Set the name of the destination file.
|
void |
setDestinationMetadata(PDMetadata meta)
Set the destination metadata that is to be set in
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting) . |
void |
setDestinationStream(java.io.OutputStream destStream)
Set the destination OutputStream.
|
void |
setDocumentMergeMode(PDFMergerUtility.DocumentMergeMode theDocumentMergeMode)
Set the merge mode to be used for merging documents
PDFMergerUtility.DocumentMergeMode |
void |
setIgnoreAcroFormErrors(boolean ignoreAcroFormErrorsValue)
Set to true to ignore acroform errors.
|
private void |
updatePageReferences(PDFCloneUtility cloner,
COSArray parentTreeEntry,
java.util.Map<COSDictionary,COSDictionary> objMapping) |
private void |
updatePageReferences(PDFCloneUtility cloner,
COSDictionary parentTreeEntry,
java.util.Map<COSDictionary,COSDictionary> objMapping)
Update the Pg and Obj references to the new (merged) page.
|
private void |
updatePageReferences(PDFCloneUtility cloner,
java.util.Map<java.lang.Integer,COSObjectable> numberTreeAsMap,
java.util.Map<COSDictionary,COSDictionary> objMapping)
Update the Pg and Obj references to the new (merged) page.
|
private void |
updateParentEntry(COSArray kArray,
COSDictionary newParent)
Update the P reference to the new parent dictionary.
|
private void |
updateStructParentEntries(PDPage page,
int structParentOffset)
Update the StructParents and StructParent values in a PDPage.
|
private static final org.apache.commons.logging.Log LOG
private final java.util.List<java.lang.Object> sources
private java.lang.String destinationFileName
private java.io.OutputStream destinationStream
private boolean ignoreAcroFormErrors
private PDDocumentInformation destinationDocumentInformation
private PDMetadata destinationMetadata
private PDFMergerUtility.DocumentMergeMode documentMergeMode
private PDFMergerUtility.AcroFormMergeMode acroFormMergeMode
private int nextFieldNum
public PDFMergerUtility.AcroFormMergeMode getAcroFormMergeMode()
PDFMergerUtility.AcroFormMergeMode
public void setAcroFormMergeMode(PDFMergerUtility.AcroFormMergeMode theAcroFormMergeMode)
PDFMergerUtility.AcroFormMergeMode
public void setDocumentMergeMode(PDFMergerUtility.DocumentMergeMode theDocumentMergeMode)
PDFMergerUtility.DocumentMergeMode
public PDFMergerUtility.DocumentMergeMode getDocumentMergeMode()
PDFMergerUtility.DocumentMergeMode
public java.lang.String getDestinationFileName()
public void setDestinationFileName(java.lang.String destination)
destination
- The destination to set.public java.io.OutputStream getDestinationStream()
public void setDestinationStream(java.io.OutputStream destStream)
destStream
- The destination to set.public PDDocumentInformation getDestinationDocumentInformation()
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting)
. The default is null, which means that it is ignored.public void setDestinationDocumentInformation(PDDocumentInformation info)
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting)
. The default is null, which means that it is ignored.info
- The destination document information.public PDMetadata getDestinationMetadata()
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting)
. The default is null, which means that it is ignored.public void setDestinationMetadata(PDMetadata meta)
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting)
. The default is null, which means that it is ignored.meta
- The destination metadata.public void addSource(java.lang.String source) throws java.io.FileNotFoundException
source
- Full path and file name of source document.java.io.FileNotFoundException
- If the file doesn't existpublic void addSource(java.io.File source) throws java.io.FileNotFoundException
source
- File representing source documentjava.io.FileNotFoundException
- If the file doesn't existpublic void addSource(java.io.InputStream source)
source
- InputStream representing source documentpublic void addSources(java.util.List<java.io.InputStream> sourcesList)
sourcesList
- List of InputStream objects representing source
documents@Deprecated public void mergeDocuments() throws java.io.IOException
mergeDocuments(org.apache.pdfbox.io.MemoryUsageSetting)
java.io.IOException
- If there is an error saving the document.public void mergeDocuments(MemoryUsageSetting memUsageSetting) throws java.io.IOException
memUsageSetting
- defines how memory is used for buffering PDF streams;
in case of null
unrestricted main memory is usedjava.io.IOException
- If there is an error saving the document.private void optimizedMergeDocuments(MemoryUsageSetting memUsageSetting) throws java.io.IOException
java.io.IOException
private void legacyMergeDocuments(MemoryUsageSetting memUsageSetting) throws java.io.IOException
memUsageSetting
- defines how memory is used for buffering PDF streams;
in case of null
unrestricted main memory is usedjava.io.IOException
- If there is an error saving the document.public void appendDocument(PDDocument destination, PDDocument source) throws java.io.IOException
destination
- the document to receive the pagessource
- the document originating the new pagesjava.io.IOException
- If there is an error accessing data from either
document.private void mergeViewerPreferences(PDDocumentCatalog destCatalog, PDDocumentCatalog srcCatalog)
private void mergeLanguage(PDDocumentCatalog destCatalog, PDDocumentCatalog srcCatalog)
private void mergeMarkInfo(PDDocumentCatalog destCatalog, PDDocumentCatalog srcCatalog)
private void mergeKEntries(PDFCloneUtility cloner, PDStructureTreeRoot srcStructTree, PDStructureTreeRoot destStructTree) throws java.io.IOException
java.io.IOException
private void mergeIDTree(PDFCloneUtility cloner, PDStructureTreeRoot srcStructTree, PDStructureTreeRoot destStructTree) throws java.io.IOException
java.io.IOException
static java.util.Map<java.lang.String,PDStructureElement> getIDTreeAsMap(PDNameTreeNode<PDStructureElement> idTree) throws java.io.IOException
java.io.IOException
static java.util.Map<java.lang.Integer,COSObjectable> getNumberTreeAsMap(PDNumberTreeNode tree) throws java.io.IOException
java.io.IOException
private void mergeRoleMap(PDStructureTreeRoot srcStructTree, PDStructureTreeRoot destStructTree)
private void mergeOutputIntents(PDFCloneUtility cloner, PDDocumentCatalog srcCatalog, PDDocumentCatalog destCatalog) throws java.io.IOException
java.io.IOException
private void mergeAcroForm(PDFCloneUtility cloner, PDDocumentCatalog destCatalog, PDDocumentCatalog srcCatalog) throws java.io.IOException
cloner
- the object cloner for the destination documentdestAcroForm
- the destination formsrcAcroForm
- the source formjava.io.IOException
- If an error occurs while adding the field.private void acroFormJoinFieldsMode(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm srcAcroForm) throws java.io.IOException
java.io.IOException
private void mergeFields(PDFCloneUtility cloner, PDField destField, PDField srcField)
private void cleanupFieldCOSDictionary(COSDictionary fieldCos)
private void cleanupWidgetCOSDictionary(COSDictionary widgetCos, boolean removeDAEntry)
private void acroFormLegacyMode(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm srcAcroForm) throws java.io.IOException
java.io.IOException
public boolean isIgnoreAcroFormErrors()
public void setIgnoreAcroFormErrors(boolean ignoreAcroFormErrorsValue)
ignoreAcroFormErrorsValue
- true if acroform errors should be
ignoredprivate void updatePageReferences(PDFCloneUtility cloner, java.util.Map<java.lang.Integer,COSObjectable> numberTreeAsMap, java.util.Map<COSDictionary,COSDictionary> objMapping) throws java.io.IOException
java.io.IOException
private void updatePageReferences(PDFCloneUtility cloner, COSDictionary parentTreeEntry, java.util.Map<COSDictionary,COSDictionary> objMapping) throws java.io.IOException
parentTreeEntry
- objMapping
- mapping between old and new referencesjava.io.IOException
private void updatePageReferences(PDFCloneUtility cloner, COSArray parentTreeEntry, java.util.Map<COSDictionary,COSDictionary> objMapping) throws java.io.IOException
java.io.IOException
private void updateParentEntry(COSArray kArray, COSDictionary newParent)
kArray
- the kids arraynewParent
- the new parentprivate void updateStructParentEntries(PDPage page, int structParentOffset) throws java.io.IOException
page
- the new pagestructParentOffset
- the offset which should be appliedjava.io.IOException
private boolean isDynamicXfa(PDAcroForm acroForm)
acroForm
- the AcroFormprivate void mergeInto(COSDictionary src, COSDictionary dst, java.util.Set<COSName> exclude)
src
- The source dictionary to get the keys/values from.dst
- The destination dictionary to merge the keys/values into.exclude
- Names of keys that shall be skipped.