PdfPageRasterizer

Headless raster output for a PdfPage using Skia (no Compose).

Typical use cases:

  • Server-side thumbnail / preview generation

  • "PDF → PNG" CLI converters

  • CI screenshot baselines for visual regression tests

  • Embedding rendered PDF previews into non-Compose JVM UIs (AWT, Swing, JavaFX) by drawing the returned Image / ByteArray through their own image APIs.

The result is a sRGB raster sized by PdfPage.rasterGeometry (rotation, crop box and /UserUnit all included), at scale device pixels per PDF user-space point. Pass scale = 2.0 for retina / "2× density" thumbnails.

Functions

Link copied to clipboard
fun encodeToPng(page: PdfPage, scale: Double = 1.0, background: Int = Color.WHITE): ByteArray

Convenience: render and return PNG bytes.

fun encodeToPng(page: PdfPage, scale: Double = 1.0, background: Int = Color.WHITE, maxPixels: Long): ByteArray

encodeToPng with an explicit allocation ceiling.

Link copied to clipboard
fun renderToImage(page: PdfPage, scale: Double = 1.0, background: Int = Color.WHITE): Image

Render page into a freshly-allocated Skia Image. The caller owns the returned object and should call close() (or use encodeToPng) once done. Skia images hold off-heap memory.

fun renderToImage(page: PdfPage, scale: Double = 1.0, background: Int = Color.WHITE, maxPixels: Long): Image

renderToImage with an explicit allocation ceiling.