Page
class Page : AutoCloseable
kotlin.Any | |
↳ | android.graphics.pdf.PdfRendererPreV.Page |
This class represents a PDF document page for rendering.
Summary
Public methods | |
---|---|
Int |
addPageAnnotation(annotation: PdfAnnotation) Adds the given annotation to the page. |
Int |
addPageObject(pageObject: PdfPageObject) Adds the given |
MutableList<Rect!> |
applyEdit(editRecord: FormEditRecord) Applies a |
Unit |
close() Closes this page. |
FormWidgetInfo |
getFormWidgetInfoAtIndex(annotationIndex: Int) Returns information about the widget with |
FormWidgetInfo |
getFormWidgetInfoAtPosition(x: Int, y: Int) Returns information about the widget at the given point. |
MutableList<FormWidgetInfo!> |
Returns information about all form widgets on the page, or an empty list if there are no form widgets on the page. |
MutableList<FormWidgetInfo!> |
getFormWidgetInfos(types: IntArray) Returns information about all form widgets of the specified types on the page, or an empty list if there are no form widgets of the specified types on the page. |
MutableList<PdfPageGotoLinkContent!> |
Gets bookmarks and goto links present on the page of a pdf document. |
Int |
Returns the height of the given |
MutableList<PdfPageImageContent!> |
Return list of |
Int |
getIndex() Gets the page index. |
MutableList<PdfPageLinkContent!> |
Get the bounds and URLs of all the links on the given page. |
MutableList<Pair<Int!, PdfAnnotation!>!> |
Returns a list of pairs, where each pair consists of a supported |
MutableList<Pair<Int!, PdfPageObject!>!> |
Returns |
MutableList<PdfPageTextContent!> |
Return list of |
Pair<Int!, PdfPageObject!>? |
getTopPageObjectAtPosition(point: PointF, types: IntArray) Retrieves the top-most page object at a specified position. |
Int |
getWidth() Returns the width of the given |
Unit |
removePageAnnotation(annotationId: Int) Removes the annotation with the specified id. |
Unit |
removePageObject(objectId: Int) Removes the |
Unit |
render(destination: Bitmap, destClip: Rect?, transform: Matrix?, params: RenderParams) Renders a page to a bitmap. |
MutableList<PageMatchBounds!> |
searchText(query: String) Search for the given string on the page and returns the bounds of all the matches. |
PageSelection? |
selectContent(start: SelectionBoundary, stop: SelectionBoundary) Return a |
Boolean |
updatePageAnnotation(annotationId: Int, annotation: PdfAnnotation) Update the given |
Boolean |
updatePageObject(objectId: Int, pageObject: PdfPageObject) Update the given |
Protected methods | |
---|---|
Unit |
finalize() |
Public methods
addPageAnnotation
fun addPageAnnotation(annotation: PdfAnnotation): Int
Adds the given annotation to the page. The annotation should be of supported type. See PdfAnnotationType
for the supported types
PdfRendererPreV.write
needs to be called to get the updated PDF stream after calling this method. PdfRendererPreV.Page
instance can be closed before calling PdfRendererPreV.write
.
Parameters | |
---|---|
annotation |
PdfAnnotation: the PdfAnnotation object to add This value cannot be null . |
Return | |
---|---|
Int |
id of the added annotation, or -1 if the annotation cannot be added. The id is guaranteed to be non-negative if the annotation is added successfully. Value is -1 or greater |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the provided annotation is of unsupported type i.e. PdfAnnotationType.UNKNOWN or if the add operation failed. |
java.lang.IllegalStateException |
if PdfRendererPreV or PdfRendererPreV.Page is closed before invocation |
addPageObject
fun addPageObject(pageObject: PdfPageObject): Int
Adds the given PdfPageObject
to the page.
PdfRenderer.write
needs to be called to get the updated PDF stream after calling this method. PdfRenderer.Page
instance can be closed before calling PdfRenderer.write
.
Parameters | |
---|---|
pageObject |
PdfPageObject: the PdfPageObject object to add. This value cannot be null . |
Return | |
---|---|
Int |
id of the added page object, or -1 if the page object cannot be added. The id is guaranteed to be non-negative if the page object is added successfully. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the provided PdfPageObject is of unsupported type i.e. PdfPageObjectType.UNKNOWN or if the add operation failed. |
java.lang.IllegalStateException |
if the PdfRenderer.Page is closed before invocation. |
applyEdit
fun applyEdit(editRecord: FormEditRecord): MutableList<Rect!>
Applies a FormEditRecord
to the PDF.
Apps must call render(android.graphics.Bitmap,android.graphics.Rect,android.graphics.Matrix,android.graphics.pdf.RenderParams)
to render new bitmaps for the corresponding areas of the page.
For click type FormEditRecord
s, performs a click on android.graphics.pdf.models.FormEditRecord#getClickPoint()
For set text type FormEditRecord
s, sets the text value of the form widget.
For set indices type FormEditRecord
s, sets the android.graphics.pdf.models.FormEditRecord#getSelectedIndices()
as selected and all others as unselected for the form widget indicated by the record.
Parameters | |
---|---|
editRecord |
FormEditRecord: the FormEditRecord to be applied This value cannot be null . |
Return | |
---|---|
MutableList<Rect!> |
Rectangular areas of the page bitmap that have been invalidated by this action. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the provided FormEditRecord cannot be applied to the widget indicated by the index, or if the index does not correspond to a widget on the page. |
java.lang.IllegalStateException |
If the page is already closed. |
close
fun close(): Unit
Closes this page.
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
getFormWidgetInfoAtIndex
fun getFormWidgetInfoAtIndex(annotationIndex: Int): FormWidgetInfo
Returns information about the widget with annotationIndex
.
Parameters | |
---|---|
annotationIndex |
Int: the index of the widget within the page's widget annotations array in the PDF document, available on results of previous calls to getFormWidgetInfos(int[]) or getFormWidgetInfoAtPosition(int,int) via FormWidgetInfo.getWidgetIndex() . Value is 0 or greater |
Return | |
---|---|
FormWidgetInfo |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if there is no form widget at the provided index. |
java.lang.IllegalStateException |
If the page is already closed. |
getFormWidgetInfoAtPosition
fun getFormWidgetInfoAtPosition(
x: Int,
y: Int
): FormWidgetInfo
Returns information about the widget at the given point.
Parameters | |
---|---|
x |
Int: the x position of the widget on the page, in points |
y |
Int: the y position of the widget on the page, in points |
Return | |
---|---|
FormWidgetInfo |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if there is no form widget at the provided position. |
java.lang.IllegalStateException |
If the page is already closed. |
getFormWidgetInfos
fun getFormWidgetInfos(): MutableList<FormWidgetInfo!>
Returns information about all form widgets on the page, or an empty list if there are no form widgets on the page.
Return | |
---|---|
MutableList<FormWidgetInfo!> |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the page is already closed. |
getFormWidgetInfos
fun getFormWidgetInfos(types: IntArray): MutableList<FormWidgetInfo!>
Returns information about all form widgets of the specified types on the page, or an empty list if there are no form widgets of the specified types on the page.
Parameters | |
---|---|
types |
IntArray: the types of form widgets to return, or an empty array to return all widgets This value cannot be null . Value is android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_UNKNOWN , android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_PUSHBUTTON , android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_CHECKBOX , android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_RADIOBUTTON , android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_COMBOBOX , android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_LISTBOX , android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_TEXTFIELD , or android.graphics.pdf.models.FormWidgetInfo#WIDGET_TYPE_SIGNATURE |
Return | |
---|---|
MutableList<FormWidgetInfo!> |
This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the page is already closed. |
getGotoLinks
fun getGotoLinks(): MutableList<PdfPageGotoLinkContent!>
Gets bookmarks and goto links present on the page of a pdf document. Goto Links are the internal navigation links which directs the user to different location within the same document.
Return | |
---|---|
MutableList<PdfPageGotoLinkContent!> |
list of all goto links PdfPageGotoLinkContent on a page, ordered left to right and top to bottom. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
getHeight
fun getHeight(): Int
Returns the height of the given Page
object in points (1/72"). It is not guaranteed that all pages will have the same height and the viewport should be resized to the given page height.
Return | |
---|---|
Int |
height of the given page Value is 0 or greater |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
getImageContents
fun getImageContents(): MutableList<PdfPageImageContent!>
Return list of PdfPageImageContent
found on the page, ordered left to right and top to bottom. It contains all the content associated with images found on the page including alt text. The list will be empty if there are no results found. Currently, localisation does not have any impact on the order in which PdfPageImageContent
is returned.
Return | |
---|---|
MutableList<PdfPageImageContent!> |
list of image content found on the page. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
getLinkContents
fun getLinkContents(): MutableList<PdfPageLinkContent!>
Get the bounds and URLs of all the links on the given page.
Return | |
---|---|
MutableList<PdfPageLinkContent!> |
list of all links on the page. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
getPageAnnotations
fun getPageAnnotations(): MutableList<Pair<Int!, PdfAnnotation!>!>
Returns a list of pairs, where each pair consists of a supported PdfAnnotation
and its corresponding ID on the specified page. ID of the annotation will be required for updatePageAnnotation(int,android.graphics.pdf.component.PdfAnnotation)
and removePageAnnotation(int)
and will remain same without mutate operations.
The returned list will be empty if no supported annotations are present on the page, even if the page contains other annotation types. Refer to PdfAnnotationType
for the supported annotation types.
Return | |
---|---|
MutableList<Pair<Int!, PdfAnnotation!>!> |
A list of pairs representing the supported annotations and their ids on the page. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if PdfRendererPreV or PdfRendererPreV.Page is closed before invocation. |
getPageObjects
fun getPageObjects(): MutableList<Pair<Int!, PdfPageObject!>!>
Returns List
of Pair
objects, where each pair contains: - An Integer
representing the object ID, which is required for updatePageObject(int,android.graphics.pdf.component.PdfPageObject)
and removePageObject(int)
. Object ID will remain same without mutate operations. - A PdfPageObject
representing the page object.
The list will be empty if there are no supported page objects present on the page, even if the page contains other page object types.
Return | |
---|---|
MutableList<Pair<Int!, PdfPageObject!>!> |
List of Pair objects containing Integer and PdfPageObject . This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the PdfRenderer.Page is closed before invocation. |
getTextContents
fun getTextContents(): MutableList<PdfPageTextContent!>
Return list of PdfPageTextContent
found on the page, ordered left to right and top to bottom. It contains all the content associated with text found on the page. The list will be empty if there are no results found. Currently, localisation does not have any impact on the order in which PdfPageTextContent
is returned.
Return | |
---|---|
MutableList<PdfPageTextContent!> |
list of text content found on the page. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
getTopPageObjectAtPosition
fun getTopPageObjectAtPosition(
point: PointF,
types: IntArray
): Pair<Int!, PdfPageObject!>?
Retrieves the top-most page object at a specified position.
Parameters | |
---|---|
point |
PointF: The coordinates (as a PointF ) on the page to check for page objects. This value cannot be null . |
types |
IntArray: An array of android.graphics.pdf.component.PdfPageObjectType.Type values. Only page objects whose types are included in this array will be considered. If multiple matching objects overlap at the specified point, only the one with the highest z-index will be returned. The order of types within this array does not influence the outcome. If this array is empty, known supported PdfPageObjectType s will be considered. This value cannot be null . Value is android.graphics.pdf.component.PdfPageObjectType#UNKNOWN , android.graphics.pdf.component.PdfPageObjectType#TEXT , android.graphics.pdf.component.PdfPageObjectType#PATH , or android.graphics.pdf.component.PdfPageObjectType#IMAGE |
Return | |
---|---|
Pair<Int!, PdfPageObject!>? |
A Pair containing:
|
Exceptions | |
---|---|
java.lang.IllegalStateException |
if the PdfRenderer.Page is closed before invocation. |
java.lang.IllegalArgumentException |
if the provided type(s) are not supported. |
getWidth
fun getWidth(): Int
Returns the width of the given Page
object in points (1/72"). It is not guaranteed that all pages will have the same width and the viewport should be resized to the given page width.
Return | |
---|---|
Int |
width of the given page Value is 0 or greater |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
removePageAnnotation
fun removePageAnnotation(annotationId: Int): Unit
Removes the annotation with the specified id.
PdfRendererPreV.write
needs to be called to get the updated PDF stream after calling this method. PdfRendererPreV.Page
instance can be closed before calling PdfRendererPreV.write
.
Parameters | |
---|---|
annotationId |
Int: id of the annotation to remove from the page Value is 0 or greater |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if annotationId is negative or invalid or if the remove operation failed. |
java.lang.IllegalStateException |
if PdfRendererPreV or PdfRendererPreV.Page is closed before invocation or if annotation is failed to get removed from the page. |
removePageObject
fun removePageObject(objectId: Int): Unit
Removes the PdfPageObject
with the specified ID.
PdfRenderer.write
needs to be called to get the updated PDF stream after calling this method. PdfRenderer.Page
instance can be closed before calling PdfRenderer.write
.
Parameters | |
---|---|
objectId |
Int: the id of the page object to remove from the page. Value is 0 or greater |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the provided objectId is negative or invalid or if the remove operation failed. |
java.lang.IllegalStateException |
if the page object cannot be removed. |
render
fun render(
destination: Bitmap,
destClip: Rect?,
transform: Matrix?,
params: RenderParams
): Unit
Renders a page to a bitmap. In case of default zoom, the Bitmap
dimensions will be equal to the page dimensions. In this case, Rect
parameter can be null.
In case of zoom, the Rect
parameter needs to be specified which represents the offset from top and left for tile generation purposes. In this case, the Bitmap
dimensions should be equal to the tile dimensions.
Note: The method will take care of closing the bitmap. Should be invoked on the android.annotation.WorkerThread
as it is long-running task.
Parameters | |
---|---|
destination |
Bitmap: Destination bitmap to write to. This value cannot be null . |
destClip |
Rect?: If null, default zoom is applied. In case the value is non-null, the value specifies the top top-left corner of the tile. |
transform |
Matrix?: Applied to scale the bitmap up/down from default 1/72 points. This value may be null . |
params |
RenderParams: Render params for the changing display mode, and / or to control the appearance of annotations and PDF form content This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
searchText
fun searchText(query: String): MutableList<PageMatchBounds!>
Search for the given string on the page and returns the bounds of all the matches. The list will be empty if there are no matches on the given page. If this function was invoked previously for any page, it will wait for that operation to complete before this operation is started.
Note: Should be invoked on the android.annotation.WorkerThread
as it is long-running task.
Parameters | |
---|---|
query |
String: plain search string for querying the document This value cannot be null . |
Return | |
---|---|
MutableList<PageMatchBounds!> |
List of PageMatchBounds representing the bounds of each match on the page. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
selectContent
fun selectContent(
start: SelectionBoundary,
stop: SelectionBoundary
): PageSelection?
Return a PageSelection
which represents the selected content that spans between the two boundaries. The boundaries can be either exactly defined with text indexes, or approximately defined with points on the page. The resulting selection will also be exactly defined with both indexes and points. If the start and stop boundary are both at the same point, selects the word at that point. In case the selection from the given boundaries result in an empty space, then the method returns null
. The start and stop SelectionBoundary
in PageSelection
resolves to the "nearest" index when returned.
Note: Should be invoked on a android.annotation.WorkerThread
as it is long-running task.
Parameters | |
---|---|
start |
SelectionBoundary: boundary where the selection starts (inclusive) This value cannot be null . |
stop |
SelectionBoundary: boundary where the selection stops (exclusive) This value cannot be null . |
Return | |
---|---|
PageSelection? |
collection of the selected content for text, images, etc. |
Exceptions | |
---|---|
java.lang.IllegalStateException |
If the document/page is closed before invocation. |
updatePageAnnotation
fun updatePageAnnotation(
annotationId: Int,
annotation: PdfAnnotation
): Boolean
Update the given PdfAnnotation
to the page.
Note: The PdfAnnotationType
of the provided annotation must be the same as the original annotation being updated.
PdfRendererPreV.write
needs to be called to get the updated PDF stream after calling this method. PdfRendererPreV.Page
instance can be closed before calling PdfRendererPreV.write
.
Parameters | |
---|---|
annotationId |
Int: id corresponding to which the annotation is to be updated Value is 0 or greater |
annotation |
PdfAnnotation: the annotation to update This value cannot be null . |
Return | |
---|---|
Boolean |
true if annotation is updated, false otherwise |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the provided annotation is of unsupported type i.e. PdfAnnotationType.UNKNOWN or if the provided annotationId is negative or if PdfAnnotationType of the provided annotation is different from the original annotation's type |
java.lang.IllegalStateException |
if PdfRendererPreV or PdfRendererPreV.Page is closed before invocation |
updatePageObject
fun updatePageObject(
objectId: Int,
pageObject: PdfPageObject
): Boolean
Update the given PdfPageObject
to the page.
Note: This method only updates the parameters of the PageObject whose setters are available. Attempting to update fields with no corresponding setters will have no effect. Furthermore, the PdfPageObjectType
of the provided pageObject must be the same as the original pageObject being updated.
PdfRenderer.write
needs to be called to get the updated PDF stream after calling this method. PdfRenderer.Page
instance can be closed before calling PdfRenderer.write
.
Parameters | |
---|---|
objectId |
Int: The unique identifier of the page object to update. Value is 0 or greater |
pageObject |
PdfPageObject: The PdfPageObject object to update. This value cannot be null . |
Return | |
---|---|
Boolean |
true if page object is updated, false otherwise. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the provided PdfPageObject is unsupported or if the PdfPageObjectType of the provided pageObject is different from the original pageObject's type. |
java.lang.IllegalStateException |
if the PdfRenderer.Page is closed before invocation. |
Protected methods
finalize
protected fun finalize(): Unit
Exceptions | |
---|---|
java.lang.Throwable |
the Exception raised by this method |