Takumi

Headers & footers

Repeat bands on every page with page counters.

header and footer accept any node input. They repeat on every page. Bands lay out at full page width and draw in the page margin areas, like Chromium's print templates. Pick a margin at least as tall as the band, or the band overlaps content, exactly as in Chromium.

import {  } from "takumi-pdf";

const  = await (, {
  : (
    < ="flex w-full justify-center text-[10px] text-gray-500">
      Page < ="pageNumber" /> of < ="totalPages" />
    </>
  ),
});

Sizing the margin

Band height depends on layout, so it is hard to guess ahead of time. measure lays out a tree the same way render measures a band: full page width, counter hooks filled with three-digit numbers. Use the height to pick a margin:

import { ,  } from "takumi-pdf";

const  = (
  < ="flex w-full justify-center text-[10px] text-gray-500">
    Page < ="pageNumber" /> of < ="totalPages" />
  </>
);
const {  } = await (, { : "a4" });
const  = await (, {
  ,
  : { : 48, : .(48,  + 20) },
});

Bands sit 20px in from the paper edge, so leave that on top of the measured height.

Passing viewport instead of a page size measures the tree as-is. Counter hooks stay empty.

Page counters

Elements with pageNumber or totalPages receive counter text. This matches Chromium's print header and footer template contract.

Add a CSS @counter-style name to the class list. It formats the number:

import {  } from "takumi-pdf";

const  = await (, {
  : (
    < ={{ : 12 }}>
      第 < ="pageNumber trad-chinese-informal" /> 頁,共{" "}
      < ="totalPages trad-chinese-informal" /> 頁
    </>
  ),
});
Counter styleExample
decimal (default)12
decimal-leading-zero07
lower-roman / upper-romanxii / XII
cjk-decimal一二
trad-chinese-informal / cjk-ideographic十二

Band height is measured once with three-digit counters. Reaching 100 pages does not shift the layout between pages.

Last updated on

On this page