@boxpdf/html-writer 0.1.19 → 0.1.22

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
@@ -23,6 +23,23 @@ try {
23
23
  }
24
24
  ```
25
25
 
26
+ For LLM and text-oriented workflows, stream Markdown from the same semantic
27
+ document inference without generating HTML first:
28
+
29
+ ```ts
30
+ import { writeMarkdownDocument } from "@boxpdf/html-writer";
31
+
32
+ await writeMarkdownDocument(pdf.pages(), write, {
33
+ semanticLookaheadPages: 4,
34
+ imageOptions: "excluded",
35
+ });
36
+ ```
37
+
38
+ Markdown preserves inferred headings, emphasis, lists, tables, preformatted
39
+ blocks, and grouped content. It uses the same bounded lookahead, table merging,
40
+ repeated-furniture suppression, image options, and semantic statistics as
41
+ semantic HTML.
42
+
26
43
  The default `visual` profile preserves page dimensions and text coordinates for
27
44
  display presentation. The `semantic` profile uses inferred reading order,
28
45
  lines, nesting, and tables to produce reflowable HTML. The visual model comes
@@ -50,10 +67,30 @@ The reported statistics also include processed pages, peak buffered lines, and
50
67
  suppressed furniture. Page-level `pageToHtml()` remains available when no
51
68
  cross-page inference is wanted.
52
69
 
70
+ Semantic HTML excludes images by default, which keeps extraction output small
71
+ for text and LLM workflows. Choose how raster and vector media are represented
72
+ with `imageOptions`:
73
+
74
+ ```ts
75
+ await writeHtmlDocument(pdf.pages(), write, {
76
+ profile: "semantic",
77
+ imageOptions: "references",
78
+ async onImage({ name, mimeType, data }) {
79
+ await saveAsset(name, mimeType, data);
80
+ },
81
+ });
82
+ ```
83
+
84
+ `"embedded"` writes raster data URIs and inline SVG into the HTML.
85
+ `"references"` writes deterministic asset names into the HTML and passes each
86
+ asset to the awaited `onImage` callback, so callers can store it without
87
+ accumulating a document's images in memory. `"excluded"` omits media. Visual
88
+ HTML defaults to `"embedded"`; semantic HTML defaults to `"excluded"`.
89
+ Referenced semantic assets include both raster images and SVG vector media.
90
+
53
91
  The legacy `layout: "positioned" | "flow"` option remains as an alias for
54
- `profile: "visual" | "semantic"`. The current visual output surface excludes
55
- images, vector graphics, and exact font reproduction; the PDFium parity report
56
- tracks progress toward complete display presentation.
92
+ `profile: "visual" | "semantic"`. The PDFium parity report tracks progress
93
+ toward complete display presentation.
57
94
 
58
95
  The callback is awaited for every chunk, so a file stream, HTTP response, or
59
96
  Web `WritableStream` can apply backpressure. The caller owns and closes the PDF
@@ -69,11 +106,11 @@ Poppler's `pdftohtml -c -hidden -noframes -zoom 1` output. Poppler serves as an
69
106
  independent test oracle. The writer's memory contract covers the reader and
70
107
  HTML serialization.
71
108
 
72
- `pnpm poppler:report` runs the visual writer over all 62 text fixtures in
73
- the pinned PDF.js corpus. The checked-in baseline currently records exact text
74
- and geometry agreement on 51 fixtures. The remaining cases are retained in the
75
- denominator; most exercise intentional PDF.js/Poppler differences in RTL text,
76
- font encodings, or malformed Unicode maps. `pnpm poppler:gate` rejects any loss
109
+ `pnpm poppler:report` runs the visual writer over every text fixture in the
110
+ pinned PDF.js corpus. Cases where visual glyph rendering intentionally replaces
111
+ extractable HTML text remain explicit in the baseline, alongside known
112
+ PDF.js/Poppler differences in RTL text, font encodings, and malformed Unicode
113
+ maps. `pnpm poppler:gate` rejects any loss
77
114
  from the known-good pass set and runs in CI.
78
115
 
79
116
  The writer retains the reader's logical Unicode order. RTL spans and flow lines