Package com.itextpdf.kernel.pdf
Class PdfArray
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObject
-
- com.itextpdf.kernel.pdf.PdfArray
-
- All Implemented Interfaces:
java.lang.Iterable<PdfObject>
- Direct Known Subclasses:
PdfTextArray
public class PdfArray extends PdfObject implements java.lang.Iterable<PdfObject>
A representation of an array as described in the PDF specification. A PdfArray can contain any subclass ofPdfObject
.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<PdfObject>
list
-
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
Constructors Constructor Description PdfArray()
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
.PdfArray(Rectangle rectangle)
Create a new PdfArray.PdfArray(PdfArray arr)
Create a new PdfArray.PdfArray(PdfObject obj)
Create a new PdfArray with the provided PdfObject as the first item in the array.PdfArray(java.lang.Iterable<? extends PdfObject> objects, int initialCapacity)
Create a new PdfArray.PdfArray(java.util.List<? extends PdfObject> objects)
Create a new PdfArray.PdfArray(java.util.List<java.lang.String> strings, boolean asNames)
Create a new PdfArray filled with a list of Strings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, PdfObject element)
Adds the specified PdfObject at the specified index.void
add(PdfObject pdfObject)
void
addAll(PdfArray a)
Adds content of thePdfArray
.void
addAll(java.util.Collection<PdfObject> c)
Adds the Collection of PdfObjects.void
clear()
boolean
contains(PdfObject o)
protected void
copyContent(PdfObject from, PdfDocument document, ICopyFilter copyFilter)
Copies object content from object 'from'.PdfObject
get(int index)
Gets the (direct) PdfObject at the specified index.PdfObject
get(int index, boolean asDirect)
PdfArray
getAsArray(int index)
Returns the element at the specified index as a PdfArray.PdfBoolean
getAsBoolean(int index)
Returns the element at the specified index as a PdfBoolean.PdfDictionary
getAsDictionary(int index)
Returns the element at the specified index as a PdfDictionary.PdfName
getAsName(int index)
Returns the element at the specified index as a PdfName.PdfNumber
getAsNumber(int index)
Returns the element at the specified index as a PdfNumber.PdfStream
getAsStream(int index)
Returns the element at the specified index as a PdfStream.PdfString
getAsString(int index)
Returns the element at the specified index as a PdfString.byte
getType()
Gets object type.int
indexOf(PdfObject o)
Gets the first index of the specified PdfObject.boolean
isEmpty()
java.util.Iterator<PdfObject>
iterator()
Returns an iterator over an array of PdfObject elements.protected PdfObject
newInstance()
Creates new instance of object.protected void
releaseContent()
Release content of PdfArray.void
remove(int index)
Removes the PdfObject at the specified index.void
remove(PdfObject o)
Removes the first occurrence of the specified PdfObject, if it is present.PdfObject
set(int index, PdfObject element)
Sets the PdfObject at the specified index in the PdfArray.int
size()
java.util.List<PdfObject>
subList(int fromIndex, int toIndex)
Returns a sublist of this PdfArray, starting at fromIndex (inclusive) and ending at toIndex (exclusive).boolean[]
toBooleanArray()
Returns this array as an array of booleans.double[]
toDoubleArray()
Returns this array as an array of doubles.float[]
toFloatArray()
Returns this array as an array of floats.int[]
toIntArray()
Returns this array as an array of ints.java.util.List<PdfObject>
toList()
Returns unmodifiableList
representation of this PdfArray.long[]
toLongArray()
Returns this array as an array of longs.Rectangle
toRectangle()
Returns the first four elements of this array as a PdfArray.java.lang.String
toString()
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObject
checkState, clearState, clone, clone, containsIndirectReference, copyContent, copyTo, copyTo, copyTo, copyTo, equalContent, flush, flush, getIndirectReference, isArray, isBoolean, isDictionary, isFlushed, isIndirect, isIndirectReference, isLiteral, isModified, isName, isNull, isNumber, isReleaseForbidden, isStream, isString, makeIndirect, makeIndirect, processCopying, processCopying, release, setIndirectReference, setModified, setState
-
-
-
-
Field Detail
-
list
protected java.util.List<PdfObject> list
-
-
Constructor Detail
-
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(java.util.List<? extends PdfObject> 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[] 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
public PdfArray(java.util.List<java.lang.String> strings, boolean asNames)
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 listasNames
- indicates whether the strings should be added as PdfName (true) or as PdfString (false)
-
PdfArray
public PdfArray(java.lang.Iterable<? extends PdfObject> 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 PdfArrayinitialCapacity
- Initial capacity of this PdfArray
-
-
Method Detail
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(PdfObject o)
-
iterator
public java.util.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 getPdfIndirectReference
instances for the indirect objects value, you shall useget(int, boolean)
method.- Specified by:
iterator
in interfacejava.lang.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 PdfObjectelement
- PdfObject to be added- See Also:
List.add(int, Object)
-
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 PdfObjectelement
- PdfObject to be added- Returns:
- true if the operation changed the PdfArray
- See Also:
List.set(int, Object)
-
addAll
public void addAll(java.util.Collection<PdfObject> c)
Adds the Collection of PdfObjects.- Parameters:
c
- the Collection of PdfObjects to be added- See Also:
List.addAll(java.util.Collection)
-
addAll
public void addAll(PdfArray a)
Adds content of thePdfArray
.- Parameters:
a
- thePdfArray
to be added- See Also:
List.addAll(java.util.Collection)
-
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:
List.remove(int)
-
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:
List.remove(Object)
-
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:
List.indexOf(Object)
-
subList
public java.util.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:
List.subList(int, int)
-
toList
public java.util.List<PdfObject> 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.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 classPdfObject
- 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 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.
-
-