Package com.itextpdf.kernel.pdf
Class PdfObject
java.lang.Object
com.itextpdf.kernel.pdf.PdfObject
- Direct Known Subclasses:
-
PdfArray
,PdfDictionary
,PdfIndirectReference
,PdfPrimitiveObject
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
static final byte
static final byte
protected static final short
Indicates if the object has been flushed.protected static final short
Indicates that the object is highly sensitive and we do not want to release it even if release() is called.protected static final short
Indicates that the indirect reference of the object could be reused or have to be marked as free.static final byte
protected PdfIndirectReference
If object is flushed the indirect reference is kept here.static final byte
protected static final short
Indicates that object changed (is used in append mode).protected static final short
For internal usage only.protected static final short
Indicates that the object shall be indirect when it is written to the document.static final byte
static final byte
static final byte
protected static final short
Indicates that the indirect reference of the object represents ObjectStream from original document.protected static final short
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).protected static final short
Indicates that definition of the indirect reference of the object still not found (e.g.static final byte
static final byte
protected static final short
Indicates that this object is not encrypted in the encrypted document. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
checkState
(short state) Checks state of the flag of current object.protected PdfObject
clearState
(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.protected void
copyContent
(PdfObject from, PdfDocument document) Copies object content from object 'from'.protected void
copyContent
(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 void
flush()
Flushes the object to the document.final void
flush
(boolean canBeInObjStm) Flushes the object to the document.Gets the indirect reference associated with the object.abstract byte
getType()
Gets object type.boolean
isArray()
Checks if thisPdfObject
is of the typePdfArray
.boolean
Checks if thisPdfObject
is of the typePdfBoolean
.boolean
Checks if thisPdfObject
is of the typePdfDictionary
.boolean
Indicates is the object has been flushed or not.boolean
Checks if object is indirect.boolean
Checks if thisPdfObject
is of the typePdfIndirectReference
.boolean
Checks if thisPdfObject
is of the typePdfLiteral
.boolean
Indicates is the object has been set as modified or not.boolean
isName()
Checks if thisPdfObject
is of the typePdfName
.boolean
isNull()
Checks if thisPdfObject
is of the typePdfNull
.boolean
isNumber()
Checks if thisPdfObject
is of the typePdfNumber
.boolean
Checks if it's forbidden to release thisPdfObject
instance.boolean
isStream()
Checks if thisPdfObject
is of the typePdfStream
.boolean
isString()
Checks if thisPdfObject
is 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 PdfObject
Creates new instance of object.void
release()
protected PdfObject
setIndirectReference
(PdfIndirectReference indirectReference) Sets the 'modified' flag to the indirect object, the flag denotes that the object was modified since the document opening.protected PdfObject
setState
(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_FLUSHEDFor internal usage only. Marks objects that shall be written to the output document. 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.
-
isIndirect
public boolean isIndirect()Checks if object is indirect.
Note: Return valuetrue
doesn'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
true
if 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
-ICopyFilter
a filter to apply while copying arrays and dictionaries UseNullCopyFilter
for 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
-ICopyFilter
a filter to apply while copying arrays and dictionaries UseNullCopyFilter
for 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
PdfObject
instance.
-
isReleaseForbidden
public boolean isReleaseForbidden()Checks if it's forbidden to release thisPdfObject
instance. Some objects are vital for the living period ofPdfDocument
or 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 thisPdfObject
is of the typePdfNull
.- Returns:
-
true
orfalse
-
isBoolean
public boolean isBoolean()Checks if thisPdfObject
is of the typePdfBoolean
.- Returns:
-
true
orfalse
-
isNumber
public boolean isNumber()Checks if thisPdfObject
is of the typePdfNumber
.- Returns:
-
true
orfalse
-
isString
public boolean isString()Checks if thisPdfObject
is of the typePdfString
.- Returns:
-
true
orfalse
-
isName
public boolean isName()Checks if thisPdfObject
is of the typePdfName
.- Returns:
-
true
orfalse
-
isArray
public boolean isArray()Checks if thisPdfObject
is of the typePdfArray
.- Returns:
-
true
orfalse
-
isDictionary
public boolean isDictionary()Checks if thisPdfObject
is of the typePdfDictionary
.- Returns:
-
true
orfalse
-
isStream
public boolean isStream()Checks if thisPdfObject
is of the typePdfStream
.- Returns:
-
true
orfalse
-
isIndirectReference
public boolean isIndirectReference()Checks if thisPdfObject
is of the typePdfIndirectReference
.- Returns:
-
true
if this is an indirect reference, otherwisefalse
-
setIndirectReference
-
isLiteral
public boolean isLiteral()Checks if thisPdfObject
is of the typePdfLiteral
.- Returns:
-
true
if 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
-ICopyFilter
a filter that will apply on dictionaries and array UseNullCopyFilter
for no filtering
-