- java.lang.Object
-
- com.itextpdf.text.pdf.PdfObject
-
- com.itextpdf.text.pdf.PdfArray
-
- Direct Known Subclasses:
PdfBorderArray,PdfDashPattern,PdfDestination,PdfRectangle
public class PdfArray extends PdfObject
PdfArrayis 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:
PdfObject
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayListarrayListthis is the actual array of PdfObjects
-
Constructor Summary
Constructors Constructor Description PdfArray()Constructs an emptyPdfArray-object.PdfArray(float[] values)Constructs aPdfArray-object, containing allfloatvalues in a specified array.PdfArray(int[] values)Constructs aPdfArray-object, containing allintvalues in a specified array.PdfArray(PdfArray array)Constructs anPdfArray-object, containing allPdfObjects in a specifiedPdfArray.PdfArray(PdfObject object)Constructs anPdfArray-object, containing 1PdfObject.PdfArray(java.util.ArrayList l)Constructs aPdfArray, containing all elements of a specifiedArrayList.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanadd(float[] values)Adds an array offloatvalues to end of thePdfArray.booleanadd(int[] values)Adds an array ofintvalues to end of thePdfArray.voidadd(int index, PdfObject element)Inserts the specified element at the specified position.booleanadd(PdfObject object)Adds aPdfObjectto the end of thePdfArray.voidaddFirst(PdfObject object)Inserts aPdfObjectat the beginning of thePdfArray.booleancontains(PdfObject object)Checks if thePdfArrayalready contains a certainPdfObject.java.util.ArrayListgetArrayList()Deprecated.PdfArraygetAsArray(int idx)Returns aPdfObjectas aPdfArray, resolving indirect references.PdfBooleangetAsBoolean(int idx)Returns aPdfObjectas aPdfBoolean, resolving indirect references.PdfDictionarygetAsDict(int idx)Returns aPdfObjectas aPdfDictionary, resolving indirect references.PdfIndirectReferencegetAsIndirectObject(int idx)Returns aPdfObjectas aPdfIndirectReference.PdfNamegetAsName(int idx)Returns aPdfObjectas aPdfName, resolving indirect references.PdfNumbergetAsNumber(int idx)Returns aPdfObjectas aPdfNumber, resolving indirect references.PdfStreamgetAsStream(int idx)Returns aPdfObjectas aPdfStream, resolving indirect references.PdfStringgetAsString(int idx)Returns aPdfObjectas aPdfString, resolving indirect references.PdfObjectgetDirectObject(int idx)Returns thePdfObjectwith the specified index, resolving a possible indirect reference to a direct object.PdfObjectgetPdfObject(int idx)Returns thePdfObjectwith the specified index.booleanisEmpty()Returnstrueif the array is empty.java.util.ListIteratorlistIterator()Returns the list iterator for the array.PdfObjectremove(int idx)Remove the element at the specified position from the array.PdfObjectset(int idx, PdfObject obj)Overwrites a specified location of the array, returning the previous valueintsize()Returns the number of entries in the array.voidtoPdf(PdfWriter writer, java.io.OutputStream os)Writes the PDF representation of thisPdfArrayas an array ofbyteto the specifiedOutputStream.java.lang.StringtoString()Returns a string representation of thisPdfArray.-
Methods inherited from class com.itextpdf.text.pdf.PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, type
-
-
-
-
Constructor Detail
-
PdfArray
public PdfArray()
Constructs an emptyPdfArray-object.
-
PdfArray
public PdfArray(PdfObject object)
Constructs anPdfArray-object, containing 1PdfObject.- Parameters:
object- aPdfObjectthat has to be added to the array
-
PdfArray
public PdfArray(float[] values)
Constructs aPdfArray-object, containing allfloatvalues in a specified array. Thefloatvalues are internally converted toPdfNumberobjects.- Parameters:
values- an array offloatvalues to be added
-
PdfArray
public PdfArray(int[] values)
Constructs aPdfArray-object, containing allintvalues in a specified array. Theintvalues are internally converted toPdfNumberobjects.- Parameters:
values- an array ofintvalues to be added
-
PdfArray
public PdfArray(java.util.ArrayList l)
Constructs aPdfArray, containing all elements of a specifiedArrayList.- Parameters:
l- anArrayListwithPdfObjects to be added to the array- Throws:
java.lang.ClassCastException- if theArrayListcontains something that isn't aPdfObject- Since:
- 2.1.3
-
PdfArray
public PdfArray(PdfArray array)
Constructs anPdfArray-object, containing allPdfObjects in a specifiedPdfArray.- Parameters:
array- aPdfArrayto be added to the array
-
-
Method Detail
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Writes the PDF representation of thisPdfArrayas an array ofbyteto the specifiedOutputStream.
-
toString
public java.lang.String toString()
Returns a string representation of thisPdfArray. The string representation consists of a list of allPdfObjects contained in thisPdfArray, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space).
-
set
public PdfObject set(int idx, PdfObject obj)
Overwrites a specified location of the array, returning the previous value- Parameters:
idx- The index of the element to be overwrittenobj- new value for the specified index- Returns:
- the previous value
- Throws:
java.lang.IndexOutOfBoundsException- if the specified position doesn't exist- Since:
- 2.1.5
-
remove
public PdfObject remove(int idx)
Remove the element at the specified position from the array. Shifts any subsequent elements to the left (subtracts one from their indices).- Parameters:
idx- The index of the element to be removed.- Throws:
java.lang.IndexOutOfBoundsException- the specified position doesn't exist- Since:
- 2.1.5
-
getArrayList
public java.util.ArrayList getArrayList()
Deprecated.Get the internal arrayList for this PdfArray. Not Recommended.- Returns:
- the internal ArrayList. Naughty Naughty.
-
size
public int size()
Returns the number of entries in the array.- Returns:
- the size of the ArrayList
-
isEmpty
public boolean isEmpty()
Returnstrueif the array is empty.- Returns:
trueif the array is empty- Since:
- 2.1.5
-
add
public boolean add(PdfObject object)
Adds aPdfObjectto the end of thePdfArray. ThePdfObjectwill be the last element.- Parameters:
object-PdfObjectto add- Returns:
- always
true
-
add
public boolean add(float[] values)
Adds an array offloatvalues to end of thePdfArray. The values will be the last elements. Thefloatvalues are internally converted toPdfNumberobjects.- Parameters:
values- An array offloatvalues to add- Returns:
- always
true
-
add
public boolean add(int[] values)
Adds an array ofintvalues to end of thePdfArray. The values will be the last elements. Theintvalues are internally converted toPdfNumberobjects.- Parameters:
values- An array ofintvalues to add- Returns:
- always
true
-
add
public void add(int index, PdfObject element)Inserts the specified element at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).- Parameters:
index- The index at which the specified element is to be insertedelement- The element to be inserted- Throws:
java.lang.IndexOutOfBoundsException- if the specified index is larger than the last position currently set, plus 1.- Since:
- 2.1.5
-
addFirst
public void addFirst(PdfObject object)
Inserts aPdfObjectat the beginning of thePdfArray. ThePdfObjectwill be the first element, any other elements will be shifted to the right (adds one to their indices).- Parameters:
object- ThePdfObjectto add
-
contains
public boolean contains(PdfObject object)
Checks if thePdfArrayalready contains a certainPdfObject.- Parameters:
object- ThePdfObjectto check- Returns:
true
-
listIterator
public java.util.ListIterator listIterator()
Returns the list iterator for the array.- Returns:
- a ListIterator
-
getPdfObject
public PdfObject getPdfObject(int idx)
Returns thePdfObjectwith the specified index. A possible indirect references is not resolved, so the returnedPdfObjectmay be either a direct object or an indirect reference, depending on how the object is stored in thePdfArray.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- A
PdfObject
-
getDirectObject
public PdfObject getDirectObject(int idx)
Returns thePdfObjectwith the specified index, resolving a possible indirect reference to a direct object. Thus this method will never return aPdfIndirectReferenceobject.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- A direct
PdfObjectornull
-
getAsDict
public PdfDictionary getAsDict(int idx)
Returns aPdfObjectas aPdfDictionary, resolving indirect references. The object corresponding to the specified index is retrieved and resolvedto a direct object. If it is aPdfDictionary, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfDictionaryobject, ornull
-
getAsArray
public PdfArray getAsArray(int idx)
Returns aPdfObjectas aPdfArray, resolving indirect references. The object corresponding to the specified index is retrieved and resolved to a direct object. If it is aPdfArray, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfArrayobject, ornull
-
getAsStream
public PdfStream getAsStream(int idx)
Returns aPdfObjectas aPdfStream, resolving indirect references. The object corresponding to the specified index is retrieved and resolved to a direct object. If it is aPdfStream, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfStreamobject, ornull
-
getAsString
public PdfString getAsString(int idx)
Returns aPdfObjectas aPdfString, resolving indirect references. The object corresponding to the specified index is retrieved and resolved to a direct object. If it is aPdfString, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfStringobject, ornull
-
getAsNumber
public PdfNumber getAsNumber(int idx)
Returns aPdfObjectas aPdfNumber, resolving indirect references. The object corresponding to the specified index is retrieved and resolved to a direct object. If it is aPdfNumber, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfNumberobject, ornull
-
getAsName
public PdfName getAsName(int idx)
Returns aPdfObjectas aPdfName, resolving indirect references. The object corresponding to the specified index is retrieved and resolved to a direct object. If it is aPdfName, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfNameobject, ornull
-
getAsBoolean
public PdfBoolean getAsBoolean(int idx)
Returns aPdfObjectas aPdfBoolean, resolving indirect references. The object corresponding to the specified index is retrieved and resolved to a direct object. If it is aPdfBoolean, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfBooleanobject, ornull
-
getAsIndirectObject
public PdfIndirectReference getAsIndirectObject(int idx)
Returns aPdfObjectas aPdfIndirectReference. The object corresponding to the specified index is retrieved. If it is aPdfIndirectReference, it is cast down and returned as such. Otherwisenullis returned.- Parameters:
idx- The index of thePdfObjectto be returned- Returns:
- the corresponding
PdfIndirectReferenceobject, ornull
-
-