This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/annotations/position-and-size.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Retrieve or set annotation bounding box on Android | Nutrient

A bounding box is the rectangular area that surrounds an annotation. Four attributes define the rectangle’s position and size in PDF page coordinates.

Accessing the bounding box

To access an annotation’s bounding box, call Annotation#getBoundingBox. The method returns a RectF(opens in a new tab) instance containing the annotation’s size and position in PDF coordinates:

Log.d(TAG, "The annotation sits at coordinates [${annotation.boundingBox.left}, " +
"${annotation.boundingBox.bottom}].")
Log.d(TAG, "The annotation is " +
"${annotation.boundingBox.width()} x ${-annotation.boundingBox.height()} PDF points large.")

Calculating screen coordinates

Annotation#getBoundingBox returns the bounding box in PDF coordinates. For conversion details, refer to the coordinate space conversion guide.

To convert the bounding box to view coordinates in pixels, use the coordinate conversion API:

// Retrieve a copy of the annotation's current bounding box.
val boundingBox = annotation.boundingBox
// After conversion, the `boundingBox` will be in view coordinates.
fragment.viewProjection.toViewRect(boundingBox, annotation.pageIndex)
Log.d(TAG, "The annotation's screen size is " +
" ${boundingBox.width().toInt()} x ${boundingBox.height().toInt()} pixels")

Annotation#getBoundingBox returns a copy of the bounding box. After modifying the copy, call Annotation#setBoundingBox to update the annotation. The next section demonstrates this process.

Changing the bounding box

To change the bounding box, pass a RectF(opens in a new tab) instance to Annotation#setBoundingBox. Use PDF coordinates for the size and position. The following example reuses the bounding box instance:

// Retrieve the current bounding box from the annotation.
val boundingBox = annotation.boundingBox
// Move the bounding box 100 points up.
boundingBox.offset(0f, 100f)
// Write the new position back to the annotation.
annotation.boundingBox = boundingBox
// Make the changes visible on the screen.
fragment.notifyAnnotationHasChanged(annotation)

Call Annotation#setBoundingBox to apply your changes. Otherwise, Nutrient won’t render or save them.