Composables
The auto-imported usePdfPageNumbers map that activates multi-pass layout.
usePdfPageNumbers
const pageNumbers = usePdfPageNumbers()
// pageNumbers: Readonly<Record<string, number | undefined>>Auto-imported inside PDF templates and the components they render. Returns a
readonly, reactive map from each destination id to the 1-based page it
finally lands on.
Reading it is the only signal that turns on the multi-pass layout loop. The engine lays the document out repeatedly, feeding each pass's destination-page map back in, until the numbers stabilize.
Behavior
- First pass is
undefined. Every entry isundefineduntil the loop has located the destination. A template must support a missing number. Keep a fallback such aspageNumbers[id] ?? ''. - First page of a section. A number resolves to the page the destination's node starts on, even when the section spans pages.
- Throws outside a render. Calling it anywhere but a PDF template's setup
throws a
PDF_TEMPLATE_INVALIDerror, rather than returning an empty map that could be mistaken for first-pass state.
<script setup lang="ts">
const pageNumbers = usePdfPageNumbers()
</script>
<template>
<PdfLink :src="`#${section.id}`">
{{ section.title }} {{ pageNumbers[section.id] ?? '' }}
</PdfLink>
</template>See Contents, links & bookmarks for
convergence semantics and maxPasses.