Package com.itextpdf.kernel.pdf
Class PdfObject
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObject
-
- Direct Known Subclasses:
PdfArray,PdfDictionary,PdfIndirectReference,PdfPrimitiveObject
public abstract class PdfObject extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static byteARRAYstatic byteBOOLEANstatic byteDICTIONARYprotected static shortFLUSHEDIndicates if the object has been flushed.protected static shortFORBID_RELEASEIndicates that the object is highly sensitive and we do not want to release it even if release() is called.protected static shortFREEIndicates that the indirect reference of the object could be reused or have to be marked as free.static byteINDIRECT_REFERENCEprotected PdfIndirectReferenceindirectReferenceIf object is flushed the indirect reference is kept here.static byteLITERALprotected static shortMODIFIEDIndicates that object changed (is used in append mode).protected static shortMUST_BE_FLUSHEDMarks objects that shall be written to the output document.protected static shortMUST_BE_INDIRECTIndicates that the object shall be indirect when it is written to the document.static byteNAMEstatic byteNULLstatic byteNUMBERprotected static shortORIGINAL_OBJECT_STREAMIndicates that the indirect reference of the object represents ObjectStream from original document.protected static shortREAD_ONLYIndicates that we do not want this object to be ever written into the resultant document (because of multiple objects read from the same reference inconsistency).protected static shortREADINGIndicates that definition of the indirect reference of the object still not found (e.g.private shortstateIndicate same special states of PdfIndirectObject or PdfObject like @see Free, @see Reading, @see Modified.static byteSTREAMstatic byteSTRINGprotected static shortUNENCRYPTEDIndicates that this object is not encrypted in the encrypted document.
-
Constructor Summary
Constructors Constructor Description PdfObject()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancheckState(short state)Checks state of the flag of current object.protected PdfObjectclearState(short state)Clear state of the flag of current object.PdfObjectclone()Creates clone of the object which belongs to the same document as original object.PdfObjectclone(ICopyFilter filter)Creates clone of the object which belongs to the same document as original object.booleancontainsIndirectReference()Checks recursively whether the object contains indirect reference at any level.protected voidcopyContent(PdfObject from, PdfDocument document)Copies object content from object 'from'.protected voidcopyContent(PdfObject from, PdfDocument document, ICopyFilter filter)Copies object content from object 'from'.PdfObjectcopyTo(PdfDocument document)Copies object to a specified document.PdfObjectcopyTo(PdfDocument document, boolean allowDuplicating)Copies object to a specified document.PdfObjectcopyTo(PdfDocument document, boolean allowDuplicating, ICopyFilter copyFilter)Copies object to a specified document.PdfObjectcopyTo(PdfDocument document, ICopyFilter copyFilter)Copies object to a specified document.(package private) static booleanequalContent(PdfObject obj1, PdfObject obj2)voidflush()Flushes the object to the document.voidflush(boolean canBeInObjStm)Flushes the object to the document.PdfIndirectReferencegetIndirectReference()Gets the indirect reference associated with the object.abstract bytegetType()Gets object type.booleanisArray()Checks if thisPdfObjectis of the typePdfArray.booleanisBoolean()Checks if thisPdfObjectis of the typePdfBoolean.booleanisDictionary()Checks if thisPdfObjectis of the typePdfDictionary.booleanisFlushed()Indicates is the object has been flushed or not.booleanisIndirect()Checks if object is indirect.booleanisIndirectReference()Checks if thisPdfObjectis of the typePdfIndirectReference.booleanisLiteral()Checks if thisPdfObjectis of the typePdfLiteral.booleanisModified()Indicates is the object has been set as modified or not.booleanisName()Checks if thisPdfObjectis of the typePdfName.booleanisNull()Checks if thisPdfObjectis of the typePdfNull.booleanisNumber()Checks if thisPdfObjectis of the typePdfNumber.booleanisReleaseForbidden()Checks if it's forbidden to release thisPdfObjectinstance.booleanisStream()Checks if thisPdfObjectis of the typePdfStream.booleanisString()Checks if thisPdfObjectis of the typePdfString.PdfObjectmakeIndirect(PdfDocument document)Marks object to be saved as indirect.PdfObjectmakeIndirect(PdfDocument document, PdfIndirectReference reference)Marks object to be saved as indirect.protected abstract PdfObjectnewInstance()Creates new instance of object.(package private) PdfObjectprocessCopying(PdfDocument documentTo, boolean allowDuplicating)Processes two cases of object copying: copying to the other document cloning inside of the current document(package private) PdfObjectprocessCopying(PdfDocument documentTo, boolean allowDuplicating, ICopyFilter filter)Processes two cases of object copying: copying to the other document cloning inside of the current documentvoidrelease()protected PdfObjectsetIndirectReference(PdfIndirectReference indirectReference)PdfObjectsetModified()Sets the 'modified' flag to the indirect object, the flag denotes that the object was modified since the document opening.protected PdfObjectsetState(short state)Sets special states of current object.
-
-
-
Field Detail
-
ARRAY
public static final byte ARRAY
- See Also:
- Constant Field Values
-
BOOLEAN
public static final byte BOOLEAN
- See Also:
- Constant Field Values
-
DICTIONARY
public static final byte DICTIONARY
- See Also:
- Constant Field Values
-
LITERAL
public static final byte LITERAL
- See Also:
- Constant Field Values
-
INDIRECT_REFERENCE
public static final byte INDIRECT_REFERENCE
- See Also:
- Constant Field Values
-
NAME
public static final byte NAME
- See Also:
- Constant Field Values
-
NULL
public static final byte NULL
- See Also:
- Constant Field Values
-
NUMBER
public static final byte NUMBER
- See Also:
- Constant Field Values
-
STREAM
public static final byte STREAM
- See Also:
- Constant Field Values
-
STRING
public static final byte STRING
- See Also:
- Constant Field Values
-
FLUSHED
protected static final short FLUSHED
Indicates if the object has been flushed.- See Also:
- Constant Field Values
-
FREE
protected static final short FREE
Indicates that the indirect reference of the object could be reused or have to be marked as free.- See Also:
- Constant Field Values
-
READING
protected static final short READING
Indicates that definition of the indirect reference of the object still not found (e.g. keys in XRefStm).- See Also:
- Constant Field Values
-
MODIFIED
protected static final short MODIFIED
Indicates that object changed (is used in append mode).- See Also:
- Constant Field Values
-
ORIGINAL_OBJECT_STREAM
protected static final short ORIGINAL_OBJECT_STREAM
Indicates that the indirect reference of the object represents ObjectStream from original document. When PdfReader read ObjectStream reference marked as OriginalObjectStream to avoid further reusing.- See Also:
- Constant Field Values
-
MUST_BE_FLUSHED
protected static final short MUST_BE_FLUSHED
Marks objects that shall be written to the output document. Shouldn't be used on purpose since this flag is handled internally: option is needed to build the correct PDF objects tree when closing the document. As a result it avoids writing unused (removed) objects.- See Also:
- Constant Field Values
-
MUST_BE_INDIRECT
protected static final short MUST_BE_INDIRECT
Indicates that the object shall be indirect when it is written to the document. It is used to postpone the creation of indirect reference for the objects that shall be indirect, so it is possible to create such objects without PdfDocument instance.- See Also:
- Constant Field Values
-
FORBID_RELEASE
protected static final short FORBID_RELEASE
Indicates that the object is highly sensitive and we do not want to release it even if release() is called. This flag can be set in stamping mode in object wrapper constructors and is automatically set when setModified flag is set (we do not want to release changed objects). The flag is set automatically for some wrappers that need document even in reader mode (FormFields etc).- See Also:
- Constant Field Values
-
READ_ONLY
protected static final short READ_ONLY
Indicates that we do not want this object to be ever written into the resultant document (because of multiple objects read from the same reference inconsistency).- See Also:
- Constant Field Values
-
UNENCRYPTED
protected static final short UNENCRYPTED
Indicates that this object is not encrypted in the encrypted document. E.g. digital signature dictionary /Contents entry shall not be encrypted.- See Also:
- Constant Field Values
-
indirectReference
protected PdfIndirectReference indirectReference
If object is flushed the indirect reference is kept here.
-
state
private short state
Indicate same special states of PdfIndirectObject or PdfObject like @see Free, @see Reading, @see Modified.
-
-
Method Detail
-
getType
public abstract byte getType()
Gets object type.- Returns:
- object type.
-
flush
public final void flush()
Flushes the object to the document.
-
flush
public final void flush(boolean canBeInObjStm)
Flushes the object to the document.- Parameters:
canBeInObjStm- indicates whether object can be placed into object stream.
-
getIndirectReference
public PdfIndirectReference getIndirectReference()
Gets the indirect reference associated with the object. The indirect reference is used when flushing object to the document.- Returns:
- indirect reference.
-
containsIndirectReference
public boolean containsIndirectReference()
Checks recursively whether the object contains indirect reference at any level.- Returns:
trueif indirect reference was found,falseotherwise
-
isIndirect
public boolean isIndirect()
Checks if object is indirect.
Note: Return valuetruedoesn't necessarily mean that indirect reference of this object is not null at the moment. Object could be marked as indirect and be transformed to indirect on flushing.
E.g. all PdfStreams are transformed to indirect objects when they are written, but they don't always have indirect references at any given moment.- Returns:
- returns
trueif object is indirect or is to be indirect in the resultant document.
-
makeIndirect
public PdfObject makeIndirect(PdfDocument document, PdfIndirectReference reference)
Marks object to be saved as indirect.- Parameters:
document- a document the indirect reference will belong to.reference- indirect reference which will be associated with this document- Returns:
- object itself.
-
makeIndirect
public PdfObject makeIndirect(PdfDocument document)
Marks object to be saved as indirect.- Parameters:
document- a document the indirect reference will belong to.- Returns:
- object itself.
-
isFlushed
public boolean isFlushed()
Indicates is the object has been flushed or not.- Returns:
- true if object has been flushed, otherwise false.
-
isModified
public boolean isModified()
Indicates is the object has been set as modified or not. Useful for incremental updates (e.g. appendMode).- Returns:
- true is object has been set as modified, otherwise false.
-
clone
public PdfObject clone()
Creates clone of the object which belongs to the same document as original object. New object shall not be used in other documents.- Overrides:
clonein classjava.lang.Object- Returns:
- cloned object.
-
clone
public PdfObject clone(ICopyFilter filter)
Creates clone of the object which belongs to the same document as original object. New object shall not be used in other documents.- Parameters:
filter- Filter what will be copied or not- Returns:
- cloned object.
-
copyTo
public PdfObject copyTo(PdfDocument document)
Copies object to a specified document.
NOTE: Works only for objects that are read from document opened in reading mode, otherwise an exception is thrown.- Parameters:
document- document to copy object to.- Returns:
- copied object.
-
copyTo
public PdfObject copyTo(PdfDocument document, boolean allowDuplicating)
Copies object to a specified document.
NOTE: Works only for objects that are read from document opened in reading mode, otherwise an exception is thrown.- Parameters:
document- document to copy object to.allowDuplicating- indicates if to allow copy objects which already have been copied. If object is associated with any indirect reference and allowDuplicating is false then already existing reference will be returned instead of copying object. If allowDuplicating is true then object will be copied and new indirect reference will be assigned.- Returns:
- copied object.
-
copyTo
public PdfObject copyTo(PdfDocument document, ICopyFilter copyFilter)
Copies object to a specified document.
NOTE: Works only for objects that are read from document opened in reading mode, otherwise an exception is thrown.- Parameters:
document- document to copy object to.copyFilter-ICopyFiltera filter to apply while copying arrays and dictionaries UseNullCopyFilterfor no filtering- Returns:
- copied object.
-
copyTo
public PdfObject copyTo(PdfDocument document, boolean allowDuplicating, ICopyFilter copyFilter)
Copies object to a specified document.
NOTE: Works only for objects that are read from document opened in reading mode, otherwise an exception is thrown.- Parameters:
document- document to copy object to.allowDuplicating- indicates if to allow copy objects which already have been copied. If object is associated with any indirect reference and allowDuplicating is false then already existing reference will be returned instead of copying object. If allowDuplicating is true then object will be copied and new indirect reference will be assigned.copyFilter-ICopyFiltera filter to apply while copying arrays and dictionaries UseNullCopyFilterfor no filtering- Returns:
- copied object.
-
setModified
public PdfObject setModified()
Sets the 'modified' flag to the indirect object, the flag denotes that the object was modified since the document opening. It is recommended to set this flag after changing any PDF object.For example flag is used in the append mode (see
StampingProperties.useAppendMode()). In append mode the whole document is preserved as is, and only changes to the document are appended to the end of the document file. Because of this, only modified objects need to be flushed and are allowed to be flushed (i.e. to be written).- Returns:
- this
PdfObjectinstance.
-
isReleaseForbidden
public boolean isReleaseForbidden()
Checks if it's forbidden to release thisPdfObjectinstance. Some objects are vital for the living period ofPdfDocumentor may be prevented from releasing by high-level entities dealing with the objects. Also it's not possible to release the objects that have been modified.- Returns:
- true if releasing this object is forbidden, otherwise false
-
release
public void release()
-
isNull
public boolean isNull()
Checks if thisPdfObjectis of the typePdfNull.- Returns:
trueorfalse
-
isBoolean
public boolean isBoolean()
Checks if thisPdfObjectis of the typePdfBoolean.- Returns:
trueorfalse
-
isNumber
public boolean isNumber()
Checks if thisPdfObjectis of the typePdfNumber.- Returns:
trueorfalse
-
isString
public boolean isString()
Checks if thisPdfObjectis of the typePdfString.- Returns:
trueorfalse
-
isName
public boolean isName()
Checks if thisPdfObjectis of the typePdfName.- Returns:
trueorfalse
-
isArray
public boolean isArray()
Checks if thisPdfObjectis of the typePdfArray.- Returns:
trueorfalse
-
isDictionary
public boolean isDictionary()
Checks if thisPdfObjectis of the typePdfDictionary.- Returns:
trueorfalse
-
isStream
public boolean isStream()
Checks if thisPdfObjectis of the typePdfStream.- Returns:
trueorfalse
-
isIndirectReference
public boolean isIndirectReference()
Checks if thisPdfObjectis of the typePdfIndirectReference.- Returns:
trueif this is an indirect reference, otherwisefalse
-
setIndirectReference
protected PdfObject setIndirectReference(PdfIndirectReference indirectReference)
-
isLiteral
public boolean isLiteral()
Checks if thisPdfObjectis of the typePdfLiteral.- Returns:
trueif this is a literal, otherwisefalse
-
newInstance
protected abstract PdfObject newInstance()
Creates new instance of object.- Returns:
- new instance of object.
-
checkState
protected boolean checkState(short state)
Checks state of the flag of current object.- Parameters:
state- special flag to check- Returns:
- true if the state was set.
-
setState
protected PdfObject setState(short state)
Sets special states of current object.- Parameters:
state- special flag of current object- Returns:
- this
PdfObject
-
clearState
protected PdfObject clearState(short state)
Clear state of the flag of current object.- Parameters:
state- special flag state to clear- Returns:
- this
PdfObject
-
copyContent
protected void copyContent(PdfObject from, PdfDocument document)
Copies object content from object 'from'.- Parameters:
from- object to copy content from.document- document to copy object to.
-
copyContent
protected void copyContent(PdfObject from, PdfDocument document, ICopyFilter filter)
Copies object content from object 'from'.- Parameters:
from- object to copy content from.document- document to copy object to.filter-ICopyFiltera filter that will apply on dictionaries and array UseNullCopyFilterfor no filtering
-
processCopying
PdfObject processCopying(PdfDocument documentTo, boolean allowDuplicating)
Processes two cases of object copying:- copying to the other document
- cloning inside of the current document
This two cases are distinguished by the state of
documentparameter: the second case is processed ifdocumentisnull.- Parameters:
documentTo- if not null: document to copy object to; otherwise indicates that object is to be cloned.allowDuplicating- indicates if to allow copy objects which already have been copied. If object is associated with any indirect reference and allowDuplicating is false then already existing reference will be returned instead of copying object. If allowDuplicating is true then object will be copied and new indirect reference will be assigned.- Returns:
- copied object.
-
processCopying
PdfObject processCopying(PdfDocument documentTo, boolean allowDuplicating, ICopyFilter filter)
Processes two cases of object copying:- copying to the other document
- cloning inside of the current document
This two cases are distinguished by the state of
documentparameter: the second case is processed ifdocumentisnull.- Parameters:
documentTo- if not null: document to copy object to; otherwise indicates that object is to be cloned.allowDuplicating- indicates if to allow copy objects which already have been copied. If object is associated with any indirect reference and allowDuplicating is false then already existing reference will be returned instead of copying object. If allowDuplicating is true then object will be copied and new indirect reference will be assigned.filter- filters what will be copies or not- Returns:
- copied object.
-
-