Class PdfObject

java.lang.Object
com.itextpdf.kernel.pdf.PdfObject
Direct Known Subclasses:
PdfArray, PdfDictionary, PdfIndirectReference, PdfPrimitiveObject

public abstract class PdfObject extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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
     
    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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    Gets object type.
    boolean
    Checks if this PdfObject is of the type PdfArray.
    boolean
    Checks if this PdfObject is of the type PdfBoolean.
    boolean
    Checks if this PdfObject is of the type PdfDictionary.
    boolean
    Indicates is the object has been flushed or not.
    boolean
    Checks if object is indirect.
    boolean
    Checks if this PdfObject is of the type PdfIndirectReference.
    boolean
    Checks if this PdfObject is of the type PdfLiteral.
    boolean
    Indicates is the object has been set as modified or not.
    boolean
    isName()
    Checks if this PdfObject is of the type PdfName.
    boolean
    isNull()
    Checks if this PdfObject is of the type PdfNull.
    boolean
    Checks if this PdfObject is of the type PdfNumber.
    boolean
    Checks if it's forbidden to release this PdfObject instance.
    boolean
    Checks if this PdfObject is of the type PdfStream.
    boolean
    Checks if this PdfObject is of the type PdfString.
    Marks object to be saved as indirect.
    Marks object to be saved as indirect.
    protected abstract PdfObject
    Creates new instance of object.
    void
     
    protected PdfObject
     
    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.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 FLUSHED
      Indicates if the object has been flushed.
      See Also:
    • 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:
    • 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:
    • MODIFIED

      protected static final short MODIFIED
      Indicates that object changed (is used in append mode).
      See Also:
    • 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:
    • MUST_BE_FLUSHED

      protected static final short MUST_BE_FLUSHED
      For 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_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:
    • 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:
    • 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:
    • 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:
    • indirectReference

      protected PdfIndirectReference 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

      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.
    • isIndirect

      public boolean isIndirect()
      Checks if object is indirect.
      Note: Return value true 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

      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:
      clone in class 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 - ICopyFilter a filter to apply while copying arrays and dictionaries Use NullCopyFilter for 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 - ICopyFilter a filter to apply while copying arrays and dictionaries Use NullCopyFilter for 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 PdfObject instance.
    • isReleaseForbidden

      public boolean isReleaseForbidden()
      Checks if it's forbidden to release this PdfObject instance. Some objects are vital for the living period of PdfDocument 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 this PdfObject is of the type PdfNull.
      Returns:
      true or false
    • isBoolean

      public boolean isBoolean()
      Checks if this PdfObject is of the type PdfBoolean.
      Returns:
      true or false
    • isNumber

      public boolean isNumber()
      Checks if this PdfObject is of the type PdfNumber.
      Returns:
      true or false
    • isString

      public boolean isString()
      Checks if this PdfObject is of the type PdfString.
      Returns:
      true or false
    • isName

      public boolean isName()
      Checks if this PdfObject is of the type PdfName.
      Returns:
      true or false
    • isArray

      public boolean isArray()
      Checks if this PdfObject is of the type PdfArray.
      Returns:
      true or false
    • isDictionary

      public boolean isDictionary()
      Checks if this PdfObject is of the type PdfDictionary.
      Returns:
      true or false
    • isStream

      public boolean isStream()
      Checks if this PdfObject is of the type PdfStream.
      Returns:
      true or false
    • isIndirectReference

      public boolean isIndirectReference()
      Checks if this PdfObject is of the type PdfIndirectReference.
      Returns:
      true if this is an indirect reference, otherwise false
    • setIndirectReference

      protected PdfObject setIndirectReference (PdfIndirectReference indirectReference)
    • isLiteral

      public boolean isLiteral()
      Checks if this PdfObject is of the type PdfLiteral.
      Returns:
      true if this is a literal, otherwise false
    • 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 - ICopyFilter a filter that will apply on dictionaries and array Use NullCopyFilter for no filtering