Canvas
Drawing in code, with a painter, at a size the layout gives it.
Import them from @inkoxide/react, @inkoxide/vue or @inkoxide/svelte; an Angular template writes them as <ink-canvas>. 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/react';
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>
);
}
<script setup lang="ts">
import { Canvas, Document, Page, View } from '@inkoxide/vue';
const 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');
};
</script>
<template>
<Document>
<Page :size="[320, 140]">
<View class="flex-1 items-center justify-center">
<Canvas :width="160" :height="80" :paint="paint" />
</View>
</Page>
</Document>
</template>
<script lang="ts">
import { Canvas, Document, Page, View } from '@inkoxide/svelte';
const 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');
};
</script>
<Document>
<Page size={[320, 140]}>
<View class="flex-1 items-center justify-center">
<Canvas width={160} height={80} paint={paint} />
</View>
</Page>
</Document>
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
const 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');
};
@Component({
selector: 'app-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<ink-document>
<ink-page [size]="[320, 140]">
<ink-view class="flex-1 items-center justify-center">
<ink-canvas [width]="160" [height]="80" [paint]="paint" />
</ink-view>
</ink-page>
</ink-document>
`,
})
export class Example {
readonly paint = paint;
}

| Prop | Type | Description |
|---|---|---|
paint (required) | (painter: import('../canvas.ts').Painter, width: number, height: number) => void | Draws with a pdfkit-style painter; width and height are the canvas size in points. |
break | BreakProp | |
fixed | boolean | Repeats the drawing on every page, like fixed on a View. |
pages | PageFilter | |
href | string | |
className | string | Box utilities for the image the drawing becomes (margins, position, pages…). |
style | Style | |
debug | boolean | Outlines the drawing's box. |
width (required) | Length | Width and height of the drawing in the layout (points or units); also the SVG viewport. |
height (required) | Length | |
alt | string | The text the drawing copies and searches as: its alternative text, at most 1024 characters. |
role | 'figure' | 'artifact' | 'artifact': decoration in tagged output. |
Synced from components/canvas.md in the inkoxide repository.