Class PdfObject

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static byte ARRAY  
      static byte BOOLEAN  
      static byte DICTIONARY  
      protected static short FLUSHED
      Indicates if the object has been flushed.
      protected static short FORBID_RELEASE
      Indicates that the object is highly sensitive and we do not want to release it even if release() is called.
      protected static short FREE
      Indicates that the indirect reference of the object could be reused or have to be marked as free.
      static byte INDIRECT_REFERENCE  
      protected PdfIndirectReference indirectReference
      If object is flushed the indirect reference is kept here.
      static byte LITERAL  
      protected static short MODIFIED
      Indicates that object changed (is used in append mode).
      protected static short MUST_BE_FLUSHED
      For internal usage only.
      protected static short MUST_BE_INDIRECT
      Indicates that the object shall be indirect when it is written to the document.
      static byte NAME  
      static byte NULL  
      static byte NUMBER  
      protected static short ORIGINAL_OBJECT_STREAM
      Indicates that the indirect reference of the object represents ObjectStream from original document.
      protected static 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).
      protected static short READING
      Indicates that definition of the indirect reference of the object still not found (e.g.
      private short state
      Indicate same special states of PdfIndirectObject or PdfObject like @see Free, @see Reading, @see Modified.
      static byte STREAM  
      static byte STRING  
      protected static short UNENCRYPTED
      Indicates that this object is not encrypted in the encrypted document.
    • Constructor Summary

      Constructors 
      Constructor Description
      PdfObject()  
    • Field Detail

      • 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
        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:
        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.
    • Constructor Detail

      • PdfObject

        public PdfObject()
    • 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.
      • 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 java.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 - 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
      • 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
      • processCopying

        PdfObject processCopying​(PdfDocument documentTo,
                                 boolean allowDuplicating)
        Processes two cases of object copying:
        1. copying to the other document
        2. cloning inside of the current document

        This two cases are distinguished by the state of document parameter: the second case is processed if document is null.

        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:
        1. copying to the other document
        2. cloning inside of the current document

        This two cases are distinguished by the state of document parameter: the second case is processed if document is null.

        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.