Class PdfArray
- java.lang.Object
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfObject
-
- com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfArray
-
- Direct Known Subclasses:
PdfBorderArray
,PdfColor
,PdfDashPattern
,PdfDestination
,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.3' section 4.6 (page 40).- See Also:
PdfObject
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList
arrayList
this is the actual array of PdfObjects
-
Constructor Summary
Constructors Constructor Description PdfArray()
Constructs an emptyPdfArray
-object.PdfArray(float[] values)
PdfArray(int[] values)
PdfArray(PdfArray array)
Constructs anPdfArray
-object, containing all thePdfObject
s in a givenPdfArray
.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 Modifier and Type Method Description boolean
add(float[] values)
boolean
add(int[] values)
void
add(int index, PdfObject element)
Inserts the specified element at the specified position.boolean
add(PdfObject object)
Adds aPdfObject
to thePdfArray
.void
addFirst(PdfObject object)
Adds aPdfObject
to thePdfArray
.boolean
contains(PdfObject object)
Checks if thePdfArray
already contains a certainPdfObject
.java.util.ArrayList
getArrayList()
Returns an ArrayList containingPdfObject
s.PdfArray
getAsArray(int idx)
Returns aPdfObject
as aPdfArray
, resolving indirect references.PdfBoolean
getAsBoolean(int idx)
Returns aPdfObject
as aPdfBoolean
, resolving indirect references.PdfDictionary
getAsDict(int idx)
Returns aPdfObject
as aPdfDictionary
, resolving indirect references.PdfIndirectReference
getAsIndirectObject(int idx)
Returns aPdfObject
as aPdfIndirectReference
.PdfName
getAsName(int idx)
Returns aPdfObject
as aPdfName
, resolving indirect references.PdfNumber
getAsNumber(int idx)
Returns aPdfObject
as aPdfNumber
, resolving indirect references.PdfStream
getAsStream(int idx)
Returns aPdfObject
as aPdfStream
, resolving indirect references.PdfString
getAsString(int idx)
Returns aPdfObject
as aPdfString
, resolving indirect references.PdfObject
getDirectObject(int idx)
Returns thePdfObject
with the specified index, resolving a possible indirect reference to a direct object.PdfObject
getPdfObject(int idx)
Returns thePdfObject
with the specified index.boolean
isEmpty()
Returnstrue
if the array is empty.java.util.ListIterator
listIterator()
PdfObject
remove(int idx)
Remove the element at the specified position from the array.PdfObject
set(int idx, PdfObject obj)
Overwrites a specified location of the array, returning the previous valueint
size()
Returns the number of entries in the array.void
toPdf(PdfWriter writer, java.io.OutputStream os)
Returns the PDF representation of thisPdfArray
.java.lang.String
toString()
Returns a string representation of thisPdfArray
.-
Methods inherited from class com.gitlab.pdftk_java.com.lowagie.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
- aPdfObject
that has to be added to the array
-
PdfArray
public PdfArray(float[] values)
-
PdfArray
public PdfArray(int[] values)
-
PdfArray
public PdfArray(java.util.ArrayList l)
Constructs aPdfArray
, containing all elements of a specifiedArrayList
.- Parameters:
l
- anArrayList
withPdfObject
s to be added to the array- Throws:
java.lang.ClassCastException
- if theArrayList
contains something that isn't aPdfObject
- Since:
- 2.1.3
-
PdfArray
public PdfArray(PdfArray array)
Constructs anPdfArray
-object, containing all thePdfObject
s in a givenPdfArray
.- Parameters:
array
- aPdfArray
that has to be added to the array
-
-
Method Detail
-
toPdf
public void toPdf(PdfWriter writer, java.io.OutputStream os) throws java.io.IOException
Returns the PDF representation of thisPdfArray
.
-
toString
public java.lang.String toString()
Returns a string representation of thisPdfArray
. The string representation consists of a list of allPdfObject
s 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()
Returns an ArrayList containingPdfObject
s.- Returns:
- an ArrayList
-
size
public int size()
Returns the number of entries in the array.- Returns:
- the size of the ArrayList
-
isEmpty
public boolean isEmpty()
Returnstrue
if the array is empty.- Returns:
true
if the array is empty- Since:
- 2.1.5
-
add
public boolean add(PdfObject object)
Adds aPdfObject
to thePdfArray
.- Parameters:
object
-PdfObject
to add- Returns:
true
-
add
public boolean add(float[] values)
-
add
public boolean add(int[] values)
-
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)
Adds aPdfObject
to thePdfArray
.The newly added object will be the first element in the
ArrayList
.- Parameters:
object
-PdfObject
to add
-
contains
public boolean contains(PdfObject object)
Checks if thePdfArray
already contains a certainPdfObject
.- Parameters:
object
-PdfObject
to check- Returns:
true
-
listIterator
public java.util.ListIterator listIterator()
-
getPdfObject
public PdfObject getPdfObject(int idx)
Returns thePdfObject
with the specified index. A possible indirect references is not resolved, so the returnedPdfObject
may be either a direct object or an indirect reference, depending on how the object is stored in thePdfArray
.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- A
PdfObject
-
getDirectObject
public PdfObject getDirectObject(int idx)
Returns thePdfObject
with the specified index, resolving a possible indirect reference to a direct object. Thus this method will never return aPdfIndirectReference
object.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- A direct
PdfObject
ornull
-
getAsDict
public PdfDictionary getAsDict(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfDictionary
object, ornull
-
getAsArray
public PdfArray getAsArray(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfArray
object, ornull
-
getAsStream
public PdfStream getAsStream(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfStream
object, ornull
-
getAsString
public PdfString getAsString(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfString
object, ornull
-
getAsNumber
public PdfNumber getAsNumber(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfNumber
object, ornull
-
getAsName
public PdfName getAsName(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfName
object, ornull
-
getAsBoolean
public PdfBoolean getAsBoolean(int idx)
Returns aPdfObject
as 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. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfBoolean
object, ornull
-
getAsIndirectObject
public PdfIndirectReference getAsIndirectObject(int idx)
Returns aPdfObject
as aPdfIndirectReference
. The object corresponding to the specified index is retrieved. If it is aPdfIndirectReference
, it is cast down and returned as such. Otherwisenull
is returned.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- the corresponding
PdfIndirectReference
object, ornull
-
-