box

fun box(width: Dp? = null, height: Dp? = null, background: PdfColor? = null, cornerRadius: Dp = Dp.Zero, padding: Padding = Padding.Zero, border: BorderStroke? = null, cornerRadiusEach: CornerRadius? = null, borderEach: BorderSides? = null, backgroundPaint: PdfPaint? = null, clipToBounds: Boolean = false, dropShadow: DropShadow? = null, rotation: Float = 0.0f, opacity: Float = 1.0f, block: BoxScope.() -> Unit)

Appends a Z-stacking container. Children stack along the depth axis: the first added is at the bottom, the last on top. Use this for image overlays, badges, or any composition where children share the same X/Y space.

Each child is positioned at one of the BoxAlignment anchor points. Children added directly take BoxAlignment.TopStart; wrap a child in aligned to position it elsewhere.

Example:

box(width = 400.dp, height = 200.dp, cornerRadius = 12.dp) {
image(bytes = heroBytes, contentScale = ContentScale.Crop)
aligned(BoxAlignment.BottomStart) {
text("Hero title") { color = PdfColor.White; fontSize = 28.sp }
}
}

Parameters

width

explicit width; null wraps the widest child.

height

explicit height; null wraps the tallest child.

background

optional fill drawn behind every child.

cornerRadius

rounded outline + clip; children are clipped to the rounded shape so they never poke past corners.

padding

inset applied before placing children.

border

outline stroked over the children.