Anchor-based placement
Find text anchors like assinatura, CPF, or CNPJ and turn them into clamped PDF signature rectangles.
Use findPdfTextAnchors when the business document already names the signing area. It replaces app-side pdfjs-dist scans and transform math with a package-owned matcher over SignatureKit text boxes.
title="anchor-placement.ts"
import { findPdfTextAnchors } from "@signature-kit/pdf/anchors"
import { type PdfSignaturePage } from "@signature-kit/pdf/config"
import { prepareAndSignPdf } from "@signature-kit/pdf/workflow"
import { pdfCoreBrowserLayer } from "@signature-kit/pdf-core/browser"
import { Effect, Layer } from "effect"
const pages: Array<PdfSignaturePage> = template.documents[0]?.pages ?? []
const stampRects = await Effect.runPromise(
findPdfTextAnchors({
pdf,
pages,
matchers: [
{ text: "assinatura:" },
{ digits: "12345678901" }, // CPF/CNPJ-style numeric-only match
],
stampSize: { width: 180, height: 54 },
placement: "below",
offset: 6,
}).pipe(Effect.provide(pdfCoreBrowserLayer)),
)
const signedPdf = await Effect.runPromise(
prepareAndSignPdf({
pdf,
pages,
stampRects,
badge: {
header: { text: "ASSINADO DIGITALMENTE" },
rows: [[{ label: "Signatário", value: "Maria Souza" }]],
footer: [{ text: "ICP-Brasil" }],
},
rubric: { initials: "MS" },
signing: { policy: "pades-icp-brasil", name: "Maria Souza" },
}).pipe(Effect.provide(Layer.merge(layer, pdfCoreBrowserLayer))),
)digits normalizes both the matcher and the PDF text to numeric-only strings, so 123.456.789-01 and 12345678901 match. Returned rectangles are clamped to the page bounds.
Generate with takumi-pdf, then sign
When you build PDFs with takumi-pdf instead of @react-pdf/renderer, install pdf-signature-anchor from the registry and place invisible markers in your JSX. Load takumi only on the client so FumaPress/SSG never executes wasm during prerender.
title="takumi-declaration.tsx"
import { render } from "takumi-pdf"
import {
PdfSignatureAnchor,
PdfSignatureLinkAnchor,
} from "@/components/signature-kit/pdf-signature-anchor"
import { findPdfTextAnchors } from "@signature-kit/pdf/anchors"
import { prepareAndSignPdf } from "@signature-kit/pdf/workflow"
import { pdfCoreBrowserLayer } from "@signature-kit/pdf-core/browser"
import { Effect, Layer } from "effect"
export async function generateAndSign(fontBytes: Uint8Array, signerLayer: Layer.Layer<unknown>) {
const pdf = await render(
<main className="flex flex-col gap-2 p-12 text-[11px]">
<h1 className="text-base font-bold">Declaração de Habilitação</h1>
<p>Declaro, sob as penas da lei, que atendo às condições de habilitação exigidas no edital.</p>
<div className="mt-6 flex flex-col items-center gap-1">
<PdfSignatureAnchor token="{{signature}}" />
<PdfSignatureLinkAnchor href="https://signature.invalid/anchor" />
</div>
</main>,
{ size: "a4", fonts: [{ name: "Liberation", data: fontBytes }] },
)
return Effect.runPromise(
Effect.gen(function* () {
const stampRects = yield* findPdfTextAnchors({
pdf,
matchers: [{ text: "{{signature}}" }, { link: "https://signature.invalid/anchor" }],
stampSize: { width: 180, height: 54 },
placement: "below",
offset: 6,
})
return yield* prepareAndSignPdf({
pdf,
stampRects,
badge: {
header: { text: "ASSINADO DIGITALMENTE" },
rows: [[{ label: "Signatário", value: "Maria Souza" }]],
footer: [{ text: "ICP-Brasil" }],
},
rubric: { initials: "MS" },
signing: { policy: "pades-icp-brasil", name: "Maria Souza" },
})
}).pipe(Effect.provide(Layer.merge(signerLayer, pdfCoreBrowserLayer))),
)
}takumi-pdf only emits http(s) link annotations and silently drops custom URI schemes, so link anchors must use an https:// URI. The default https://signature.invalid/anchor uses the reserved .invalid TLD, so it never resolves if a reader clicks it.