Tickets & receipts
One-page output at an exact paper size, or sized to its content.
Some documents are one page by definition. A ticket, a shipping label, a certificate, a till receipt. viewport renders exactly one page and skips pagination entirely. See Single-page viewport for how the mode behaves.
Labels and tickets
Give viewport the paper size in CSS px at 96 dpi. Percentage heights resolve against it, so a full-bleed background is height: "100%":
import { } from "takumi-pdf";
// 4in × 6in shipping label
const = await (
< ="flex h-full w-full flex-col justify-between bg-white p-6">
< ="text-2xl font-semibold">ACME · Priority</>
< ="qr.svg" ="Tracking code" ="h-40 w-40 self-center" />
< ="text-xs text-gray-500">1Z 999 AA1 0123 4567</>
</>,
{ : { : 384, : 576 }, : [{ : "qr.svg", : }] },
);Generate the QR or barcode as SVG and pass its bytes through images. SVG sources embed as vector paths, so the code stays crisp at any zoom and any print resolution.
Common sizes in CSS px:
| Paper | Width × height |
|---|---|
| A4 portrait | 794 × 1123 |
| A4 landscape | 1123 × 794 |
| A6 postcard | 397 × 559 |
| 4in × 6in label | 384 × 576 |
| 80mm receipt | 302 × auto |
Receipts
Omit height and the page grows to fit the content. A till receipt is one continuous strip, however many lines it has:
import { } from "takumi-pdf";
const = await (, { : { : 302 } }); // 80mm at 96 dpiPercentage heights do not resolve in this mode. Nothing knows the final height until the layout finishes.
Certificates
A certificate is a fixed page with artwork behind the text. Gradients, borders, radii, and transforms all draw as vectors:
import { } from "takumi-pdf";
const = await (
<
="flex h-full w-full flex-col items-center justify-center"
={{ : "linear-gradient(135deg, #eef2ff, #ffffff)" }}
>
< ="text-sm tracking-[0.3em] text-indigo-500">CERTIFICATE OF COMPLETION</>
< ="mt-6 text-5xl">{}</>
</>,
{ : { : 1123, : 794 } },
);Overflowing content is clipped, exactly like an image render. Size the text to the box, or measure it first.
What the mode gives up
viewport rejects the paged options as type errors. Everything else carries over, including pdfa and attachments. See Single-page viewport.
Rendering the same component as a PNG for email or as a PDF for print is a matter of swapping the renderer. The tree, the CSS, and the Tailwind classes stay as they are.
Last updated on