AwtCanvas

PdfCanvas backed by java.awt.Graphics2D. Pure JRE — no Skia, no Compose, no native binaries.

The right choice when:

  • you're rendering a PDF inside an AWT / Swing / JavaFX (via SwingNode) component

  • you want PNG/JPEG output via javax.imageio.ImageIO without pulling in Skia's native libs

  • server-side rendering where the JVM is already there

Pair with AwtPdfRasterizer for the common "give me a BufferedImage" use case.

Caveats: Java2D supports a subset of PDF's 16 blend modes natively. The common ones (Normal, SrcOver) are mapped to AlphaComposite. The rest (Multiply, Screen, …) require a custom java.awt.Composite — we ship a pixel-level PdfBlendComposite that implements all 16 modes for fidelity.

Constructors

Link copied to clipboard
constructor(g: Graphics2D)

Functions

Link copied to clipboard
open override fun applySoftMask(kind: SoftMask.Kind, maskBBox: Rectangle, maskCtm: Matrix, render: () -> Unit, renderMask: (PdfCanvas) -> Unit)

Soft mask via offscreen compositing. We render the content layer onto an offscreen BufferedImage, render the mask group onto a second one, apply DST_IN, then blit the result onto the underlying Graphics2D.

Link copied to clipboard
open override fun beginPage(widthPt: Double, heightPt: Double, deviceCtm: Matrix)
Link copied to clipboard
open override fun beginTransparencyGroup(bbox: Rectangle, ctm: Matrix, isolated: Boolean, knockout: Boolean, alpha: Double, blendMode: BlendMode)

Open an offscreen layer for transparency-group compositing. Java2D has no built-in saveLayer like Skia, so we manually pixel-render into a BufferedImage and blit it back when the group ends.

Link copied to clipboard
open override fun drawImage(image: ImageXObject, ctm: Matrix, alpha: Double)
Link copied to clipboard
open override fun drawText(bytes: ByteArray, font: PdfFont, fontSize: Double, textMatrix: Matrix, fillColor: RgbColor, alpha: Double, blendMode: BlendMode)
Link copied to clipboard
open override fun endPage()
Link copied to clipboard
open override fun endTransparencyGroup()
Link copied to clipboard
open override fun fillPath(path: PdfPath, ctm: Matrix, color: RgbColor, evenOdd: Boolean, alpha: Double, blendMode: BlendMode)
Link copied to clipboard
open override fun fillShading(shading: PdfShading, ctm: Matrix, clipPath: PdfPath?, alpha: Double, blendMode: BlendMode)
Link copied to clipboard
open override fun popClip()
Link copied to clipboard
open override fun pushClip(path: PdfPath, ctm: Matrix, evenOdd: Boolean)
Link copied to clipboard
open override fun strokePath(path: PdfPath, ctm: Matrix, color: RgbColor, lineWidth: Double, alpha: Double, blendMode: BlendMode, dashArray: List<Double>?, dashPhase: Double)