Package com.itextpdf.kernel.pdf
Class PdfObject
java.lang.Object
com.itextpdf.kernel.pdf.PdfObject
- Direct Known Subclasses:
-
PdfArray,PdfDictionary,PdfIndirectReference,PdfPrimitiveObject
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final bytestatic final bytestatic final byteprotected static final shortIndicates if the object has been flushed.protected static final shortIndicates that the object is highly sensitive and we do not want to release it even if release() is called.protected static final shortIndicates that the indirect reference of the object could be reused or have to be marked as free.static final byteprotected PdfIndirectReferenceIf object is flushed the indirect reference is kept here.static final byteprotected static final shortIndicates that object changed (is used in append mode).protected static final shortMarks objects that shall be written to the output document.protected static final shortIndicates that the object shall be indirect when it is written to the document.static final bytestatic final bytestatic final byteprotected static final shortIndicates that the indirect reference of the object represents ObjectStream from original document.protected static final shortIndicates 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 final shortIndicates that definition of the indirect reference of the object still not found (e.g.static final bytestatic final byteprotected static final shortIndicates that this object is not encrypted in the encrypted document. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancheckState(short state) Checks state of the flag of current object.protected PdfObjectclearState(short state) Clear state of the flag of current object.clone()Creates clone of the object which belongs to the same document as original object.clone(ICopyFilter filter) Creates clone of the object which belongs to the same document as original object.booleanChecks 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'.copyTo(PdfDocument document) Copies object to a specified document.copyTo(PdfDocument document, boolean allowDuplicating) Copies object to a specified document.copyTo(PdfDocument document, boolean allowDuplicating, ICopyFilter copyFilter) Copies object to a specified document.copyTo(PdfDocument document, ICopyFilter copyFilter) Copies object to a specified document.final voidflush()Flushes the object to the document.final voidflush(boolean canBeInObjStm) Flushes the object to the document.Gets the indirect reference associated with the object.abstract bytegetType()Gets object type.booleanisArray()Checks if thisPdfObjectis of the typePdfArray.booleanChecks if thisPdfObjectis of the typePdfBoolean.booleanChecks if thisPdfObjectis of the typePdfDictionary.booleanIndicates is the object has been flushed or not.booleanChecks if object is indirect.booleanChecks if thisPdfObjectis of the typePdfIndirectReference.booleanChecks if thisPdfObjectis of the typePdfLiteral.booleanIndicates 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.booleanChecks if it's forbidden to release thisPdfObjectinstance.booleanisStream()Checks if thisPdfObjectis of the typePdfStream.booleanisString()Checks if thisPdfObjectis of the typePdfString.makeIndirect(PdfDocument document) Marks object to be saved as indirect.makeIndirect(PdfDocument document, PdfIndirectReference reference) Marks object to be saved as indirect.protected abstract PdfObjectCreates new instance of object.voidrelease()protected PdfObjectsetIndirectReference(PdfIndirectReference indirectReference) 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 Details
-
ARRAY
public static final byte ARRAY- See Also:
-
BOOLEAN
public static final byte BOOLEAN- See Also:
-
DICTIONARY
public static final byte DICTIONARY- See Also:
-
LITERAL
public static final byte LITERAL- See Also:
-
INDIRECT_REFERENCE
public static final byte INDIRECT_REFERENCE- See Also:
-
NAME
public static final byte NAME- See Also:
-
NULL
public static final byte NULL- See Also:
-
NUMBER
public static final byte NUMBER- See Also:
-
STREAM
public static final byte STREAM- See Also:
-
STRING
public static final byte STRING- See Also:
-
FLUSHED
protected static final short FLUSHEDIndicates if the object has been flushed.- See Also:
-
FREE
protected static final short FREEIndicates that the indirect reference of the object could be reused or have to be marked as free.- See Also:
-
READING
protected static final short READINGIndicates that definition of the indirect reference of the object still not found (e.g. keys in XRefStm).- See Also:
-
MODIFIED
protected static final short MODIFIEDIndicates that object changed (is used in append mode).- See Also:
-
ORIGINAL_OBJECT_STREAM
protected static final short ORIGINAL_OBJECT_STREAMIndicates 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:
-
MUST_BE_FLUSHED
protected static final short MUST_BE_FLUSHEDMarks 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:
-
MUST_BE_INDIRECT
protected static final short MUST_BE_INDIRECTIndicates 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:
-
FORBID_RELEASE
protected static final short FORBID_RELEASEIndicates 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:
-
READ_ONLY
protected static final short READ_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).- See Also:
-
UNENCRYPTED
protected static final short UNENCRYPTEDIndicates that this object is not encrypted in the encrypted document. E.g. digital signature dictionary /Contents entry shall not be encrypted.- See Also:
-
indirectReference
If object is flushed the indirect reference is kept here.
-
-
Constructor Details
-
PdfObject
public PdfObject()
-
-
Method Details
-
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
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
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
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
Creates clone of the object which belongs to the same document as original object. New object shall not be used in other documents. -
clone
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
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
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
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
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
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
-
isLiteral
public boolean isLiteral()Checks if thisPdfObjectis of the typePdfLiteral.- Returns:
-
trueif this is a literal, otherwisefalse
-
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
Sets special states of current object.- Parameters:
-
state- special flag of current object - Returns:
-
this
PdfObject
-
clearState
Clear state of the flag of current object.- Parameters:
-
state- special flag state to clear - Returns:
-
this
PdfObject
-
copyContent
Copies object content from object 'from'.- Parameters:
-
from- object to copy content from. -
document- document to copy object to.
-
copyContent
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
-