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
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:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPdfArray()Constructs an emptyPdfArray-object.PdfArray(float[] values) PdfArray(int[] values) Constructs anPdfArray-object, containing all thePdfObjects in a givenPdfArray.Constructs anPdfArray-object, containing 1PdfObject.Constructs aPdfArray, containing all elements of a specifiedArrayList. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(float[] values) booleanadd(int[] values) voidInserts the specified element at the specified position.booleanAdds aPdfObjectto thePdfArray.voidAdds aPdfObjectto thePdfArray.booleanChecks if thePdfArrayalready contains a certainPdfObject.Returns an ArrayList containingPdfObjects.getAsArray(int idx) Returns aPdfObjectas aPdfArray, resolving indirect references.getAsBoolean(int idx) Returns aPdfObjectas aPdfBoolean, resolving indirect references.getAsDict(int idx) Returns aPdfObjectas aPdfDictionary, resolving indirect references.getAsIndirectObject(int idx) Returns aPdfObjectas aPdfIndirectReference.getAsName(int idx) Returns aPdfObjectas aPdfName, resolving indirect references.getAsNumber(int idx) Returns aPdfObjectas aPdfNumber, resolving indirect references.getAsStream(int idx) Returns aPdfObjectas aPdfStream, resolving indirect references.getAsString(int idx) Returns aPdfObjectas aPdfString, resolving indirect references.getDirectObject(int idx) Returns thePdfObjectwith the specified index, resolving a possible indirect reference to a direct object.getPdfObject(int idx) Returns thePdfObjectwith the specified index.booleanisEmpty()Returnstrueif the array is empty.remove(int idx) Remove the element at the specified position from the array.Overwrites a specified location of the array, returning the previous valueintsize()Returns the number of entries in the array.voidtoPdf(PdfWriter writer, OutputStream os) Returns the PDF representation of thisPdfArray.toString()Returns a string representation of thisPdfArray.Methods inherited from class 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- aPdfObjectthat has to be added to the array
-
PdfArray
public PdfArray(float[] values) -
PdfArray
public PdfArray(int[] values) -
PdfArray
Constructs aPdfArray, containing all elements of a specifiedArrayList.- Parameters:
l- anArrayListwithPdfObjects to be added to the array- Throws:
ClassCastException- if theArrayListcontains something that isn't aPdfObject- Since:
- 2.1.3
-
PdfArray
Constructs anPdfArray-object, containing all thePdfObjects in a givenPdfArray.- Parameters:
array- aPdfArraythat has to be added to the array
-
-
Method Details
-
toPdf
Returns the PDF representation of thisPdfArray.- Overrides:
toPdfin classPdfObject- Parameters:
writer- for backwards compatibilityos- the outputstream to write the bytes to.- Throws:
IOException
-
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
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.- Throws:
IndexOutOfBoundsException- the specified position doesn't exist- Since:
- 2.1.5
-
getArrayList
-
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
Adds aPdfObjectto thePdfArray.- Parameters:
object-PdfObjectto add- Returns:
true
-
add
public boolean add(float[] values) -
add
public boolean add(int[] values) -
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
Adds aPdfObjectto thePdfArray.The newly added object will be the first element in the
ArrayList.- Parameters:
object-PdfObjectto add
-
contains
Checks if thePdfArrayalready contains a certainPdfObject.- Parameters:
object-PdfObjectto check- Returns:
true
-
listIterator
-
getPdfObject
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
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
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
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
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
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
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
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
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
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
-