rasterGeometry

rasterGeometry with the library's default allocation ceiling.


fun PdfPage.rasterGeometry(scale: Double = 1.0, maxPixels: Long): PdfRasterGeometry

The PdfRasterGeometry for rendering this page at scale device pixels per PDF user-space unit (so scale = dpi / 72.0). maxPixels prevents an untrusted page size, /UserUnit, or accidental scale from requesting an allocation large enough to terminate the host process.

Composes three things a correct rasterizer needs and a naive one skips:

  • The ROTATED display box (PdfPage.rotatedWidth / rotatedHeight): /CropBox intersected with /MediaBox, with /Rotate folded in (ISO 32000-1 7.7.3.3), not the raw unrotated /MediaBox.

  • PdfPage.pageToDeviceBase, which already maps that box's own origin (wherever /MediaBox sits, not necessarily [0 0]) onto a top-left, y-down device box, rather than a plain Y-flip that assumes the page starts at [0 0].

  • /UserUnit (14.11.2, Table 30): a positive multiplier on the 1/72in default user-space unit, e.g. /UserUnit 2 on a 612-wide page is physically 1224/72in wide, so its rendered output is twice as wide at the same scale. This changes output dimensions for any document that carries /UserUnit, which previously had no effect on rendering at all. A missing, non-positive or non-finite /UserUnit degrades to the spec default of 1 (lenient salvage) rather than producing a zero, negative or mirrored surface.

scale and /UserUnit both multiply the same way, so they compose into one factor applied once: effective = scale * userUnit.