pdfnative 1.0.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,6 +15,24 @@
15
15
 
16
16
  Pure native PDF generation library — zero vendor dependencies. ISO 32000-1 (PDF 1.7) compliant.
17
17
 
18
+ ## Ecosystem
19
+
20
+ pdfnative ships as three coordinated packages — pick whichever entry point fits your workflow:
21
+
22
+ | Package | Latest | Use it for |
23
+ |---|:---:|---|
24
+ | [`pdfnative`](https://www.npmjs.com/package/pdfnative) | **v1.2.0** | The library itself — call from Node, browsers, Workers, Deno, Bun. |
25
+ | [`pdfnative-cli`](https://www.npmjs.com/package/pdfnative-cli) | **v0.3.0** | Render JSON → PDF, sign (RSA + ECDSA-SHA256, RFC 3161 detection), inspect, and verify CMS signatures from the shell. New in v0.3.0: `--watch`, `--template`, `--font {latin,emoji}`, auto signature placeholder. |
26
+ | [`pdfnative-mcp`](https://www.npmjs.com/package/pdfnative-mcp) | **v0.3.0** | Use pdfnative from Claude Desktop, Cursor, Continue, Zed (or any stdio MCP client) — **9 structured tools** including the new `inspect_pdf`, a `pdfA` flag on every doc tool, multi-script `lang`, and per-tool `outputSchema` (MCP 2025-06-18). |
27
+
28
+ ```bash
29
+ npm install pdfnative # library
30
+ npm install -g pdfnative-cli # CLI
31
+ npm install -g pdfnative-mcp # MCP server
32
+ ```
33
+
34
+ Detailed docs: [CLI guide](docs/guides/cli.md) · [MCP guide](docs/guides/mcp.md) · [Onboarding cheatsheet](docs/guides/onboarding.md).
35
+
18
36
  ## Highlights
19
37
 
20
38
  - **Zero dependencies** — built from scratch in pure TypeScript. Zero runtime dependencies, tree-shakeable, auditable
@@ -22,17 +40,19 @@ Pure native PDF generation library — zero vendor dependencies. ISO 32000-1 (PD
22
40
  - **16 Unicode scripts** — Thai, Japanese, Chinese (SC), Korean, Greek, Devanagari, Turkish, Vietnamese, Polish, Arabic, Hebrew, Cyrillic, Georgian, Armenian, Bengali, Tamil
23
41
  - **Thai OpenType shaping** — GSUB substitution + GPOS mark-to-base + mark-to-mark positioning
24
42
  - **Arabic positional shaping** — GSUB isolated/initial/medial/final forms + lam-alef ligatures
25
- - **BiDi text layout** — simplified Unicode Bidirectional Algorithm (UAX #9) with glyph mirroring
43
+ - **BiDi text layout** — Unicode Bidirectional Algorithm (UAX #9) with glyph mirroring, isolates (LRI/RLI/FSI/PDI), and explicit embeddings (LRE/RLE/LRO/RLO/PDF)
44
+ - **USE-lite cluster classifier** — public API (`classifyUseCategory`, `classifyClusters`) with per-script tables for Devanagari, Bengali, Tamil (v1.2.0; shaper rewire lands in v1.3)
26
45
  - **Multi-font fallback** — automatic cross-script font switching with continuation bias
27
46
  - **TTF subsetting** — only used glyphs embedded (dramatic file size reduction)
28
47
  - **Tagged PDF / PDF/A** — structure tree, /ActualText, XMP metadata, sRGB OutputIntent (PDF/A-1b, 2b, 2u, 3b with embedded file attachments)
29
48
  - **PDF Encryption** — AES-128 (V4/R4) and AES-256 (V5/R6), owner + user passwords, granular permissions
30
49
  - **Free-form document builder** — headings, paragraphs, lists, tables, images, barcodes, SVG paths, form fields, spacers, page breaks, table of contents
50
+ - **Smart tables** — multi-page slicing with repeated headers, auto-wrap on column overflow, zebra striping, captions, and smart auto-fit columns (v1.2.0). [Guide →](docs/guides/tables.md)
31
51
  - **Barcode & QR code generation** — Code 128, EAN-13, QR Code, Data Matrix, PDF417 — pure PDF path operators (no images)
32
52
  - **SVG path rendering** — path, rect, circle, ellipse, line, polyline, polygon as native PDF operators
33
53
  - **AcroForm fields** — text, multiline, checkbox, radio, dropdown, listbox with appearance streams (ISO 32000-1 §12.7)
34
- - **Digital signatures** — CMS/PKCS#7 detached signatures with RSA + ECDSA, SHA-256/384/512, X.509 parsing (ISO 32000-1 §12.8)
35
- - **Streaming output** — AsyncGenerator-based progressive PDF emission with configurable chunk size
54
+ - **Digital signatures** — CMS/PKCS#7 detached signatures with RSA + ECDSA, SHA-256/384/512, X.509 parsing (ISO 32000-1 §12.8). One-call placeholder injection via `addSignaturePlaceholder()` (v1.2.0)
55
+ - **Streaming output** — AsyncGenerator-based progressive PDF emission with configurable chunk size, plus object-boundary page-by-page streaming (`buildPDFStreamPageByPage()`, v1.2.0)
36
56
  - **PDF parser & modifier** — read existing PDFs (tokenizer, xref, object parser, FlateDecode inflate) + incremental modification
37
57
  - **Image embedding** — JPEG (DCTDecode) and PNG (FlateDecode) with auto-scaling and alignment
38
58
  - **Hyperlinks** — PDF link annotations (/URI) with URL validation, blue underlined text, tagged /Link
@@ -42,7 +62,7 @@ Pure native PDF generation library — zero vendor dependencies. ISO 32000-1 (PD
42
62
  - **FlateDecode compression** — zlib stream compression (50–90% size reduction), zero-dependency, platform-native
43
63
  - **Web Worker support** — off-main-thread generation for large datasets
44
64
  - **Tree-shakeable** — ESM + CJS dual build with TypeScript declarations
45
- - **95%+ test coverage** — 1588+ tests across 40 files, fuzz suite, performance benchmarks
65
+ - **95%+ test coverage** — 1822+ tests across 53 files, fuzz suite, performance benchmarks
46
66
  - **NPM provenance** — signed builds via GitHub Actions OIDC
47
67
  - **On-device generation** — runs in Node, browsers, Workers, Deno, Bun. No SaaS round-trip; documents never leave the calling process unless your application explicitly sends them
48
68
  - **No telemetry, no network calls** — verifiable in source. The library never opens a socket, fetches remote fonts, or phones home
@@ -181,6 +201,11 @@ registerFonts({
181
201
  hy: () => import('pdfnative/fonts/noto-armenian-data.js'),
182
202
  bn: () => import('pdfnative/fonts/noto-bengali-data.js'),
183
203
  ta: () => import('pdfnative/fonts/noto-tamil-data.js'),
204
+ // v1.1.0+ — optional Latin fallback for PDF/A documents with curly quotes,
205
+ // em-dash, ellipsis, etc. (activates automatically when needed):
206
+ latin: () => import('pdfnative/fonts/noto-sans-data.js'),
207
+ // v1.1.0+ — optional monochrome emoji:
208
+ emoji: () => import('pdfnative/fonts/noto-emoji-data.js'),
184
209
  });
185
210
 
186
211
  const thaiFont = await loadFontData('th');
@@ -212,6 +237,8 @@ const pdf = buildPDFBytes({
212
237
  | Armenian | `hy` | Noto Sans Armenian | Armenian alphabet |
213
238
  | Bengali | `bn` | Noto Sans Bengali | GSUB conjuncts + GPOS marks |
214
239
  | Tamil | `ta` | Noto Sans Tamil | GSUB ligatures + split vowels |
240
+ | Latin (PDF/A) | `latin` | Noto Sans VF | WinAnsi-extended Latin (curly quotes, em-dash, ellipsis…) |
241
+ | Emoji | `emoji` | Noto Emoji | Monochrome emoji (BMP/SMP, Fitzpatrick, ZWJ, VS-15/16) |
215
242
 
216
243
  ## Multi-Font (Mixed Scripts)
217
244
 
@@ -369,7 +396,7 @@ Generate sample PDFs for all supported languages to visually verify output:
369
396
  npm run test:generate
370
397
  ```
371
398
 
372
- This creates **140+ PDF files** in `test-output/` (git-ignored), organized in twenty-three categories.
399
+ This creates **150+ PDF files** in `test-output/` (git-ignored), organized in twenty-five categories (including `emoji/` and `pdfa-latin/` added in v1.1.0).
373
400
  See [scripts/README.md](scripts/README.md) for the modular generator architecture.
374
401
 
375
402
  ### Financial Statements (per language)
@@ -814,24 +841,39 @@ pdfnative ships as a library, but two official companion packages cover the most
814
841
 
815
842
  ### pdfnative-cli — command-line interface
816
843
 
817
- [`pdfnative-cli`](https://github.com/Nizoka/pdfnative-cli) is the **official CLI**. It exposes three commands — `render`, `sign`, `inspect` — for use in shell scripts, Makefiles, GitHub Actions, and Docker images. Zero extra runtime dependencies, npm-provenance-signed.
844
+ [`pdfnative-cli`](https://github.com/Nizoka/pdfnative-cli) v0.3.0 is the **official CLI**. It exposes four commands — `render`, `sign`, `inspect`, **`verify`** covering the full `pdfnative` v1.1.0 surface for use in shell scripts, Makefiles, GitHub Actions, and Docker images. Zero extra runtime dependencies, npm-provenance-signed.
818
845
 
819
- ```bash
820
- # render a JSON document spec to PDF
821
- npx pdfnative-cli render document.json --output report.pdf
846
+ **New in v0.3.0:** ECDSA-SHA256 (P-256) signing fully wired, real CMS/PKCS#7 verification with RFC 3161 timestamp detection, automatic signature-placeholder injection on `sign`, plus three iteration-friendly `render` flags (`--watch`, `--template`, `--font {latin,emoji}`). **100 % backward-compatible** with v0.2.0.
822
847
 
823
- # sign an existing PDF (RSA or ECDSA, CMS/PKCS#7)
824
- npx pdfnative-cli sign report.pdf --cert cert.pem --key key.pem --output signed.pdf
848
+ **Previously (v0.2.0):** hybrid `flags + --layout file.json` model, encryption (AES-128/256), watermarks (text + image), header/footer page templates with `{page}/{pages}/{date}/{title}`, PDF/A-3 attachments (Factur-X / ZUGFeRD pattern), multilingual fonts via `--lang`, table-variant rendering, signing metadata + intermediate cert chains, `inspect --verbose/--pages/--check`, and the `verify` command.
825
849
 
826
- # inspect a PDF (page count, metadata, fonts, signatures)
827
- npx pdfnative-cli inspect signed.pdf
850
+ ```bash
851
+ # render with full layout coverage (encryption + watermark + PDF/A-2b)
852
+ npx pdfnative-cli render --input doc.json --output report.pdf \
853
+ --tagged pdfa2b --compress \
854
+ --watermark-text "DRAFT" --watermark-opacity 0.15
855
+
856
+ # sign with metadata and intermediate cert chain
857
+ npx pdfnative-cli sign --input report.pdf --output signed.pdf \
858
+ --reason "Approved" --name "Finance Team" \
859
+ --signing-time 2026-04-28T10:00:00Z \
860
+ --cert-chain intermediate.pem
861
+
862
+ # verify embedded signatures (byte-range + chain + trust)
863
+ npx pdfnative-cli verify --input signed.pdf --strict --trust ca-root.pem
864
+
865
+ # inspect with CI assertions (exit 1 on failure)
866
+ npx pdfnative-cli inspect --input signed.pdf \
867
+ --check pdfa --check signed --format json
828
868
  ```
829
869
 
830
- See the [CLI Guide](https://pdfnative.dev/guides/cli.html) for full reference, security model, and pipeline examples.
870
+ See the [CLI Guide](https://pdfnative.dev/guides/cli.html) for the full v0.3.0 reference, security model, recipes, and the `--conformance` → `--tagged` migration path. Try the [interactive CLI playground](https://pdfnative.dev/playgrounds/cli.html) to build commands without leaving the browser.
831
871
 
832
872
  ### pdfnative-mcp — Model Context Protocol server
833
873
 
834
- [`pdfnative-mcp`](https://github.com/Nizoka/pdfnative-mcp) is a **Model Context Protocol server** that bridges pdfnative to any MCP-compatible AI client. Once configured, your AI assistant can generate PDFs, embed barcodes, create forms, sign documents, and render international text — all without writing code.
874
+ [`pdfnative-mcp`](https://github.com/Nizoka/pdfnative-mcp) v0.3.0 is a **Model Context Protocol server** that bridges pdfnative to any MCP-compatible AI client. Once configured, your AI assistant can generate PDFs, embed barcodes, create forms, sign documents, render international text, and **inspect** existing PDFs — all without writing code.
875
+
876
+ **New in v0.3.0:** `inspect_pdf` (the 9th tool, structured metadata/page/signature/PDF/A report), `pdfA` flag on every document tool, multi-script `lang` (`string | string[] | csv`) with bundled `latin` + `emoji` codes, `add_table` `autoFitColumns`/`clipCells`, and per-tool `outputSchema` per the MCP 2025-06-18 spec.
835
877
 
836
878
  ```bash
837
879
  npx -y pdfnative-mcp
@@ -842,13 +884,14 @@ npx -y pdfnative-mcp
842
884
  | Tool | Purpose |
843
885
  |------|---------|
844
886
  | `generate_basic_pdf` | Multi-page documents from structured blocks (headings, paragraphs, lists) |
845
- | `add_table` | Tabular reports from column headers and data rows |
887
+ | `add_table` | Tabular reports from column headers and data rows (v0.3.0: `autoFitColumns`, `clipCells`) |
846
888
  | `add_barcode` | QR Code, Code 128, EAN-13, Data Matrix, PDF417 |
847
- | `add_international_text` | 16 non-Latin scripts with BiDi & OpenType shaping |
889
+ | `add_international_text` | 16 non-Latin scripts with BiDi & OpenType shaping (v0.3.0: multi-script `lang`) |
848
890
  | `add_form` | Interactive AcroForm PDFs (text, checkbox, radio, dropdown) |
849
891
  | `embed_image` | Embed a JPEG or PNG image (base64) |
850
892
  | `prepare_signature_placeholder` | PDF with a `/Sig` field ready to be signed |
851
893
  | `sign_pdf` | CMS/PKCS#7 digital signatures (RSA-SHA256 / ECDSA-SHA256) |
894
+ | `inspect_pdf` | **New in v0.3.0** — structured PDF report (metadata, pages, signatures, PDF/A) |
852
895
 
853
896
  ### Claude Desktop configuration
854
897
 
@@ -931,7 +974,7 @@ src/
931
974
  fonts/ # Pre-built font data modules (16 scripts)
932
975
  tools/ # CLI: build-font-data.cjs (TTF → JS module)
933
976
  scripts/ # Modular sample PDF generation (23 generators, 140+ PDFs)
934
- tests/ # 1588+ tests (40 files: unit + integration + fuzz + parser)
977
+ tests/ # 1726+ tests (48 files: unit + integration + fuzz + parser)
935
978
  bench/ # Performance benchmarks (vitest bench)
936
979
  ```
937
980
 
@@ -945,7 +988,7 @@ npm install
945
988
  npm run build # tsup → dist/ (ESM + CJS + .d.ts)
946
989
  npm run test # vitest run (1588+ tests)
947
990
  npm run test:coverage # vitest with v8 coverage (95%+)
948
- npm run test:generate # Generate 140+ sample PDFs → test-output/
991
+ npm run test:generate # Generate 150+ sample PDFs → test-output/
949
992
  npm run lint # ESLint 9 + typescript-eslint strict
950
993
  npm run typecheck # tsc --noEmit (src/)
951
994
  npm run typecheck:tests # tsc --project tsconfig.test.json
@@ -1010,17 +1053,26 @@ When `tagged` is set, the output includes:
1010
1053
 
1011
1054
  The `tagged` option is backward-compatible — omitting it or setting `false` produces the same output as before.
1012
1055
 
1013
- > **PDF/A status (v1.0.4).** As of v1.0.4 every PDF emits a trailer
1014
- > `/ID` and the `/Info CreationDate` is byte-equivalent to the
1015
- > `xmp:CreateDate` (with timezone offset) closing two veraPDF
1016
- > reference-validator findings. **Latin font embedding** is **not yet
1017
- > implemented**: standard 14 Helvetica is still emitted as an
1018
- > unembedded reference, which veraPDF flags under ISO 19005-1 §6.3.4.
1019
- > Treat the `pdfaid:part` claim in XMP as aspirational until **v1.0.5**
1020
- > lands. See [docs/guides/pdfa.html](docs/guides/pdfa.html) and the
1021
- > tracking issue [release-notes/draft-issue-v1.0.5-latin-embedding.md](release-notes/draft-issue-v1.0.5-latin-embedding.md).
1022
- > Run `npm run validate:pdfa` locally (with veraPDF installed) to
1023
- > verify against the reference validator.
1056
+ > **PDF/A status (v1.1.0).** Every PDF/A-claiming sample now passes
1057
+ > the **veraPDF** reference validator (1b / 2b / 2u / 3b) when the
1058
+ > Latin font module is registered. Trailer `/ID` and
1059
+ > `/Info CreationDate` are byte-equivalent to `xmp:CreateDate`
1060
+ > (with timezone offset). `<dc:title>`, `<dc:description>`,
1061
+ > `<pdf:Keywords>` mirror `/Info /Title`, `/Subject`, `/Keywords`
1062
+ > byte-for-byte (ISO 19005-1 §6.7.3 t1 / t4 / t5). Object 3 / Object 4
1063
+ > are emitted as Type0 redirector dicts pointing to the embedded
1064
+ > CIDFontType2 chain — no more unembedded `Helvetica` references
1065
+ > (ISO 19005-1 §6.3.4 / ISO 19005-2 §6.2.11.4.1). To produce strict
1066
+ > PDF/A:
1067
+ >
1068
+ > ```ts
1069
+ > import { registerFont } from 'pdfnative';
1070
+ > registerFont('latin', () => import('pdfnative/fonts/noto-sans-data.js'));
1071
+ > ```
1072
+ >
1073
+ > Run `npm run validate:pdfa` locally (with veraPDF installed, see
1074
+ > [docs/guides/pdfa.html](docs/guides/pdfa.html)) to verify against
1075
+ > the reference validator. CI runs veraPDF as a blocking check.
1024
1076
 
1025
1077
  ### PDF Encryption — Implemented ✅
1026
1078