Export to PNG, SVG and PDF
Download a board or a frame as a PNG or SVG file, or a PDF with one page per frame.
Export a PNG
viewport.exportImage(options) draws the board into a new canvas and resolves to a PNG Blob. It resolves to null when no element on a visible layer is left to draw and no region or frameId is set.
const blob = await viewport.exportImage({ padding: 20 });
if (blob) download(blob, 'board.png');
The options:
scale: pixels per board unit, default 2.padding: space around the elements, in board units, default 0.background: the fill colour. A board PNG or JPEG defaults to the board colour:#ffffffon a light board,#1e1f22on a dark one, or your opaqueboardtoken. A frame PNG defaults to transparent; on a dark board its elements keep their adapted light colours. An explicitbackgroundwins even when it clashes with the theme.theme: the theme to draw with,'light','dark'or{ base, tokens }. It defaults to the board’s current theme;'system'is not accepted.filter(element): returnfalseto leave an element out.region: { x, y, w, h }: exports that rectangle of the board instead of the area the elements cover.frameId: exports one root frame’s exact content rectangle. It includes only that frame’s descendants and leaves out the frame title, border, padding chrome, and unrelated overlap. An empty frame still produces output at its exact size. It conflicts with rasterregion, so supplying both throws.format: 'jpeg', withqualityabove 0 and up to 1, makes a JPEG. A JPEG has no transparency, so keep an opaquebackground.maxDimension(default 16,384px) andmaxPixels(default 67,108,864) cap the output. A larger export throws aRangeError, unlessscaleMode: 'fit'lowers the scale until it fits.
Export an SVG
viewport.exportSVG(options) resolves to an SVG string. It takes the same padding, filter, and
frameId options. frameId selects one root frame’s exact content rectangle and includes only its
descendants, without frame title, border, padding chrome, or unrelated overlap. An empty frame
produces an SVG at that size. SVG does not support region. theme works as for PNG, and an
explicit background wins. Without background, a board SVG gets a rectangle in the board colour
when that colour is opaque (a dark board or a custom opaque board token), while the default light
board has nothing behind the elements. A frame SVG never gets a background, so its light ink on a
dark board needs a dark page behind it.
const svg = await viewport.exportSVG({ padding: 20, background: '#ffffff' });
download(new Blob([svg], { type: 'image/svg+xml' }), 'board.svg');
Strokes, shapes and arrows become SVG paths and shapes. Text, sticky notes and labels are SVG text
laid out as on the canvas, so viewers can select them and find words. Text running past a sticky
note is clipped to the note. Images and HTML elements remain PNG pictures at rasterScale (default
2). Images are embedded as data URLs; one that can’t be loaded keeps its original URL. An empty
board gives a 0 by 0 SVG.
Fonts
setTextFontFamily(family) sets the font of board text on screen and in exports. Call it once at
startup, before creating a viewport, because a later call reaches each element only when it next
redraws. Field Notes doesn’t load the font, so load it in your page, for example with a CSS
@font-face rule.
setTextFontFamily('Inter, system-ui, sans-serif');
ExportSvgOptions.fonts embeds supplied faces in the SVG. The export loads only faces it uses.
onFontError receives an embedding failure; without it, the exporter logs the failure with
console.warn and keeps the family name in the SVG.
export async function exportSvgWithFonts(viewport: Viewport): Promise<void> {
const svg = await viewport.exportSVG({
fonts: [{ family: 'Inter', src: '/fonts/inter.woff2' }],
});
download(new Blob([svg], { type: 'image/svg+xml' }), 'board.svg');
}
Export a PDF
viewport.exportPDF(options) resolves to a PDF Blob, or null for an empty board. Each page is a
picture, so its text can’t be selected. Element links to web pages, email addresses and elements in
the PDF stay clickable. A PDF follows the board theme unless theme overrides it, and an explicit
background wins even when it clashes with themed colours. A dark PDF fills the whole page.
ExportPdfOptions lists:
frameIds: one page per root frame, in this order; without it, one page for the board.pageSize:'a4'595.28 x 841.89 pt, the default;'letter'612 x 792 pt; or{ width, height }in points.orientation:'portrait','landscape'or'auto', the default, landscape when the content is wider than tall.margin: in points, default 36.dpi: pixels per inch of each page picture, default 144.links: default true; false writes no clickable links.
PDF links still point at elements under fog; pass links: false when sharing a fogged board.
export async function exportPdf(viewport: PdfViewport): Promise<void> {
const frameIds = viewport.store
.getAll()
.filter(isFrameElement)
.filter((frame) => frame.parentId === undefined)
.map((frame) => frame.id);
const blob = await viewport.exportPDF({
...(frameIds.length > 0 ? { frameIds } : {}),
pageSize: 'a4',
});
if (blob) download(blob, 'board.pdf');
}
What an export includes
- Elements on visible layers, at each layer’s opacity. Elements on hidden layers are left out.
- Drawing that plugins register for exports, such as the fog on a tabletop map.
- Images from another origin, fetched with anonymous CORS. An image that fails to load shows the
grey placeholder in PNG and PDF; SVG retains the original URL.
onAssetErrorreceives its id, URL andcors,load,timeout, orencodereason. Without a callback, the exporter logs oneconsole.warnper URL. If the image server leaves outVary: Origin, the browser can reuse a cached response without CORS headers and the export draws the placeholder. SendVary: Originfrom that server, or don’t show the same URL elsewhere on your page withoutcrossorigin. - An explicit
background, callerfilter, HTML renderers or painters, image diagnostics, registry capabilities, and render hooks also apply to a frame export.
The selection, remote cursors and the board’s background pattern are not drawn.
HTML elements in an export
An export draws on a canvas, and an HTML element is a DOM node, so the export leaves it out unless you draw it. There are two ways:
renderHtml(element)returns a canvas, anImageBitmapor a loaded image for the element, or a promise of one. The export sizes, rotates and orders it like the element, at its layer’s opacity. Field Notes doesn’t turn DOM into pixels: draw the element from itsdata, as below, or use a DOM-to-image library.- A canvas painter registered with
viewport.registerHtmlPainter(htmlType, painter)draws every element of thathtmlTypein exports, withoutrenderHtml. It also draws them on the board, which then shows no DOM node for them.
function drawCard(element: HtmlElement): HTMLCanvasElement {
const canvas = document.createElement('canvas');
// Twice the element size, to match the default export scale of 2.
canvas.width = element.size.w * 2;
canvas.height = element.size.h * 2;
const ctx = canvas.getContext('2d');
if (!ctx) return canvas;
ctx.scale(2, 2);
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, element.size.w, element.size.h);
ctx.fillStyle = '#2a2d31';
ctx.font = '600 18px sans-serif';
const title = element.data?.title;
ctx.fillText(typeof title === 'string' ? title : '', 16, 32);
return canvas;
}
const blob = await viewport.exportImage({
renderHtml: (element) => (element.htmlType === 'initiative' ? drawCard(element) : null),
onHtmlError: ({ elementId, reason }) => console.warn(`Left out ${elementId}: ${reason}`),
});
if (blob) download(blob, 'board.png');
onHtmlError reports each HTML element left out, with a reason such as unsupported when there is no renderHtml, render when it returns null or throws, and timeout after htmlTimeoutMs (default 10 seconds). The export goes on without that element.