Class PdfObject

java.lang.Object
com.lowagie.text.pdf.PdfObject
Direct Known Subclasses:
PdfArray, PdfBoolean, PdfDictionary, PdfIndirectReference, PdfLiteral, PdfName, PdfNull, PdfNumber, PdfString

public abstract class PdfObject extends Object
PdfObject is the abstract superclass of all PDF objects.

PDF supports seven basic types of objects: Booleans, numbers, strings, names, arrays, dictionaries and streams. In addition, PDF provides a null object. Objects may be labeled so that they can be referred to by other objects.
All these basic PDF objects are described in the 'Portable Document Format Reference Manual version 1.3' Chapter 4 (pages 37-54).

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A possible type of PdfObject
    static final int
    A possible type of PdfObject
    protected byte[]
    The content of this PdfObject
    static final int
    A possible type of PdfObject
    static final int
    A possible type of PdfObject
    Holds the indirect reference.
    static final int
    A possible type of PdfObject
    static final String
    An empty string used for the PdfNull-object and for an empty PdfString-object.
    static final int
    A possible type of PdfObject
    static final int
    A possible type of PdfObject
    static final int
    A possible type of PdfObject
    static final int
    A possible type of PdfObject
    static final String
    This is the default encoding to be used for converting Strings into bytes and vice versa.
    static final String
    This is the encoding to be used to output text in Unicode.
    protected int
    The type of this PdfObject
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    PdfObject(int type)
    Constructs a PdfObject of a certain type without any content.
    protected
    PdfObject(int type, byte[] bytes)
    Constructs a PdfObject of a certain type with a certain content.
    protected
    PdfObject(int type, String content)
    Constructs a PdfObject of a certain type with a certain content.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether this object can be contained in an object stream.
    byte[]
    Gets the presentation of this object in a byte array
    Get the indirect reference
    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
    Checks if this PdfObject is of the type PdfIndirectObject.
    boolean
    Checks if this PdfObject is of the type PdfName.
    boolean
    Checks if this PdfObject is of the type PdfNull.
    boolean
    Checks if this PdfObject is of the type PdfNumber.
    boolean
    Checks if this PdfObject is of the type PdfStream.
    boolean
    Checks if this PdfObject is of the type PdfString.
    int
    Returns the length of the actual content of the PdfObject.
    protected void
    setContent(String content)
    Changes the content of this PdfObject.
    void
    Set the indirect reference
    void
    Writes the PDF representation of this PdfObject as an array of bytes to the writer.
    Returns the String-representation of this PdfObject.
    int
    Returns the type of this PdfObject.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • BOOLEAN

      public static final int BOOLEAN
      A possible type of PdfObject
      See Also:
    • NUMBER

      public static final int NUMBER
      A possible type of PdfObject
      See Also:
    • STRING

      public static final int STRING
      A possible type of PdfObject
      See Also:
    • NAME

      public static final int NAME
      A possible type of PdfObject
      See Also:
    • ARRAY

      public static final int ARRAY
      A possible type of PdfObject
      See Also:
    • DICTIONARY

      public static final int DICTIONARY
      A possible type of PdfObject
      See Also:
    • STREAM

      public static final int STREAM
      A possible type of PdfObject
      See Also:
    • NULL

      public static final int NULL
      A possible type of PdfObject
      See Also:
    • INDIRECT

      public static final int INDIRECT
      A possible type of PdfObject
      See Also:
    • NOTHING

      public static final String NOTHING
      An empty string used for the PdfNull-object and for an empty PdfString-object.
      See Also:
    • TEXT_PDFDOCENCODING

      public static final String TEXT_PDFDOCENCODING
      This is the default encoding to be used for converting Strings into bytes and vice versa. The default encoding is PdfDocEncoding.
      See Also:
    • TEXT_UNICODE

      public static final String TEXT_UNICODE
      This is the encoding to be used to output text in Unicode.
      See Also:
    • bytes

      protected byte[] bytes
      The content of this PdfObject
    • type

      protected int type
      The type of this PdfObject
    • indRef

      protected PRIndirectReference indRef
      Holds the indirect reference.
  • Constructor Details

    • PdfObject

      protected PdfObject(int type)
      Constructs a PdfObject of a certain type without any content.
      Parameters:
      type - type of the new PdfObject
    • PdfObject

      protected PdfObject(int type, String content)
      Constructs a PdfObject of a certain type with a certain content.
      Parameters:
      type - type of the new PdfObject
      content - content of the new PdfObject as a String.
    • PdfObject

      protected PdfObject(int type, byte[] bytes)
      Constructs a PdfObject of a certain type with a certain content.
      Parameters:
      type - type of the new PdfObject
      bytes - content of the new PdfObject as an array of byte.
  • Method Details

    • toPdf

      public void toPdf(PdfWriter writer, OutputStream os) throws IOException
      Writes the PDF representation of this PdfObject as an array of bytes to the writer.
      Parameters:
      writer - for backwards compatibility
      os - The OutputStream to write the bytes to.
      Throws:
      IOException - on error
    • toString

      public String toString()
      Returns the String-representation of this PdfObject.
      Overrides:
      toString in class Object
      Returns:
      a String
    • getBytes

      public byte[] getBytes()
      Gets the presentation of this object in a byte array
      Returns:
      a byte array
    • canBeInObjStm

      public boolean canBeInObjStm()
      Whether this object can be contained in an object stream.

      PdfObjects of type STREAM OR INDIRECT can not be contained in an object stream.

      Returns:
      true if this object can be in an object stream. Otherwise false
    • length

      public int length()
      Returns the length of the actual content of the PdfObject.

      In some cases, namely for PdfString and PdfStream, this method differs from the method pdfLength because pdfLength returns the length of the PDF representation of the object, not of the actual content as does the method length.

      Remark: the actual content of an object is in some cases identical to its representation. The following statement is always true: length() >= pdfLength().

      Returns:
      The length as int
    • setContent

      protected void setContent(String content)
      Changes the content of this PdfObject.
      Parameters:
      content - the new content of this PdfObject
    • type

      public int type()
      Returns the type of this PdfObject.

      May be either of: - NULL: A PdfNull - BOOLEAN: A PdfBoolean - NUMBER: A PdfNumber - STRING: A PdfString - NAME: A PdfName - ARRAY: A PdfArray - DICTIONARY: A PdfDictionary - STREAM: A PdfStream - INDIRECT: > PdfIndirectObject

      Returns:
      The type
    • 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
    • isIndirect

      public boolean isIndirect()
      Checks if this PdfObject is of the type PdfIndirectObject.
      Returns:
      true if this is an indirect object, otherwise false
    • getIndRef

      public PRIndirectReference getIndRef()
      Get the indirect reference
      Returns:
      A PdfIndirectReference
    • setIndRef

      public void setIndRef(PRIndirectReference indRef)
      Set the indirect reference
      Parameters:
      indRef - New value as a PdfIndirectReference