Repository navigation
v1.5.0 — Math/technical-symbols font, pdfnative/tools font compiler, SVG <text>, page-labels reader, layout debug + inspection, markup annotation read/write, AI-agent governance
pdfnative v1.5.0
Delivers the v1.5.0 roadmap — a page-labels reader, a layout debug
overlay + programmatic inspection API, a typed markup-annotation read/write
model, and an audit confirming byte-identical streaming document generation —
plus six resolved GitHub issues: a bundled math / technical-symbols font
(#57), the pdfnative/tools
font compiler/parser (#60),
SVG <text> rendering (#61),
control-character hardening (#58),
a table descender-clipping fix (#59),
and a human-in-the-loop AI-agent governance policy
(#56). 100% backward-compatible —
every new feature is additive or opt-in, and pre-existing PDFs are byte-identical
for unchanged code paths.
Still zero runtime dependencies. 93 test files / 2218 tests, all green.
Highlights
- feat(parser): Page-labels reader (
getPageLabels()).PdfReader.getPageLabels()
parses an existing document's/PageLabelsnumber tree — walking/Numsand
/Kids— back into a typedPageLabelRange[](decimal/roman/Roman/
alpha/Alpha/none, withprefixandstart). It round-trips the
v1.4.0buildPageLabelsDictwriter and surfaces logical page numbering to
tooling such asinspect_pdf. Returnsnullwhen the document has no page
labels. (src/parser/pdf-reader.ts) - feat(core): Layout debug overlay + inspection. An opt-in
layout: { debug: true }(or a granularLayoutDebugOptionswith
showMargins/showContentBounds/showCells) overlays margin, per-block
content-bounds, and table-cell boxes directly onto the rendered PDF for visual
layout debugging — each shape wrapped in its own graphics state and drawn last,
on top of the content. Separately,inspectDocumentLayout(params, layout?)
runs the same pagination engine as the builder but returns a
LayoutInspectionof per-page block geometry (type,page,x,top,
width,height) with no rendering. Both are byte-neutral: with debug
off, output is byte-identical to v1.4.0. Newsrc/core/pdf-layout-debug.ts+
src/core/pdf-layout-inspect.ts;inspectDocumentLayout+LayoutDebugOptions
/LayoutInspection/InspectedPage/InspectedBlockexported.
(src/core/pdf-layout-inspect.ts) - feat(core): Markup annotation read/write. A typed markup-annotation model
covering nine types —text,highlight,underline,strikeout,
squiggly,square,circle,line,freetext— withbuildAnnotation()
(full indirect object) andbuildAnnotationBody()(dict body). On the read
side,PdfReader.getAnnotations(pageIndex)returnsParsedAnnotation[]
(decoding UTF-16BE/Contents) andgetPageRef(pageIndex)resolves a page's
indirect reference; on the write side,PdfModifier.addAnnotation(pageIndex, body)injects a new annotation via a non-destructive incremental update. This
unblockspdfnative-mcp'sredact_pdfoverlay mode. New
src/core/pdf-annot-markup.ts; the annotation types + builders +
ParsedAnnotationare exported. (src/core/pdf-annot-markup.ts) - feat(stream): Streaming document generation (audited). The
constant-memorybuildDocumentPDFStreamTrue()builder was audited against the
bufferedbuildDocumentPDFBytes()and confirmed byte-identical while
freeing each part as it is emitted, so peak memory stays flat for 10k-page
documents. No API change was required — the roadmap item is delivered by the
existing streaming surface. (src/core/pdf-stream-writer.ts) - feat(fonts): Math / technical-symbols font ([#57]). Noto Sans Math
(OFL-1.1) is bundled aspdfnative/fonts/noto-sans-math-data.jsunder lang
'math'. Mathematical operators (U+2200–U+22FF), supplemental / misc math
operators, arrows, letterlike symbols, and Mathematical Alphanumeric Symbols
(U+1D400–U+1D7FF) are detected viaisMathCodepoint/containsMathand
routed automatically by script detection. Opt-in via
registerFont('math', () => import('pdfnative/fonts/noto-sans-math-data.js')).
(src/shaping/script-registry.ts) - feat(tools):
pdfnative/toolsfont compiler/parser ([#60]). A new
pdfnative/toolsentry point exposescompileFontData(buffer, opts?)(TTF/OTF
Uint8Array→ font-data module source, byte-identical to
tools/build-font-data.cjs) andparseFontData(buffer, opts?)(→ an
introspectableFontDataObjectwith metrics, cmap, widths, and glyph
coverage). TypesCompiledFontMetrics/FontDataObject/
CompileFontDataOptions/ParseFontDataOptions. tsup emits
dist/tools/index.{js,cjs,d.ts}. (src/tools/font-compiler.ts) - feat(svg): SVG
<text>rendering ([#61]). SVG<text>elements render as
upright PDF text withx/ypositioning andtext-anchor
(start/middle/end) support — ideal for labelled diagrams and charts.
Text is emitted outside the SVG coordinate transform so it stays upright
regardless of viewBox scaling; control characters are sanitised. MVP: no
automatic word-wrap. (src/core/pdf-svg.ts) - fix(fonts): Control-character hardening ([#58]). Text-run encoding now
drops/escapes control characters that previously produced.notdeftofu,
byte-safe across both base-14 WinAnsi and CIDFont modes. - fix(core): Table descender clipping ([#59]). The table cell clipping
rectangle no longer clips glyph descenders (g, j, p, q, y). - docs(governance): AI-agent human-in-the-loop policy ([#56]).
.github/AGENT_RULES.md and the machine-readable
.github/ai-governance.json codify a
human-in-the-loop protocol for AI agents (no autonomous GitHub writes, no
runtime dependencies, mandatory review of any generated issue report). A new
npm run verify:issuegate (scripts/verify-issue.mjs) validates draft issue
reports (in.github/drafts/) before a human submits them. - docs(site): Authoring+ playground. An eighth browser playground exercises
the v1.5.0 authoring features — SVG<text>labelled charts, the layout debug
overlay +inspectDocumentLayout(), and markup annotations with build +
read-back — entirely client-side.
(docs/playgrounds/authoring-plus.html)
API additions
| Symbol | Kind | Purpose |
|---|---|---|
PdfReader.getPageLabels() |
method | Parse /PageLabels into PageLabelRange[] |
PdfReader.getAnnotations(), getPageRef() |
method | Read page annotations / resolve a page ref |
PdfModifier.addAnnotation() |
method | Inject an annotation via incremental update |
ParsedAnnotation |
type | A parsed page annotation |
inspectDocumentLayout |
fn | Programmatic per-page block geometry |
LayoutDebugOptions, LayoutInspection, InspectedPage, InspectedBlock |
type | Layout debug / inspection types |
PdfLayoutOptions.debug |
field | Opt-in visual layout overlay |
buildAnnotation, buildAnnotationBody |
fn | Build markup annotations |
MarkupAnnotation, TextAnnotation, TextMarkupAnnotation, ShapeAnnotation, LineAnnotation, FreeTextAnnotation, AnnotationBase |
type | Annotation model |
isMathCodepoint, containsMath |
fn | Math-symbol detection (lang 'math') |
compileFontData, parseFontData (pdfnative/tools) |
fn | Font-data compiler / parser |
CompiledFontMetrics, FontDataObject, CompileFontDataOptions, ParseFontDataOptions |
type | pdfnative/tools types |
All additions are additive; no existing signature changed.
Downstream integration notes
- pdfnative-mcp can now implement
redact_pdf's overlay mode on the new
annotation read/write API (getAnnotations/addAnnotation/
buildAnnotationBody), and surface logical page numbering via
getPageLabels()ininspect_pdf. - pdfnative-cli and pdfnative-react can re-pin
pdfnative@^1.5.0; the
math font, SVG<text>, layout debug overlay, andinspectDocumentLayoutare
all surfaced through the document builder / SVG block APIs. - The new
pdfnative/toolsentry (compileFontData/parseFontData) lets
downstream tools build and introspect font-data modules programmatically,
complementing thenpx pdfnative-build-fontCLI.
Security
- AI-agent governance ([#56]). A human-in-the-loop policy plus a
verify:issuegate reduce the risk of unreviewed automated GitHub writes and
dependency additions. No runtime dependency was added — the published package
remains zero-dependency. - Control-character hardening ([#58]). Text-run encoding is byte-safe against
control characters, eliminating a class of.notdef/ malformed-stream output.
Compatibility
- Zero runtime dependencies (unchanged).
- Backward-compatible: every feature is additive or opt-in. Documents that
do not setlayout.debug, do not register the'math'font, and do not use
SVG<text>are byte-identical to v1.4.0. - Node + browser: the full new surface is environment-agnostic; the
pdfnative/toolscompiler reads a font buffer you supply.
Verification
npm run typecheck:all— clean (src + tests + scripts).npm run lint— clean.npm run test— 93 files / 2218 tests, all green (+53 vs v1.4.0).npm run build— ESM + CJS +.d.ts(incl.dist/tools/).npm run test:generate— 210 sample PDFs (+9), incl.math/,svg/svg-text-labels.pdf,
debug/(clean + overlay + inspection),annotations/(types + read-back), andtools/font-compiler-report.pdf.npm run validate:pdfa— veraPDF runs in CI.