Takumi

Single-page viewport

Create a single-page PDF with a fixed viewport or a height that fits its content.

Set viewport to render one page, such as a certificate, card, or receipt. With both dimensions set, the page works like an image render: percentage heights resolve against the viewport, and content outside it is clipped.

Single-page viewport
import {  } from "takumi-pdf";

const  = await (< ={{ : "100%", : "100%" }}>Certificate</>, {
  : { : 1123, : 794 }, // A4 landscape in px
});

Content-sized pages

Omit height and the page grows to fit its content, like a thermal receipt. Percentage heights do not resolve in this mode, so size elements by their content or with explicit lengths:

Content-sized pages
import {  } from "takumi-pdf";

const  = await (, { : { : 302 } }); // 80mm at 96 dpi

Options

viewport cannot be combined with the paged options: size, landscape, margin, header, footer, pages, or pageRanges. TypeScript reports the combination as a type error. A single page has no margin, so add padding inside the document for whitespace.

Every other option works the same, including links, outline, metadata, pdfa, and attachments.

Last updated on