PdfPageRasterizer
object 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 to the page in PDF user-space units (1pt = 1/72in) multiplied by scale. Pass scale = 2.0 for retina / "2× density" thumbnails.
Functions
Link copied to clipboard
fun encodeToPng(page: <Error class: unknown class>, scale: Double = 1.0, background: Int = Color.WHITE): ByteArray
Convenience: render and return PNG bytes.
Link copied to clipboard
fun renderToImage(page: <Error class: unknown class>, 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.