Class PdfArray

java.lang.Object
org.openpdf.text.pdf.PdfObject
org.openpdf.text.pdf.PdfArray
Direct Known Subclasses:
PdfRectangle

public class PdfArray extends PdfObject
PdfArray is the PDF Array object.

An array is a sequence of PDF objects. An array may contain a mixture of object types. An array is written as a left square bracket ([), followed by a sequence of objects, followed by a right square bracket (]).
This object is described in the 'Portable Document Format Reference Manual version 1.7' section 3.2.5 (page 58).

See Also:
  • Field Details

    • arrayList

      protected List<PdfObject> arrayList
      this is the actual array of PdfObjects
  • Constructor Details

    • PdfArray

      public PdfArray()
      Constructs an empty PdfArray-object.
    • PdfArray

      public PdfArray(PdfObject object)
      Constructs an PdfArray-object, containing 1 PdfObject.
      Parameters:
      object - a PdfObject that has to be added to the array
    • PdfArray

      public PdfArray(int[] values)
      Constructs a PdfArray-object, containing all int values in a specified array.

      The int values are internally converted to PdfNumber objects.

      Parameters:
      values - an array of int values to be added
    • PdfArray

      public PdfArray(List<? extends PdfObject> pdfObjectList)
      Constructs a PdfArray, containing all elements of a specified List.
      Parameters:
      pdfObjectList - an List with PdfObjects to be added to the array
      Since:
      2.1.3
  • Method Details

    • toPdf

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

      public String toString()
      Returns a string representation of this PdfArray.

      The string representation consists of a list of all PdfObjects contained in this PdfArray, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space).

      Overrides:
      toString in class PdfObject
      Returns:
      the string representation of this PdfArray
    • size

      public int size()
      Returns the number of entries in the array.
      Returns:
      the size of the List
    • isEmpty

      public boolean isEmpty()
      Returns true if the array is empty.
      Returns:
      true if the array is empty
      Since:
      2.1.5
    • add

      public boolean add(PdfObject object)
      Adds a PdfObject to the end of the PdfArray.

      The PdfObject will be the last element.

      Parameters:
      object - PdfObject to add
      Returns:
      always true
    • add

      public boolean add(int[] values)
      Adds an array of int values to end of the PdfArray.

      The values will be the last elements. The int values are internally converted to PdfNumber objects.

      Parameters:
      values - An array of int values to add
      Returns:
      always true
    • contains

      public boolean contains(PdfObject object)
      Checks if the PdfArray already contains a certain PdfObject.
      Parameters:
      object - The PdfObject to check
      Returns:
      true
    • getPdfObject

      public PdfObject getPdfObject(int idx)
      Returns the PdfObject with the specified index.

      A possible indirect references is not resolved, so the returned PdfObject may be either a direct object or an indirect reference, depending on how the object is stored in the PdfArray.

      Parameters:
      idx - The index of the PdfObject to be returned
      Returns:
      A PdfObject
    • getDirectObject

      public PdfObject getDirectObject(int idx)
      Returns the PdfObject with the specified index, resolving a possible indirect reference to a direct object.

      Thus this method will never return a PdfIndirectReference object.

      Parameters:
      idx - The index of the PdfObject to be returned
      Returns:
      A direct PdfObject or null
    • getAsName

      public PdfName getAsName(int idx)
      Returns a PdfObject as a PdfName, resolving indirect references.

      The object corresponding to the specified index is retrieved and resolved to a direct object. If it is a PdfName, it is cast down and returned as such. Otherwise null is returned.

      Parameters:
      idx - The index of the PdfObject to be returned
      Returns:
      the corresponding PdfName object, or null