Takumi

Tickets & receipts

One-page output at an exact paper size, or sized to its content.

Use viewport for a ticket, shipping label, certificate, or receipt. Set both dimensions for fixed paper, or omit the height for a receipt that grows with its content.

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 code or barcode as SVG and pass its bytes through images. Vector paths scale with the page. Check that the printed code has enough physical size and clear space for scanning.

Common sizes in CSS px:

PaperWidth × height
A4 portrait794 × 1123
A4 landscape1123 × 794
A6 postcard397 × 559
4in × 6in label384 × 576
80mm receipt302 × 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 dpi

Percentage 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.

Options and overflow

viewport rejects the paged options as type errors. Everything else carries over, including pdfa and attachments. See Single-page viewport.

The same component can also render as a PNG with takumi-js. Pass image dimensions to the image renderer instead of PDF page options.

Last updated on

On this page