Package com.itextpdf.kernel.pdf
Class PdfArray
java.lang.Object
com.itextpdf.kernel.pdf.PdfObject
com.itextpdf.kernel.pdf.PdfArray
- Direct Known Subclasses:
-
PdfTextArray
A representation of an array as described in the PDF specification. A PdfArray can contain any subclass of
PdfObject
.
-
Field Summary
Fields inherited from class com.itextpdf.kernel.pdf.PdfObject
ARRAY, BOOLEAN, DICTIONARY, FLUSHED, FORBID_RELEASE, FREE, INDIRECT_REFERENCE, indirectReference, LITERAL, MODIFIED, MUST_BE_FLUSHED, MUST_BE_INDIRECT, NAME, NULL, NUMBER, ORIGINAL_OBJECT_STREAM, READ_ONLY, READING, STREAM, STRING, UNENCRYPTED
-
Constructor Summary
ConstructorDescriptionPdfArray()
Create a new, empty PdfArray.PdfArray
(boolean[] values) Create a new PdfArray filled with the values in the boolean[] asPdfBoolean
.PdfArray
(double[] numbers) Create a new PdfArray filled with the values in the double[] asPdfNumber
.PdfArray
(float[] numbers) Create a new PdfArray filled with the values in the float[] asPdfNumber
.PdfArray
(int[] numbers) Create a new PdfArray filled with the values in the int[] asPdfNumber
.Create a new PdfArray.Create a new PdfArray.Create a new PdfArray with the provided PdfObject as the first item in the array.Create a new PdfArray.Create a new PdfArray.Create a new PdfArray filled with a list of Strings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the specified PdfObject at the specified index.void
void
Adds content of thePdfArray
.void
Adds the Collection of PdfObjects.void
clear()
boolean
protected void
copyContent
(PdfObject from, PdfDocument document, ICopyFilter copyFilter) Copies object content from object 'from'.get
(int index) Gets the (direct) PdfObject at the specified index.get
(int index, boolean asDirect) getAsArray
(int index) Returns the element at the specified index as a PdfArray.getAsBoolean
(int index) Returns the element at the specified index as a PdfBoolean.getAsDictionary
(int index) Returns the element at the specified index as a PdfDictionary.getAsName
(int index) Returns the element at the specified index as a PdfName.getAsNumber
(int index) Returns the element at the specified index as a PdfNumber.getAsStream
(int index) Returns the element at the specified index as a PdfStream.getAsString
(int index) Returns the element at the specified index as a PdfString.byte
getType()
Gets object type.int
Gets the first index of the specified PdfObject.boolean
isEmpty()
iterator()
Returns an iterator over an array of PdfObject elements.protected PdfObject
Creates new instance of object.protected void
Release content of PdfArray.void
remove
(int index) Removes the PdfObject at the specified index.void
Removes the first occurrence of the specified PdfObject, if it is present.Sets the PdfObject at the specified index in the PdfArray.int
size()
subList
(int fromIndex, int toIndex) Returns a sublist of this PdfArray, starting at fromIndex (inclusive) and ending at toIndex (exclusive).boolean[]
Returns this array as an array of booleans.double[]
Returns this array as an array of doubles.float[]
Returns this array as an array of floats.int[]
Returns this array as an array of ints.toList()
Returns unmodifiableList
representation of this PdfArray.long[]
Returns this array as an array of longs.Returns the first four elements of this array as a PdfArray.toString()
Methods inherited from class com.itextpdf.kernel.pdf.PdfObject
checkState, clearState, clone, clone, copyContent, copyTo, copyTo, copyTo, copyTo, flush, flush, getIndirectReference, isArray, isBoolean, isDictionary, isFlushed, isIndirect, isIndirectReference, isLiteral, isModified, isName, isNull, isNumber, isReleaseForbidden, isStream, isString, makeIndirect, makeIndirect, release, setIndirectReference, setModified, setState
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
list
-
-
Constructor Details
-
PdfArray
public PdfArray()Create a new, empty PdfArray. -
PdfArray
Create a new PdfArray with the provided PdfObject as the first item in the array.- Parameters:
-
obj
- first item in the array
-
PdfArray
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
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
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[] asPdfNumber
.- 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[] asPdfNumber
.- 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[] asPdfNumber
.- 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[] asPdfBoolean
.- Parameters:
-
values
- values to be added to this PdfArray
-
PdfArray
Create a new PdfArray filled with a list of Strings. The boolean value decides if the Strings should be added asPdfName
(true) or asPdfString
(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
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
-
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 getPdfIndirectReference
instances for the indirect objects value, you shall useget(int, boolean)
method. -
add
-
add
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
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
Adds the Collection of PdfObjects.- Parameters:
-
c
- the Collection of PdfObjects to be added - See Also:
-
addAll
Adds content of thePdfArray
.- Parameters:
-
a
- thePdfArray
to be added - See Also:
-
get
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
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
Gets the first index of the specified PdfObject.- Parameters:
-
o
- PdfObject to find the index of - Returns:
- index of the PdfObject
- See Also:
-
subList
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:
-
toList
Returns unmodifiableList
representation of this PdfArray.- Returns:
-
unmodifiable
List
representation of this PdfArray
-
getType
public byte getType()Description copied from class:PdfObject
Gets object type. -
toString
-
get
- 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
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
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
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
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
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
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
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
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
Description copied from class:PdfObject
Creates new instance of object.- Specified by:
-
newInstance
in classPdfObject
- Returns:
- new instance of object.
-
copyContent
Description copied from class:PdfObject
Copies object content from object 'from'.- Overrides:
-
copyContent
in classPdfObject
- Parameters:
-
from
- object to copy content from. -
document
- document to copy object to. -
copyFilter
-ICopyFilter
a filter that will apply on dictionaries and array UseNullCopyFilter
for no filtering
-
releaseContent
protected void releaseContent()Release content of PdfArray.
-