Skip to content

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

Choose a tag to compare

@Nizoka Nizoka released this 05 Jul 02:04
· 11 commits to main since this release
d1299ea

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 /PageLabels number tree — walking /Nums and
    /Kids — back into a typed PageLabelRange[] (decimal / roman / Roman /
    alpha / Alpha / none, with prefix and start). It round-trips the
    v1.4.0 buildPageLabelsDict writer and surfaces logical page numbering to
    tooling such as inspect_pdf. Returns null when 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 granular LayoutDebugOptions with
    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
    LayoutInspection of 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. New src/core/pdf-layout-debug.ts +
    src/core/pdf-layout-inspect.ts; inspectDocumentLayout + LayoutDebugOptions
    / LayoutInspection / InspectedPage / InspectedBlock exported.
    (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 — with buildAnnotation()
    (full indirect object) and buildAnnotationBody() (dict body). On the read
    side, PdfReader.getAnnotations(pageIndex) returns ParsedAnnotation[]
    (decoding UTF-16BE /Contents) and getPageRef(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
    unblocks pdfnative-mcp's redact_pdf overlay mode. New
    src/core/pdf-annot-markup.ts; the annotation types + builders +
    ParsedAnnotation are exported. (src/core/pdf-annot-markup.ts)
  • feat(stream): Streaming document generation (audited). The
    constant-memory buildDocumentPDFStreamTrue() builder was audited against the
    buffered buildDocumentPDFBytes() 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 as pdfnative/fonts/noto-sans-math-data.js under 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 via isMathCodepoint / containsMath and
    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/tools font compiler/parser ([#60]). A new
    pdfnative/tools entry point exposes compileFontData(buffer, opts?) (TTF/OTF
    Uint8Array → font-data module source, byte-identical to
    tools/build-font-data.cjs) and parseFontData(buffer, opts?) (→ an
    introspectable FontDataObject with metrics, cmap, widths, and glyph
    coverage). Types CompiledFontMetrics / 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 with x / y positioning and text-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 .notdef tofu,
    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:issue gate (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() in inspect_pdf.
  • pdfnative-cli and pdfnative-react can re-pin pdfnative@^1.5.0; the
    math font, SVG <text>, layout debug overlay, and inspectDocumentLayout are
    all surfaced through the document builder / SVG block APIs.
  • The new pdfnative/tools entry (compileFontData / parseFontData) lets
    downstream tools build and introspect font-data modules programmatically,
    complementing the npx pdfnative-build-font CLI.

Security

  • AI-agent governance ([#56]). A human-in-the-loop policy plus a
    verify:issue gate 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 set layout.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/tools compiler 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), and tools/font-compiler-report.pdf.
  • npm run validate:pdfa — veraPDF runs in CI.