PdfCanvas
Platform-agnostic 2D drawing surface for one PDF page.
A PdfCanvas is obtained from PdfDriver.beginPage and is valid until the matching PdfDriver.endPage call. All coordinates are in PDF points and use a top-left origin (Y grows downward) — the platform implementations take care of flipping where the native context uses bottom-left.
The interface is deliberately small. New primitive operations should be added here only when they cannot be expressed as a composition of existing ones, and every addition must be implemented on every platform backend.
Functions
Starts a transparency group: subsequent drawing is composited at alpha opacity until the matching endTransparencyGroup. Backends without group support default to a no-op (content draws opaque).
Constrains all subsequent drawing to the area inside commands. Used by container decoration when the corners cannot be expressed as a single uniform cornerRadius. The path is closed implicitly; winding rule is non-zero (the platform default).
Constrains all subsequent drawing to the given rectangle. Effective until the next restoreState call. Wrap calls in saveState / restoreState to scope clipping to a region of code.
Draws a bitmap, optionally embedding only a vertical window of the source — sourceTop / sourceBottom are normalized (0..1) offsets used by the page-break slicer to continue a tall image across pages.
Draws a vector path defined by a sequence of PathCommands.
Fills an axis-aligned rectangle whose four corners are rounded with the given cornerRadius. A radius of zero is equivalent to drawRect.
Closes the group opened by beginTransparencyGroup.
Records an internal go-to link covering the given rectangle and jumping to the namedDestination registered under name. Forward references are fine — backends resolve names when the document is finished. Links whose name is never registered are silently inert.
Registers a named destination at the given vertical position on the current page. Internal links created with linkToDestination (possibly on other pages, before or after this one) jump here.
Restores the canvas state most recently pushed with saveState.
Rotates all subsequent drawing by degrees (clockwise, in the top-left coordinate space) around the pivot point. Effective until the next restoreState — always wrap in saveState / restoreState pairs, which is what the renderer does for rotated containers.
Pushes the current canvas state (transform, clip) onto an internal stack. Pair every call with restoreState; mismatched pairs leak state across draw calls and produce garbled output.