Class PdfArray
- Direct Known Subclasses:
PdfBorderArray
,PdfColor
,PdfDashPattern
,PdfDestination
,PdfRectangle
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 Summary
FieldsModifier and TypeFieldDescriptionthis is the actual array of PdfObjects -
Constructor Summary
ConstructorsConstructorDescriptionPdfArray()
Constructs an emptyPdfArray
-object.PdfArray
(float[] values) Constructs aPdfArray
-object, containing allfloat
values in a specified array.PdfArray
(int[] values) Constructs aPdfArray
-object, containing allint
values in a specified array.Constructs anPdfArray
-object, containing allPdfObject
s in a specifiedPdfArray
.Constructs anPdfArray
-object, containing 1PdfObject
.Constructs aPdfArray
, containing all elements of a specifiedList
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(float[] values) Adds an array offloat
values to end of thePdfArray
.boolean
add
(int[] values) Adds an array ofint
values to end of thePdfArray
.void
Inserts the specified element at the specified position.boolean
Adds aPdfObject
to the end of thePdfArray
.void
Inserts aPdfObject
at the beginning of thePdfArray
.boolean
Checks if thePdfArray
already contains a certainPdfObject
.getAsArray
(int idx) Returns aPdfObject
as aPdfArray
, resolving indirect references.getAsBoolean
(int idx) Returns aPdfObject
as aPdfBoolean
, resolving indirect references.getAsDict
(int idx) Returns aPdfObject
as aPdfDictionary
, resolving indirect references.getAsIndirectObject
(int idx) Returns aPdfObject
as aPdfIndirectReference
.getAsName
(int idx) Returns aPdfObject
as aPdfName
, resolving indirect references.getAsNumber
(int idx) Returns aPdfObject
as aPdfNumber
, resolving indirect references.getAsStream
(int idx) Returns aPdfObject
as aPdfStream
, resolving indirect references.getAsString
(int idx) Returns aPdfObject
as aPdfString
, resolving indirect references.getDirectObject
(int idx) Returns thePdfObject
with the specified index, resolving a possible indirect reference to a direct object.Get a copy the internal list for this PdfArray.getPdfObject
(int idx) Returns thePdfObject
with the specified index.boolean
isEmpty()
Returnstrue
if the array is empty.Returns the list iterator for the array.remove
(int idx) Remove the element at the specified position from the array.boolean
Removes the element from the list.Overwrites a specified location of the array, returning the previous valueint
size()
Returns the number of entries in the array.void
toPdf
(PdfWriter writer, OutputStream os) Writes the PDF representation of thisPdfArray
as an array ofbyte
to the specifiedOutputStream
.toString()
Returns a string representation of thisPdfArray
.Methods inherited from class com.lowagie.text.pdf.PdfObject
canBeInObjStm, getBytes, getIndRef, isArray, isBoolean, isDictionary, isIndirect, isName, isNull, isNumber, isStream, isString, length, setContent, setIndRef, type
-
Field Details
-
arrayList
this is the actual array of PdfObjects
-
-
Constructor Details
-
PdfArray
public PdfArray()Constructs an emptyPdfArray
-object. -
PdfArray
Constructs anPdfArray
-object, containing 1PdfObject
.- Parameters:
object
- aPdfObject
that has to be added to the array
-
PdfArray
public PdfArray(float[] values) Constructs aPdfArray
-object, containing allfloat
values in a specified array.The
float
values are internally converted toPdfNumber
objects.- Parameters:
values
- an array offloat
values to be added
-
PdfArray
public PdfArray(int[] values) Constructs aPdfArray
-object, containing allint
values in a specified array.The
int
values are internally converted toPdfNumber
objects.- Parameters:
values
- an array ofint
values to be added
-
PdfArray
Constructs aPdfArray
, containing all elements of a specifiedList
.- Parameters:
pdfObjectList
- anList
withPdfObject
s to be added to the array- Since:
- 2.1.3
-
PdfArray
Constructs anPdfArray
-object, containing allPdfObject
s in a specifiedPdfArray
.- Parameters:
array
- aPdfArray
to be added to the array
-
-
Method Details
-
toPdf
Writes the PDF representation of thisPdfArray
as an array ofbyte
to the specifiedOutputStream
.- Overrides:
toPdf
in classPdfObject
- Parameters:
writer
- for backwards compatibilityos
- theOutputStream
to write the bytes to.- Throws:
IOException
- on error
-
toString
Returns a string representation of thisPdfArray
.The string representation consists of a list of all
PdfObject
s contained in thisPdfArray
, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). -
set
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:
IndexOutOfBoundsException
- if the specified position doesn't exist- Since:
- 2.1.5
-
remove
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.- Returns:
- the PdfObject that was removed
- Throws:
IndexOutOfBoundsException
- the specified position doesn't exist- Since:
- 2.1.5
-
remove
Removes the element from the list.Shifts any subsequent elements to the left (subtracts one from their indices).
- Parameters:
object
- to be removed.
-
getElements
Get a copy the internal list for this PdfArray.- Returns:
- a copy of the the internal List.
-
size
public int size()Returns the number of entries in the array.- Returns:
- the size of the List
-
isEmpty
public boolean isEmpty()Returnstrue
if the array is empty.- Returns:
true
if the array is empty- Since:
- 2.1.5
-
add
Adds aPdfObject
to the end of thePdfArray
.The
PdfObject
will be the last element.- Parameters:
object
-PdfObject
to add- Returns:
- always
true
-
add
public boolean add(float[] values) Adds an array offloat
values to end of thePdfArray
.The values will be the last elements. The
float
values are internally converted toPdfNumber
objects.- Parameters:
values
- An array offloat
values to add- Returns:
- always
true
-
add
public boolean add(int[] values) Adds an array ofint
values to end of thePdfArray
.The values will be the last elements. The
int
values are internally converted toPdfNumber
objects.- Parameters:
values
- An array ofint
values to add- Returns:
- always
true
-
add
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:
IndexOutOfBoundsException
- if the specified index is larger than the last position currently set, plus 1.- Since:
- 2.1.5
-
addFirst
Inserts aPdfObject
at the beginning of thePdfArray
.The
PdfObject
will be the first element, any other elements will be shifted to the right (adds one to their indices).- Parameters:
object
- ThePdfObject
to add
-
contains
Checks if thePdfArray
already contains a certainPdfObject
.- Parameters:
object
- ThePdfObject
to check- Returns:
true
-
listIterator
Returns the list iterator for the array.- Returns:
- a ListIterator
-
getPdfObject
Returns thePdfObject
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 thePdfArray
.- Parameters:
idx
- The index of thePdfObject
to be returned- Returns:
- A
PdfObject
-
getDirectObject
Returns thePdfObject
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 thePdfObject
to be returned- Returns:
- A direct
PdfObject
ornull
-
getAsDict
Returns aPdfObject
as aPdfDictionary
, resolving indirect references.The object corresponding to the specified index is retrieved and resolvedto a direct object. If it is a
PdfDictionary
, 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
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 a
PdfArray
, 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
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 a
PdfStream
, 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
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 a
PdfString
, 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
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 a
PdfNumber
, 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
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 a
PdfName
, 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
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 a
PdfBoolean
, 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
Returns aPdfObject
as aPdfIndirectReference
.The object corresponding to the specified index is retrieved. If it is a
PdfIndirectReference
, 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
-