@shuji-bonji/pdf-reader-mcp 0.8.0 → 0.9.1

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.ja.md +37 -7
  3. package/README.md +41 -9
  4. package/dist/services/actual-text-service.d.ts +99 -0
  5. package/dist/services/actual-text-service.d.ts.map +1 -0
  6. package/dist/services/actual-text-service.js +196 -0
  7. package/dist/services/actual-text-service.js.map +1 -0
  8. package/dist/services/content-stream-service.d.ts +70 -0
  9. package/dist/services/content-stream-service.d.ts.map +1 -0
  10. package/dist/services/content-stream-service.js +524 -0
  11. package/dist/services/content-stream-service.js.map +1 -0
  12. package/dist/services/pdfjs-service.d.ts +69 -24
  13. package/dist/services/pdfjs-service.d.ts.map +1 -1
  14. package/dist/services/pdfjs-service.js +163 -177
  15. package/dist/services/pdfjs-service.js.map +1 -1
  16. package/dist/services/struct-tree-service.d.ts +21 -62
  17. package/dist/services/struct-tree-service.d.ts.map +1 -1
  18. package/dist/services/struct-tree-service.js +132 -132
  19. package/dist/services/struct-tree-service.js.map +1 -1
  20. package/dist/services/struct-tree-walker.d.ts +93 -0
  21. package/dist/services/struct-tree-walker.d.ts.map +1 -0
  22. package/dist/services/struct-tree-walker.js +177 -0
  23. package/dist/services/struct-tree-walker.js.map +1 -0
  24. package/dist/tools/tier1/read-text.d.ts.map +1 -1
  25. package/dist/tools/tier1/read-text.js +5 -1
  26. package/dist/tools/tier1/read-text.js.map +1 -1
  27. package/dist/tools/tier1/search-text.d.ts.map +1 -1
  28. package/dist/tools/tier1/search-text.js +22 -1
  29. package/dist/tools/tier1/search-text.js.map +1 -1
  30. package/dist/tools/tier2/extract-tables.d.ts.map +1 -1
  31. package/dist/tools/tier2/extract-tables.js +15 -9
  32. package/dist/tools/tier2/extract-tables.js.map +1 -1
  33. package/dist/types.d.ts +17 -3
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/utils/formatter.d.ts +12 -0
  36. package/dist/utils/formatter.d.ts.map +1 -1
  37. package/dist/utils/formatter.js +49 -3
  38. package/dist/utils/formatter.js.map +1 -1
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,100 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.9.1] - 2026-07-20
9
+
10
+ ### Fixed
11
+
12
+ - **🔴 `read_text` / `search_text` が `/ActualText` を解決するように**
13
+ ([#18](https://github.com/shuji-bonji/pdf-reader-mcp/issues/18))。0.9.0 は #15 を「明示」で閉じており、
14
+ **同一サーバ内で「この PDF に Difficult と書いてあるか」の答えが Yes/No に割れた**ままでした
15
+ (`extract_structured_text` は `Difficult`、`search_text("Difficult")` は 0 件)。本リリースで
16
+ ISO 32000-2 §14.9.4 が定める**置換テキストの 2 経路をどちらも解決**します。
17
+ - **経路 1 — 構造要素の `/ActualText`**(PDF 1.4)。`StructTreeRoot` を走査し、要素が持つ
18
+ マーク付きコンテンツ参照(`/Pg` + `/MCID`)を pdfjs の MCID に対応づけて置換します。
19
+ 要素に `/ActualText` があればその**サブツリー全体**が置換対象なので、内側の `/ActualText` には
20
+ 降りません(§14.9.4「a character substitution for the content **enclosed by**…」)。
21
+ - **経路 2 — マーク付きコンテンツの `/ActualText`**(PDF 1.5、`Span` の property list)。
22
+ pdfjs の `getTextContent({ includeMarkedContent: true })` は property list を捨てて `/MCID` しか
23
+ 渡さないため、**コンテンツストリームを自前で走査**します(新規 `content-stream-service`)。
24
+ この経路は**タグ無し文書にも現れる**ので、構造木経由では原理的に届きません。
25
+ - **位置合わせは出現順インデックス**です。スキャナは `BMC`/`BDC`/`EMC` の順序だけを記録し、
26
+ pdfjs が出すマーカーと 1:1 で対応させます(座標マッチ不要)。**数が食い違ったページは
27
+ 経路 2 を丸ごと諦めます** — 生グリフを返すのは 0.9.0 までの既知の挙動ですが、
28
+ ズレた位置に置換テキストを差し込むのは新しい壊れ方なので。`/Contents` 配列の結合と
29
+ Form XObject の `Do` 追跡は pdfjs と同じ順序に揃えてあります。
30
+ - **R-14.9.4-3 に対応**: 「consecutive な `/ActualText` の間に語区切りを入れてはならない」。
31
+ 行グルーピングより優先されます(条文の EXAMPLE がまさに行跨ぎのハイフネーションのため)。
32
+ - `search_text` の `note` は #15 の一律警告から、**実際に解決できなかったページ**を名指しし、
33
+ さらに**理由**(`encrypted` / `unaligned`)を伝えるものに変わりました。暗号化が理由のときは
34
+ 「他のツールでも解決できない」と言い切ります(`extract_structured_text` も pdf-lib 経由なので)。
35
+ 内部 API では `searchText()` が `unresolvedReason` を返します。
36
+ - 副次的な変更: 空文字の EOL 項目が行頭に余分な空白を生んでいたのを止めました
37
+ (`"…\n This is…"` → `"…\nThis is…"`)。
38
+ - **暗号化 PDF では両経路を無効化**します。§7.6.2 が暗号化するのは**文字列とストリームだけ**なので、
39
+ 構造木は普通に歩けてしまう一方、そこに入っている文字列は暗号文です。reader は pdf-lib を
40
+ `ignoreEncryption` で読む(=復号はしない)ため、`/ActualText` として返るのは RC4 の出力でした。
41
+ 実測: `PDF32000_2008.pdf`(オーナーパスワードのみ・ビューアでは普通に開く)は
42
+ **18026 件**の `/ActualText` を持ち、その全てが `&)ð` のようなバイト列。#18 はこれを
43
+ **本文の置換に使う**ので、1 ページ目の表題が
44
+ `Document management&)ð — 6±o Portable document format` になっていました。
45
+ `doc.isEncrypted` で `struct-tree-walker` の文字列読み取りと
46
+ コンテンツストリーム走査の両方を止めます(`extract_structured_text` /
47
+ `extract_tables` の `/ActualText`・`/Alt`・`/Lang` にも同じ穴があり、あわせて塞がります)。
48
+ - 新フィクスチャ `actual-text-span.pdf`(**タグ無し**・§14.9.4 EXAMPLE の「Druk-/ker → Drucker」と
49
+ 連続 ActualText の「Bäcke-/rei → Bäckerei」)と `encrypted-actualtext.pdf`
50
+ (RC4 40-bit・`/ActualText` が暗号文。pdf-lib では作れないので手書き)、
51
+ ST-8・ST-10〜ST-15、`tests/tier1/actual-text-service.test.ts` を追加。
52
+ - `searchText()` の戻り値が `SearchMatch[]` → `{ matches, unresolvedPages, unresolvedReason }`
53
+ になりました(内部 API)。
54
+ - 構造木の走査部分を `struct-tree-walker.ts` に分離(pdfjs に依存しない部分だけを切り出し、
55
+ `actual-text-service` から循環インポートなしに使うため)。`struct-tree-service` は再エクスポートします。
56
+
57
+ ## [0.9.0] - 2026-07-19
58
+
59
+ > spec ⇄ reader 相互チェック(2026-07-19。`Document-Note/mcps/PDFfamily/reviews/` の 2 レポート)で
60
+ > 発見された 4 件(Issue #14〜#17)の一括対応。
61
+
62
+ ### Changed
63
+
64
+ - **🔴 `extract_tables` を StructTreeRoot 走査に載せ替え** ([#14](https://github.com/shuji-bonji/pdf-reader-mcp/issues/14)・破壊的変更)。
65
+ 従来はページごとの `page.getStructTree()` を併合していたため、**ページを跨ぐ Table 要素が
66
+ ページ単位の断片に分裂**し、Figure しか載っていないページには「ヘッダ 1 セル・中身空」の
67
+ **幻テーブル**が生まれていました(ISO 32000-2 EC3 の pp.383–388 で実測: 実体 4 表に対し 8 表を報告。
68
+ 0.8.0 の C-1 で `inspect_tags` から取り除いたのと同じ failure mode で、本ツールの主要ユースケース
69
+ = 新旧対照表はほぼ確実にページを跨ぎます)。M-8 と同じ walker(`struct-tree-service`)に載せ替え、
70
+ 跨ぎ Table は `pages: [383, 384, 385, 386]` のような **1 つの表**として返します。
71
+ - **出力が変わります**: `tables[].page`(数値)→ **`tables[].pages`(配列)**。`index` はページ内
72
+ 連番から**文書全体の論理順連番**に変更(`pages` フィルタに関わらず同じ表は同じ index)。
73
+ Markdown の見出しも `## Page N — Table M` → `## Table M — Page(s) …`。
74
+ - 副次的な改善: セルの `/ActualText` を解決するようになりました(§14.9.4。旧経路は生グリフ)。
75
+ - 実測: ISO PDF pp.383–388 が 8 表 → **5 表**(幻 3 つが消え、Table 126 の跨ぎ断片が 1 表に)。
76
+ - 回帰フィクスチャ `spanning-table.pdf`(ページ跨ぎ Table 単体)と ET-6〜ET-8 を追加。
77
+ `create-e2e-fixtures.ts` は引数で単一フィクスチャのみ生成できるようにしました
78
+ (既存フィクスチャの再生成・再コミットを避けるため)。
79
+
80
+ ### Fixed
81
+
82
+ - **`search_text` / `read_text` の ActualText 非対応を明示し、空振り時に案内を返すように**
83
+ ([#15](https://github.com/shuji-bonji/pdf-reader-mcp/issues/15))。両ツールは生グリフを見るため、
84
+ `/ActualText` 置換(§14.9.4「shall be used as a replacement」)で運ばれる語は**ビューアに見えていても
85
+ ヒットしません**(`extract_structured_text` は「Difficult」を返すのに `search_text("Difficult")` は
86
+ 0 件 — 同一サーバ内で答えが割れていました)。グリフ置換の解決は pdfjs の textContent が
87
+ ActualText を公開しないため本リリースでは行わず、(1) 両 description に生グリフである旨と
88
+ `extract_structured_text` への案内を明記し、(2) **タグ付き文書で 0 件のとき `note` を返す**ように
89
+ しました(「無い」と「見えない」の区別を呼び出し側に渡す)。`isTaggedPdf()` を追加。
90
+ read_text の description が M-8 登場前のまま `extract_tables` しか案内していなかった点も更新
91
+ (Issue #15 同梱の R-6)。
92
+ - **`extract_structured_text` の Markdown で表セル内の `|` を GFM エスケープ**
93
+ ([#16](https://github.com/shuji-bonji/pdf-reader-mcp/issues/16))。ISO PDF Table 126 の `−|𝑦|` などで
94
+ 列が壊れていました。`extract_tables` は抽出時にエスケープ済みで、同一リポジトリ内で挙動が
95
+ 割れていたもの。M-8 側は**表示時のみ**エスケープし、JSON は生テキストのまま(層の分離を保つ)。
96
+ - **`extract_structured_text` の Markdown の `pages` 表示を連続範囲に圧縮**
97
+ ([#17](https://github.com/shuji-bonji/pdf-reader-mcp/issues/17))。`join('–')` で全列挙していたため、
98
+ 文書全域に跨る `Document` 要素が 1000 個超のページ番号を並べ、応答が数十 KB 膨張して
99
+ truncate を圧迫していました。`1–3, 7, 9–10` 形式に変更(表示のみ。JSON の配列は不変)。
100
+ 副次効果として、構造木に載らないページが欠番として一目で見えます。
101
+
8
102
  ## [0.8.0] - 2026-07-18
9
103
 
10
104
  ### Added
package/README.ja.md CHANGED
@@ -22,7 +22,7 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
22
22
 
23
23
  ## 機能
24
24
 
25
- **16 ツール** を 3 層構成で提供します。
25
+ **17 ツール** を 3 層構成で提供します。
26
26
 
27
27
  ### Tier 1: 基本機能
28
28
 
@@ -30,8 +30,8 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
30
30
  | ---------------- | ----------------------------------------------------- |
31
31
  | `get_page_count` | ページ数の軽量取得 |
32
32
  | `get_metadata` | メタデータ抽出(タイトル、著者、PDF版、タグ有無等) |
33
- | `read_text` | テキスト抽出(Y座標ベースの読み順保持。`split_columns: 2 \| 3` で **タグなし** 多カラム PDF、`compact_whitespace` で 帳票 の U+3000 連続空白を畳み込み) |
34
- | `search_text` | 全文検索(前後コンテキスト付き) |
33
+ | `read_text` | テキスト抽出(Y座標ベースの読み順保持。`split_columns: 2 \| 3` で **タグなし** 多カラム PDF、`compact_whitespace` で 帳票 の U+3000 連続空白を畳み込み)。`/ActualText` 置換(§14.9.4。構造要素・`Span` マーク付きコンテンツの両経路)を解決。**論理順**が要るタグ付き PDF の本文は `extract_structured_text` を推奨 |
34
+ | `search_text` | 全文検索(前後コンテキスト付き)。`read_text` と同じテキスト(`/ActualText` 解決済み)を検索するため、ヒット=読み手に見えている語(位置合わせできなかったページがあれば `note` で名指し) |
35
35
  | `read_images` | 画像抽出(base64、メタデータ付き) |
36
36
  | `read_url` | URLからリモートPDFを取得して処理 |
37
37
  | `summarize` | 全体概要レポート(メタデータ + テキスト + 画像数) |
@@ -45,14 +45,15 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
45
45
  | `inspect_fonts` | フォント一覧(埋め込み/サブセット/Type判定) |
46
46
  | `inspect_annotations` | 注釈一覧(タイプ別分類) |
47
47
  | `inspect_signatures` | 電子署名フィールドの構造解析 |
48
- | `extract_tables` | Tagged PDF の `<Table>` を Markdown テーブルとして抽出 |
48
+ | `extract_structured_text` | Tagged PDF のテキストを**論理コンテンツ順**(ISO 32000-2 §14.8.2.5)で、構造タイプ(`H1` / `P` / `Table` …)のラベル付きで抽出。`/ActualText` を解決し、`/Alt`・箇条書き記号は本文と分離、ページ跨ぎ要素は 1 要素のまま |
49
+ | `extract_tables` | Tagged PDF の `<Table>` を Markdown テーブルとして抽出。ページを跨ぐ表は 1 つの表(`pages` 配列)として返す |
49
50
 
50
51
  ### Tier 3: 検証・分析
51
52
 
52
53
  | ツール | 説明 |
53
54
  | ------------------- | ---------------------------------------------- |
54
- | `validate_tagged` | PDF/UA タグ構造の検証(8項目チェック) |
55
- | `validate_metadata` | メタデータの仕様適合チェック(10項目チェック) |
55
+ | `validate_tagged` | **非推奨** — ISO 規格への合否判定は [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) の `validate_conformance`(`flavour: "pdfua-1"`)へ移管。次のメジャーまで残置 |
56
+ | `validate_metadata` | **非推奨** — 移管先は上と同じ。次のメジャーまで残置 |
56
57
  | `compare_structure` | 2つのPDFの構造差分比較(プロパティ+フォント) |
57
58
 
58
59
  ## インストール
@@ -161,6 +162,32 @@ compare_structure({
161
162
  | Tagged | true | true | ✅ |
162
163
  ```
163
164
 
165
+ ### 論理コンテンツ順のテキスト抽出(Tagged PDF)
166
+
167
+ ```
168
+ extract_structured_text({ file_path: "/path/to/report.pdf", pages: "1-2" })
169
+ → # Structured Text
170
+ - **Tagged**: Yes / **Language**: en-US / **Elements**: 7
171
+
172
+ ## Logical Content Order
173
+
174
+ - **Document** (pages 1–2)
175
+ - **H1** (page 1) — Quarterly Report
176
+ - **P** (pages 1–2) — This paragraph begins on page one and continues on page two.
177
+ - **Table** (page 1)
178
+ | Item | Amount |
179
+ |---|---|
180
+ | Sales | 100 |
181
+ - **Figure** (page 2) — *alt:* A bar chart of sales
182
+ ```
183
+
184
+ 「H1 の文字列は何か」に答えるツールです(座標順でフラットな `read_text` には
185
+ 答えられません)。順序は構造木の深さ優先走査(ISO 32000-2 §14.8.2.5)。
186
+ `/ActualText` はグリフを置換し(§14.9.4)、`/Alt` は本文に混ぜず(§14.9.3)、
187
+ 箇条書き記号は `label` に分離、ページ跨ぎ要素は 1 要素のまま返します。
188
+ `roles: ["H1", "H2"]` でアウトラインだけの取得も可能。タグ無し文書は座標から
189
+ 推測せず `isTagged: false` と理由を返します。
190
+
164
191
  ### Tagged PDF からテーブル抽出
165
192
 
166
193
  ```
@@ -168,13 +195,16 @@ extract_tables({ file_path: "/path/to/kaisei-tsutatsu.pdf", pages: "1" })
168
195
  → # Extracted Tables
169
196
  - **Tagged**: Yes / **Pages Scanned**: 1 / **Tables Found**: 1
170
197
 
171
- ## Page 1 — Table 1
198
+ ## Table 1 — Page 1
172
199
 
173
200
  | 改正後 | 改正前 |
174
201
  | --- | --- |
175
202
  | …第2条第 16 項《定義》… | …第2条第 15 項《定義》… |
176
203
  ```
177
204
 
205
+ ページを跨いで続く表は **1 つの表**として返します — `pages` は配列で、
206
+ 見出しも `## Table 3 — Pages 5–7` のようになります。要求した `pages` 範囲に
207
+ かかる表は丸ごと返り、セルの `/ActualText` 置換も解決します。
178
208
  タグ無し PDF では空結果と note を返し、下記の column-aware 抽出への
179
209
  フォールバックを推奨します。
180
210
 
package/README.md CHANGED
@@ -22,7 +22,7 @@ While typical PDF MCP servers are thin wrappers for text extraction, this projec
22
22
 
23
23
  ## Features
24
24
 
25
- **16 tools** organized into three tiers:
25
+ **17 tools** organized into three tiers:
26
26
 
27
27
  ### Tier 1: Basic Operations
28
28
 
@@ -30,8 +30,8 @@ While typical PDF MCP servers are thin wrappers for text extraction, this projec
30
30
  | ---------------- | -------------------------------------------------------- |
31
31
  | `get_page_count` | Lightweight page count retrieval |
32
32
  | `get_metadata` | Full metadata extraction (title, author, PDF version...) |
33
- | `read_text` | Text extraction with Y-coordinate reading order (opt-in `split_columns: 2 \| 3` for untagged multi-column PDFs, `compact_whitespace` for Japanese forms) |
34
- | `search_text` | Full-text search with surrounding context |
33
+ | `read_text` | Text extraction with Y-coordinate reading order (opt-in `split_columns: 2 \| 3` for untagged multi-column PDFs, `compact_whitespace` for Japanese forms). Resolves `/ActualText` replacements (§14.9.4, both the structure-element and the `Span` marked-content path). For **logical** order in tagged PDFs, prefer `extract_structured_text` |
34
+ | `search_text` | Full-text search with surrounding context. Searches the same text `read_text` returns, `/ActualText` included, so a hit means what a reader sees (a `note` names any page whose marked content could not be aligned) |
35
35
  | `read_images` | Image extraction as base64 with metadata |
36
36
  | `read_url` | Fetch and process remote PDFs from URLs |
37
37
  | `summarize` | Quick overview report (metadata + text + image count) |
@@ -45,14 +45,15 @@ While typical PDF MCP servers are thin wrappers for text extraction, this projec
45
45
  | `inspect_fonts` | Font inventory (embedded/subset/type detection) |
46
46
  | `inspect_annotations` | Annotation listing (categorized by subtype) |
47
47
  | `inspect_signatures` | Digital signature field structure analysis |
48
- | `extract_tables` | Tagged PDF `<Table>` subtree → Markdown table (preserves columns) |
48
+ | `extract_structured_text` | Tagged PDF text in **logical content order** (ISO 32000-2 §14.8.2.5), each piece labelled with its structure type (`H1` / `P` / `Table` …). Resolves `/ActualText`, separates `/Alt` and list labels, keeps page-spanning elements whole |
49
+ | `extract_tables` | Tagged PDF `<Table>` subtree → Markdown table (preserves columns). A table continuing across a page break is ONE table (`pages` array) |
49
50
 
50
51
  ### Tier 3: Validation & Analysis
51
52
 
52
53
  | Tool | Description |
53
54
  | ------------------- | ---------------------------------------------------- |
54
- | `validate_tagged` | PDF/UA tag structure validation (8 checks) |
55
- | `validate_metadata` | Metadata conformance checking (10 checks) |
55
+ | `validate_tagged` | **Deprecated** — PDF/UA pass/fail belongs to [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) `validate_conformance` (`flavour: "pdfua-1"`). Kept until the next major |
56
+ | `validate_metadata` | **Deprecated** — same migration path as above. Kept until the next major |
56
57
  | `compare_structure` | Structural diff between two PDFs (properties + fonts)|
57
58
 
58
59
  ## Installation
@@ -162,6 +163,33 @@ compare_structure({
162
163
  | Tagged | true | true | ✅ |
163
164
  ```
164
165
 
166
+ ### Extract Structured Text (Tagged PDF, logical order)
167
+
168
+ ```
169
+ extract_structured_text({ file_path: "/path/to/report.pdf", pages: "1-2" })
170
+ → # Structured Text
171
+ - **Tagged**: Yes / **Language**: en-US / **Elements**: 7
172
+
173
+ ## Logical Content Order
174
+
175
+ - **Document** (pages 1–2)
176
+ - **H1** (page 1) — Quarterly Report
177
+ - **P** (pages 1–2) — This paragraph begins on page one and continues on page two.
178
+ - **Table** (page 1)
179
+ | Item | Amount |
180
+ |---|---|
181
+ | Sales | 100 |
182
+ - **Figure** (page 2) — *alt:* A bar chart of sales
183
+ ```
184
+
185
+ This answers "what is the text of the H1?" — which `read_text` (flat,
186
+ coordinate order) cannot. Order is a depth-first traversal of the structure
187
+ tree (ISO 32000-2 §14.8.2.5). `/ActualText` replaces the glyphs (§14.9.4),
188
+ `/Alt` stays out of the body text (§14.9.3), list labels are reported
189
+ separately, and an element spanning a page break stays ONE element. Use
190
+ `roles: ["H1", "H2"]` to pull an outline. Untagged PDFs return
191
+ `isTagged: false` with a reason — nothing is guessed from coordinates.
192
+
165
193
  ### Extract Tables (Tagged PDF)
166
194
 
167
195
  ```
@@ -169,15 +197,19 @@ extract_tables({ file_path: "/path/to/kaisei-tsutatsu.pdf", pages: "1" })
169
197
  → # Extracted Tables
170
198
  - **Tagged**: Yes / **Pages Scanned**: 1 / **Tables Found**: 1
171
199
 
172
- ## Page 1 — Table 1
200
+ ## Table 1 — Page 1
173
201
 
174
202
  | 改正後 | 改正前 |
175
203
  | --- | --- |
176
204
  | …第2条第 16 項《定義》… | …第2条第 15 項《定義》… |
177
205
  ```
178
206
 
179
- Untagged PDFs return an empty result with a `note` recommending the
180
- column-aware fallback below.
207
+ A table that continues across a page break is reported as ONE table —
208
+ `pages` is an array (e.g. `## Table 3 — Pages 5–7`), and a table touching
209
+ the requested `pages` range is returned whole. Cell text honours
210
+ `/ActualText` replacements (as do `read_text` and `search_text` since #18).
211
+ Untagged PDFs return an empty result with a
212
+ `note` recommending the column-aware fallback below.
181
213
 
182
214
  ### Read Untagged Multi-Column PDF
183
215
 
@@ -0,0 +1,99 @@
1
+ /**
2
+ * `/ActualText` resolution for coordinate-order text extraction (#18).
3
+ *
4
+ * ISO 32000-2 §14.9.4:
5
+ *
6
+ * > The ActualText value **shall** be used as a **replacement, not a
7
+ * > description**, for the content, providing text that is equivalent to what a
8
+ * > person would see when viewing the content. The value of ActualText is a
9
+ * > character substitution for the content enclosed by the structure element or
10
+ * > marked-content sequence.
11
+ *
12
+ * A text-extracting tool that ignores it therefore returns text that is *not*
13
+ * equivalent to what a person sees — which is what #15 documented and #18 fixes.
14
+ *
15
+ * Replacement text lives in two places, and this module resolves both:
16
+ *
17
+ * 1. **structure element** `/ActualText` (PDF 1.4) — found by walking
18
+ * `StructTreeRoot` and mapping the element's marked-content references
19
+ * (`/Pg` + `/MCID`) onto the MCIDs pdfjs reports;
20
+ * 2. **marked-content sequence** `/ActualText` (PDF 1.5, a `Span` property
21
+ * list) — found by scanning the content stream, because pdfjs drops
22
+ * property lists (see `content-stream-service`). This one occurs in
23
+ * **untagged** documents too, so path 1 alone cannot reach it.
24
+ *
25
+ * ## How the two streams are aligned
26
+ *
27
+ * The scanner records `BMC` / `BDC` / `EMC` in content-stream order; pdfjs emits
28
+ * one marker per such operator, in the same order. So the *n*-th begin marker
29
+ * from pdfjs is the *n*-th begin event from the scan — no coordinate matching.
30
+ * When the two disagree on how many there are, the alignment is unknown and
31
+ * path 2 is abandoned for that page (path 1 is unaffected: it keys off MCIDs
32
+ * pdfjs supplies itself). Returning raw glyphs is the old, documented
33
+ * behaviour; attaching replacement text to the wrong glyphs would be new damage.
34
+ */
35
+ import type { PDFDocument as PdfLibDocument } from 'pdf-lib';
36
+ /** A pdfjs text item, reduced to what reading order and joining need. */
37
+ export interface PositionedText {
38
+ str: string;
39
+ /** `[a, b, c, d, e, f]` — `e`/`f` are the X/Y of the item's origin. */
40
+ transform: number[];
41
+ width: number;
42
+ height: number;
43
+ /**
44
+ * Set when this item is `/ActualText` standing in for the glyphs it replaced.
45
+ * `adjacentToPrevious` records that the sequence it came from directly
46
+ * followed another one that also had `/ActualText`, which is the condition
47
+ * §14.9.4's "no word break" requirement turns on — and which is no longer
48
+ * recoverable once the items have been sorted into reading order.
49
+ */
50
+ replacement?: {
51
+ adjacentToPrevious: boolean;
52
+ };
53
+ }
54
+ /** A pdfjs `getTextContent({ includeMarkedContent: true })` item. */
55
+ interface RawItem {
56
+ type?: string;
57
+ id?: string | null;
58
+ tag?: string;
59
+ str?: string;
60
+ width?: number;
61
+ height?: number;
62
+ transform?: number[];
63
+ hasEOL?: boolean;
64
+ }
65
+ /**
66
+ * Map every MCID that a structure element with `/ActualText` owns to that text.
67
+ *
68
+ * The element's replacement covers everything it encloses, descendants
69
+ * included, so the walk stops descending once it finds an `/ActualText`: an
70
+ * inner one would be substituting for content the outer one has already
71
+ * replaced. Keyed by pdfjs's marked-content id (`p7R_mc3`) so no page bookkeeping
72
+ * is needed at lookup time.
73
+ */
74
+ export declare function buildStructActualTextMap(doc: PdfLibDocument): Map<string, string>;
75
+ /**
76
+ * Fold a page's pdfjs items into positioned text, substituting `/ActualText`.
77
+ *
78
+ * A replaced region collapses to a single item carrying the replacement string,
79
+ * placed at the first glyph it replaced and as wide as the region — so the
80
+ * caller's Y/X sort still puts it where the reader sees it. A region containing
81
+ * no glyphs at all (replacement text over a Figure, say) inherits the previous
82
+ * item's position, which is the only ordering information available.
83
+ *
84
+ * @param structActualText MCID → replacement, from `buildStructActualTextMap`.
85
+ * @param spanActualText Begin-marker index → replacement, from the content
86
+ * stream scan. Undefined when alignment is unknown.
87
+ */
88
+ export declare function foldActualText(rawItems: RawItem[], structActualText: ReadonlyMap<string, string>, spanActualText: ReadonlyMap<number, string> | undefined): PositionedText[];
89
+ /**
90
+ * Build the `Span`-level replacement map for one page, or `undefined` when the
91
+ * content stream and pdfjs disagree about how many marked-content sequences the
92
+ * page has (see the module comment for why that is fatal to the alignment).
93
+ *
94
+ * @param pageIndex 0-based.
95
+ * @param pdfjsBeginCount How many begin markers pdfjs reported for the page.
96
+ */
97
+ export declare function buildSpanActualTextMap(doc: PdfLibDocument, pageIndex: number, pdfjsBeginCount: number): Map<number, string> | undefined;
98
+ export {};
99
+ //# sourceMappingURL=actual-text-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actual-text-service.d.ts","sourceRoot":"","sources":["../../src/services/actual-text-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,SAAS,CAAC;AAK7D,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,WAAW,CAAC,EAAE;QAAE,kBAAkB,EAAE,OAAO,CAAA;KAAE,CAAC;CAC/C;AAED,qEAAqE;AACrE,UAAU,OAAO;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBjF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,OAAO,EAAE,EACnB,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7C,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GACtD,cAAc,EAAE,CA0GlB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,cAAc,EACnB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAYjC"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * `/ActualText` resolution for coordinate-order text extraction (#18).
3
+ *
4
+ * ISO 32000-2 §14.9.4:
5
+ *
6
+ * > The ActualText value **shall** be used as a **replacement, not a
7
+ * > description**, for the content, providing text that is equivalent to what a
8
+ * > person would see when viewing the content. The value of ActualText is a
9
+ * > character substitution for the content enclosed by the structure element or
10
+ * > marked-content sequence.
11
+ *
12
+ * A text-extracting tool that ignores it therefore returns text that is *not*
13
+ * equivalent to what a person sees — which is what #15 documented and #18 fixes.
14
+ *
15
+ * Replacement text lives in two places, and this module resolves both:
16
+ *
17
+ * 1. **structure element** `/ActualText` (PDF 1.4) — found by walking
18
+ * `StructTreeRoot` and mapping the element's marked-content references
19
+ * (`/Pg` + `/MCID`) onto the MCIDs pdfjs reports;
20
+ * 2. **marked-content sequence** `/ActualText` (PDF 1.5, a `Span` property
21
+ * list) — found by scanning the content stream, because pdfjs drops
22
+ * property lists (see `content-stream-service`). This one occurs in
23
+ * **untagged** documents too, so path 1 alone cannot reach it.
24
+ *
25
+ * ## How the two streams are aligned
26
+ *
27
+ * The scanner records `BMC` / `BDC` / `EMC` in content-stream order; pdfjs emits
28
+ * one marker per such operator, in the same order. So the *n*-th begin marker
29
+ * from pdfjs is the *n*-th begin event from the scan — no coordinate matching.
30
+ * When the two disagree on how many there are, the alignment is unknown and
31
+ * path 2 is abandoned for that page (path 1 is unaffected: it keys off MCIDs
32
+ * pdfjs supplies itself). Returning raw glyphs is the old, documented
33
+ * behaviour; attaching replacement text to the wrong glyphs would be new damage.
34
+ */
35
+ import { scanPageMarkedContent } from './content-stream-service.js';
36
+ import { collectContentRefs, walkStructTree } from './struct-tree-walker.js';
37
+ /**
38
+ * Map every MCID that a structure element with `/ActualText` owns to that text.
39
+ *
40
+ * The element's replacement covers everything it encloses, descendants
41
+ * included, so the walk stops descending once it finds an `/ActualText`: an
42
+ * inner one would be substituting for content the outer one has already
43
+ * replaced. Keyed by pdfjs's marked-content id (`p7R_mc3`) so no page bookkeeping
44
+ * is needed at lookup time.
45
+ */
46
+ export function buildStructActualTextMap(doc) {
47
+ const map = new Map();
48
+ const roots = walkStructTree(doc);
49
+ if (!roots)
50
+ return map;
51
+ const visit = (element) => {
52
+ if (element.actualText !== null) {
53
+ const refs = collectContentRefs(element);
54
+ for (const ref of refs) {
55
+ map.set(`p${ref.pageObjNum}R_mc${ref.mcid}`, element.actualText);
56
+ }
57
+ // Do not descend: the whole subtree is what this text replaces.
58
+ return;
59
+ }
60
+ for (const child of element.children)
61
+ visit(child);
62
+ };
63
+ for (const root of roots)
64
+ visit(root);
65
+ return map;
66
+ }
67
+ /**
68
+ * Fold a page's pdfjs items into positioned text, substituting `/ActualText`.
69
+ *
70
+ * A replaced region collapses to a single item carrying the replacement string,
71
+ * placed at the first glyph it replaced and as wide as the region — so the
72
+ * caller's Y/X sort still puts it where the reader sees it. A region containing
73
+ * no glyphs at all (replacement text over a Figure, say) inherits the previous
74
+ * item's position, which is the only ordering information available.
75
+ *
76
+ * @param structActualText MCID → replacement, from `buildStructActualTextMap`.
77
+ * @param spanActualText Begin-marker index → replacement, from the content
78
+ * stream scan. Undefined when alignment is unknown.
79
+ */
80
+ export function foldActualText(rawItems, structActualText, spanActualText) {
81
+ const out = [];
82
+ /** How many marked-content sequences are currently open. */
83
+ let depth = 0;
84
+ let beginIndex = -1;
85
+ /** The replacement currently being accumulated, if any. */
86
+ let open = null;
87
+ /** True while nothing but the closing of a replacement has been emitted. */
88
+ let lastEmittedWasReplacement = false;
89
+ let sawTextSinceReplacement = true;
90
+ let lastTransform = null;
91
+ let lastHeight = 0;
92
+ const closeOpen = () => {
93
+ if (!open)
94
+ return;
95
+ const transform = open.transform ?? lastTransform ?? [1, 0, 0, 1, 0, 0];
96
+ const width = open.transform ? Math.max(0, open.maxX - open.minX) : 0;
97
+ out.push({
98
+ str: open.text,
99
+ transform,
100
+ width,
101
+ height: open.height || lastHeight,
102
+ replacement: {
103
+ // §14.9.4: "If each of two (or more) consecutive structure or
104
+ // marked-content sequences has an ActualText entry, they shall be
105
+ // treated as if no word break is present between them." Consecutive
106
+ // means nothing came between — hence `sawTextSinceReplacement`.
107
+ adjacentToPrevious: lastEmittedWasReplacement && !sawTextSinceReplacement,
108
+ },
109
+ });
110
+ lastEmittedWasReplacement = true;
111
+ sawTextSinceReplacement = false;
112
+ lastTransform = transform;
113
+ open = null;
114
+ };
115
+ for (const item of rawItems) {
116
+ const type = item.type;
117
+ if (type === 'beginMarkedContent' || type === 'beginMarkedContentProps') {
118
+ beginIndex++;
119
+ // Already inside a replacement? The outer one covers this too: §14.9.4
120
+ // makes ActualText a substitution for everything the sequence encloses.
121
+ const replacementText = open
122
+ ? undefined
123
+ : (spanActualText?.get(beginIndex) ??
124
+ (item.id ? structActualText.get(item.id) : undefined));
125
+ if (replacementText !== undefined) {
126
+ open = { text: replacementText, depth, transform: null, minX: 0, maxX: 0, height: 0 };
127
+ }
128
+ depth++;
129
+ continue;
130
+ }
131
+ if (type === 'endMarkedContent') {
132
+ if (depth > 0)
133
+ depth--;
134
+ if (open && depth === open.depth)
135
+ closeOpen();
136
+ continue;
137
+ }
138
+ if (type !== undefined)
139
+ continue; // an unrecognised marker
140
+ // A text item.
141
+ const transform = item.transform;
142
+ const width = item.width ?? 0;
143
+ const height = item.height ?? 0;
144
+ if (open) {
145
+ // Swallowed by the replacement, but its geometry positions it.
146
+ if (transform) {
147
+ if (!open.transform) {
148
+ open.transform = transform;
149
+ open.minX = transform[4];
150
+ open.maxX = transform[4] + width;
151
+ open.height = height;
152
+ }
153
+ else {
154
+ open.maxX = Math.max(open.maxX, transform[4] + width);
155
+ }
156
+ }
157
+ continue;
158
+ }
159
+ const str = item.hasEOL ? '' : (item.str ?? '');
160
+ if (!transform)
161
+ continue;
162
+ lastTransform = transform;
163
+ if (height)
164
+ lastHeight = height;
165
+ if (!str)
166
+ continue;
167
+ out.push({ str, transform, width, height });
168
+ lastEmittedWasReplacement = false;
169
+ sawTextSinceReplacement = true;
170
+ }
171
+ closeOpen();
172
+ return out;
173
+ }
174
+ /**
175
+ * Build the `Span`-level replacement map for one page, or `undefined` when the
176
+ * content stream and pdfjs disagree about how many marked-content sequences the
177
+ * page has (see the module comment for why that is fatal to the alignment).
178
+ *
179
+ * @param pageIndex 0-based.
180
+ * @param pdfjsBeginCount How many begin markers pdfjs reported for the page.
181
+ */
182
+ export function buildSpanActualTextMap(doc, pageIndex, pdfjsBeginCount) {
183
+ const events = scanPageMarkedContent(doc, pageIndex);
184
+ if (!events)
185
+ return pdfjsBeginCount === 0 ? new Map() : undefined;
186
+ const begins = events.filter((e) => e.kind === 'begin');
187
+ if (begins.length !== pdfjsBeginCount)
188
+ return undefined;
189
+ const map = new Map();
190
+ begins.forEach((event, index) => {
191
+ if (event.actualText !== undefined)
192
+ map.set(index, event.actualText);
193
+ });
194
+ return map;
195
+ }
196
+ //# sourceMappingURL=actual-text-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actual-text-service.js","sourceRoot":"","sources":["../../src/services/actual-text-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAA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