Top Description Fields Constructors Methods
org.apache.pdfbox.multipdf

public Class PDFCloneUtility

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.util.HashMap, .HashSet, .Map, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSObject, .COSStream, org.apache.pdfbox.io.IOUtils, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.common.COSObjectable

Utility class used to clone PDF objects. It keeps track of objects it has already cloned.

Field Summary

Modifier and TypeField and Description
private final Set<COSBase>
private final Map<COSBase, COSBase>
private final PDDocument
private static final Log

Constructor Summary

AccessConstructor and Description
protected
PDFCloneUtility(PDDocument
the destination PDF document that will receive the clones
dest
)

Creates a new instance for the given target document.

Method Summary

Modifier and TypeMethod and Description
private COSArray
private COSBase
private COSDictionary
private COSStream
public <TCOSBase extends COSBase> TCOSBase

Returns:

the cloned instance of the base object
cloneForNewDocument
(TCOSBase
the initial object as the root of the deep-clone operation
base
)

Deep-clones the given object for inclusion into a different PDF document identified by the destination parameter.

pack-priv void
cloneMerge(final COSObjectable
the base object to be cloned
base
,
COSObjectable
the merge target
target
)

Merges two objects of the same type by deep-cloning its members.

private void
cloneMergeCOSBase(final COSBase source, final COSBase target)

pack-priv PDDocument

Returns:

the destination PDF document
getDestination
()

Returns the destination PDF document this cloner instance is set up for.

private boolean
hasSelfReference(COSBase
COSArray or COSDictionary
parent
,
COSBase
an element
value
)

Check whether an element (of an array or a dictionary) points to its parent.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clonedValuesback to summary
private final Set<COSBase> clonedValues
clonedVersionback to summary
private final Map<COSBase, COSBase> clonedVersion
destinationback to summary
private final PDDocument destination
LOGback to summary
private static final Log LOG

Constructor Detail

PDFCloneUtilityback to summary
protected PDFCloneUtility(PDDocument dest)

Creates a new instance for the given target document.

Parameters
dest:PDDocument

the destination PDF document that will receive the clones

Method Detail

cloneCOSArrayback to summary
private COSArray cloneCOSArray(COSArray array) throws IOException
cloneCOSBaseForNewDocumentback to summary
private COSBase cloneCOSBaseForNewDocument(COSBase base) throws IOException
cloneCOSDictionaryback to summary
private COSDictionary cloneCOSDictionary(COSDictionary dictionary) throws IOException
cloneCOSStreamback to summary
private COSStream cloneCOSStream(COSStream stream) throws IOException
cloneForNewDocumentback to summary
public <TCOSBase extends COSBase> TCOSBase cloneForNewDocument(TCOSBase base) throws IOException

Deep-clones the given object for inclusion into a different PDF document identified by the destination parameter. Expert use only, don’t use it if you don’t know exactly what you are doing.

Parameters
base:TCOSBase

the initial object as the root of the deep-clone operation

Returns:TCOSBase

the cloned instance of the base object

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an I/O error occurs
cloneMergeback to summary
pack-priv void cloneMerge(final COSObjectable base, COSObjectable target) throws IOException

Merges two objects of the same type by deep-cloning its members.
Base and target must be instances of the same class.

Parameters
base:COSObjectable

the base object to be cloned

target:COSObjectable

the merge target

Exceptions
IOException:
if an I/O error occurs
cloneMergeCOSBaseback to summary
private void cloneMergeCOSBase(final COSBase source, final COSBase target) throws IOException
getDestinationback to summary
pack-priv PDDocument getDestination()

Returns the destination PDF document this cloner instance is set up for.

Returns:PDDocument

the destination PDF document

hasSelfReferenceback to summary
private boolean hasSelfReference(COSBase parent, COSBase value)

Check whether an element (of an array or a dictionary) points to its parent.

Parameters
parent:COSBase

COSArray or COSDictionary

value:COSBase

an element