Takumi

Tickets & receipts

Generate PDF tickets, shipping labels, and receipts with fixed dimensions or content-sized pages.

Use viewport for a ticket, shipping label, certificate, or receipt. Set both dimensions for a fixed paper size, or omit 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%":

Labels and tickets
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. It stays vector at any print size. Check that the printed code is large enough, with enough clear space around it, to scan.

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, so a till receipt is one continuous strip however many lines it has:

Receipts
import {  } from "takumi-pdf";

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

Percentage heights do not resolve in this mode, because the page height is known only after layout.

Certificates

A certificate is a fixed page with artwork behind the text. Gradients, borders, border radii, and transforms all draw as vectors:

Certificates
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 } },
);

Content that overflows the page is clipped, as in an image render. Size the text to fit, or check it first with measure().

Options

viewport rules out the paged options, and TypeScript reports them as type errors. Every other option still works, including pdfa and attachments. See Single-page viewport.

The same component also renders as a PNG with takumi-js. Pass width and height to the image renderer instead of viewport.

Last updated on