Skip to content
Inkoxide

Search covers every page and heading of the docs. Use ↑ ↓ and ↵.

Canvas

Drawing in code, with a painter, at a size the layout gives it.

Edit this page

Import them from @inkoxide/render. Examples, and how these components work together, are in the guide.

Canvas

Imperative drawing with a painter (paint={(p, w, h) => p.circle(w / 2, h / 2, 20).fill('red')}).

import { Canvas, Document, Page, View } from '@inkoxide/render';

export default function Example() {
  return (
    <Document>
      <Page size={[320, 140]}>
        <View className="flex-1 items-center justify-center">
          <Canvas
            width={160}
            height={80}
            paint={(p, w, h) => {
              const sky = p.linearGradient(0, 0, 0, h).stop(0, '#f6c79a').stop(1, '#c4471b');
              p.save().roundedRect(0, 0, w, h, 8).clip();
              p.rect(0, 0, w, h).fill(sky);
              p.restore().circle(w / 2, h / 2, 16).fill('#fff4e2');
            }}
          />
        </View>
      </Page>
    </Document>
  );
}
The PDF this example renders.
PropTypeDescription
paint (required)(painter: import('../canvas.ts').Painter, width: number, height: number) => voidDraws with a pdfkit-style painter; width and height are the canvas size in points.
breakBreakProp
fixedbooleanRepeats the drawing on every page, like fixed on a View.
pagesPageFilter
hrefstring
classNamestringBox utilities for the image the drawing becomes (margins, position, pages…).
styleStyle
debugbooleanOutlines the drawing's box.
width (required)LengthWidth and height of the drawing in the layout (points or units); also the SVG viewport.
height (required)Length

Synced from components/canvas.md in the inkoxide repository.