Class PdfArray

java.lang.Object
com.itextpdf.kernel.pdf.PdfObject
com.itextpdf.kernel.pdf.PdfArray
All Implemented Interfaces:
Iterable<PdfObject>
Direct Known Subclasses:
PdfTextArray

public class PdfArray extends PdfObject implements Iterable<PdfObject>
A representation of an array as described in the PDF specification. A PdfArray can contain any subclass of PdfObject.
  • Field Details

  • Constructor Details

    • PdfArray

      public PdfArray()
      Create a new, empty PdfArray.
    • PdfArray

      public PdfArray (PdfObject obj)
      Create a new PdfArray with the provided PdfObject as the first item in the array.
      Parameters:
      obj - first item in the array
    • PdfArray

      public PdfArray (PdfArray arr)
      Create a new PdfArray. The array is filled with the items of the provided PdfArray.
      Parameters:
      arr - PdfArray containing items that will added to this PdfArray
    • PdfArray

      public PdfArray (Rectangle rectangle)
      Create a new PdfArray. The array is filled with the four values of the Rectangle in the following order: left, bottom, right, top.
      Parameters:
      rectangle - Rectangle whose 4 values will be added to the PdfArray
    • PdfArray

      public PdfArray (ListPdfObject> objects)
      Create a new PdfArray. The PdfObjects in the list will be added to the PdfArray.
      Parameters:
      objects - List of PdfObjects to be added to this PdfArray
    • PdfArray

      public PdfArray (float[] numbers)
      Create a new PdfArray filled with the values in the float[] as PdfNumber.
      Parameters:
      numbers - values to be added to this PdfArray
    • PdfArray

      public PdfArray (double[] numbers)
      Create a new PdfArray filled with the values in the double[] as PdfNumber.
      Parameters:
      numbers - values to be added to this PdfArray
    • PdfArray

      public PdfArray (int[] numbers)
      Create a new PdfArray filled with the values in the int[] as PdfNumber.
      Parameters:
      numbers - values to be added to this PdfArray
    • PdfArray

      public PdfArray (boolean[] values)
      Create a new PdfArray filled with the values in the boolean[] as PdfBoolean.
      Parameters:
      values - values to be added to this PdfArray
    • PdfArray

      public PdfArray (List<String> strings, boolean asNames)
      Create a new PdfArray filled with a list of Strings. The boolean value decides if the Strings should be added as PdfName (true) or as PdfString (false).
      Parameters:
      strings - list of strings to be added to the list
      asNames - indicates whether the strings should be added as PdfName (true) or as PdfString (false)
    • PdfArray

      public PdfArray (IterablePdfObject> objects, int initialCapacity)
      Create a new PdfArray. The PdfObjects in the iterable object will be added to the PdfArray.
      Parameters:
      objects - List of PdfObjects to be added to this PdfArray
      initialCapacity - Initial capacity of this PdfArray
  • Method Details

    • size

      public int size()
    • isEmpty

      public boolean isEmpty()
    • contains

      public boolean contains (PdfObject o)
    • iterator

      public Iterator<PdfObject> iterator()
      Returns an iterator over an array of PdfObject elements.
      NOTE: since 7.0.1 it returns collection of direct objects. If you want to get PdfIndirectReference instances for the indirect objects value, you shall use get(int, boolean) method.
      Specified by:
      iterator in interface Iterable<PdfObject>
      Returns:
      an Iterator.
    • add

      public void add (PdfObject pdfObject)
    • add

      public void add (int index, PdfObject element)
      Adds the specified PdfObject at the specified index. All objects after this index will be shifted by 1.
      Parameters:
      index - position to insert the PdfObject
      element - PdfObject to be added
      See Also:
    • set

      public PdfObject set (int index, PdfObject element)
      Sets the PdfObject at the specified index in the PdfArray.
      Parameters:
      index - the position to set the PdfObject
      element - PdfObject to be added
      Returns:
      true if the operation changed the PdfArray
      See Also:
    • addAll

      public void addAll (Collection<PdfObject> c)
      Adds the Collection of PdfObjects.
      Parameters:
      c - the Collection of PdfObjects to be added
      See Also:
    • addAll

      public void addAll (PdfArray a)
      Adds content of the PdfArray.
      Parameters:
      a - the PdfArray to be added
      See Also:
    • get

      public PdfObject get (int index)
      Gets the (direct) PdfObject at the specified index.
      Parameters:
      index - index of the PdfObject in the PdfArray
      Returns:
      the PdfObject at the position in the PdfArray
    • remove

      public void remove (int index)
      Removes the PdfObject at the specified index.
      Parameters:
      index - position of the PdfObject to be removed
      See Also:
    • remove

      public void remove (PdfObject o)
      Removes the first occurrence of the specified PdfObject, if it is present.
      Parameters:
      o - a PdfObject to be removed
      See Also:
    • clear

      public void clear()
    • indexOf

      public int indexOf (PdfObject o)
      Gets the first index of the specified PdfObject.
      Parameters:
      o - PdfObject to find the index of
      Returns:
      index of the PdfObject
      See Also:
    • subList

      public List<PdfObject> subList (int fromIndex, int toIndex)
      Returns a sublist of this PdfArray, starting at fromIndex (inclusive) and ending at toIndex (exclusive).
      Parameters:
      fromIndex - the position of the first element in the sublist (inclusive)
      toIndex - the position of the last element in the sublist (exclusive)
      Returns:
      List of PdfObjects
      See Also:
    • getType

      public byte getType()
      Description copied from class: PdfObject
      Gets object type.
      Specified by:
      getType in class PdfObject
      Returns:
      object type.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • get

      public PdfObject get (int index, boolean asDirect)
      Parameters:
      asDirect - true is to extract direct object always.
      index - index of the element to return
      Returns:
      the element at the specified position in this list
    • getAsArray

      public PdfArray getAsArray (int index)
      Returns the element at the specified index as a PdfArray. If the element isn't a PdfArray, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfArray
    • getAsDictionary

      public PdfDictionary getAsDictionary (int index)
      Returns the element at the specified index as a PdfDictionary. If the element isn't a PdfDictionary, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfDictionary
    • getAsStream

      public PdfStream getAsStream (int index)
      Returns the element at the specified index as a PdfStream. If the element isn't a PdfStream, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfStream
    • getAsNumber

      public PdfNumber getAsNumber (int index)
      Returns the element at the specified index as a PdfNumber. If the element isn't a PdfNumber, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfNumber
    • getAsName

      public PdfName getAsName (int index)
      Returns the element at the specified index as a PdfName. If the element isn't a PdfName, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfName
    • getAsString

      public PdfString getAsString (int index)
      Returns the element at the specified index as a PdfString. If the element isn't a PdfString, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfString
    • getAsBoolean

      public PdfBoolean getAsBoolean (int index)
      Returns the element at the specified index as a PdfBoolean. If the element isn't a PdfBoolean, null is returned.
      Parameters:
      index - position of the element to be returned
      Returns:
      the element at the index as a PdfBoolean
    • toRectangle

      public Rectangle toRectangle()
      Returns the first four elements of this array as a PdfArray. The first four values need to be PdfNumbers, if not a PdfException will be thrown.
      Returns:
      Rectangle of the first four values
      Throws:
      PdfException - if one of the first values isn't a PdfNumber
    • toFloatArray

      public float[] toFloatArray()
      Returns this array as an array of floats. Will throw a PdfException when it encounters an issue.
      Returns:
      this array as an array of floats
      Throws:
      PdfException - if one of the values isn't a number
    • toDoubleArray

      public double[] toDoubleArray()
      Returns this array as an array of doubles. Will throw a PdfException when it encounters an issue.
      Returns:
      this array as an array of doubles
      Throws:
      PdfException - if one of the values isn't a number
    • toLongArray

      public long[] toLongArray()
      Returns this array as an array of longs. Will throw a PdfException when it encounters an issue.
      Returns:
      this array as an array of longs
      Throws:
      PdfException - if one of the values isn't a number
    • toIntArray

      public int[] toIntArray()
      Returns this array as an array of ints. Will throw a PdfException when it encounters an issue.
      Returns:
      this array as an array of ints
      Throws:
      PdfException - if one of the values isn't a number
    • toBooleanArray

      public boolean[] toBooleanArray()
      Returns this array as an array of booleans. Will throw a PdfException when it encounters an issue.
      Returns:
      this array as an array of booleans
      Throws:
      PdfException - if one of the values isn't a boolean
    • newInstance

      protected PdfObject newInstance()
      Description copied from class: PdfObject
      Creates new instance of object.
      Specified by:
      newInstance in class PdfObject
      Returns:
      new instance of object.
    • copyContent

      protected void copyContent (PdfObject from, PdfDocument document, ICopyFilter copyFilter)
      Description copied from class: PdfObject
      Copies object content from object 'from'.
      Overrides:
      copyContent in class PdfObject
      Parameters:
      from - object to copy content from.
      document - document to copy object to.
      copyFilter - ICopyFilter a filter that will apply on dictionaries and array Use NullCopyFilter for no filtering
    • releaseContent

      protected void releaseContent()
      Release content of PdfArray.