@shuji-bonji/pdf-reader-mcp 0.10.0 → 0.11.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,76 @@ 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.11.1] - 2026-07-27
9
+
10
+ ### Fixed
11
+
12
+ - **`instructions` said this server cannot map objects to coordinates — it has been able to
13
+ since v0.10.0.** The "what it does NOT do" list still read "no object-ID-to-coordinate
14
+ mapping", a line that went stale the moment `locate_objects` shipped and stayed wrong through
15
+ `include_bbox`.
16
+
17
+ This is worse than a stale README. `instructions` is returned from `initialize` and lands in
18
+ the client's system context **before any tool is considered** — which is exactly why the
19
+ family adopted it (PDFfamily specs/06 §2.10). So the one text that is read first was telling
20
+ every client that the two newest features do not exist, suppressing their use.
21
+
22
+ Replaced with what is actually true: `locate_objects` turns an object number into a page and a
23
+ rectangle, `extract_structured_text` with `include_bbox` does the same for a structure element,
24
+ and both answer in the form `add_annotation` takes. The incremental-update line now points at
25
+ `pdf-verify-mcp` `verify_integrity` rather than simply denying the capability exists anywhere.
26
+
27
+ No API change; the published 0.11.0 behaves identically.
28
+
29
+ ## [0.11.0] - 2026-07-27
30
+
31
+ ### Added
32
+
33
+ - **`extract_structured_text` `include_bbox` — structure element → drawing rectangle**
34
+ ([#20](https://github.com/shuji-bonji/pdf-reader-mcp/issues/20), stage 2). Stage 1
35
+ (`locate_objects`) answered "where is object 27?", which is what a revision diff hands over.
36
+ This answers the question the issue was actually filed for: **"where is this paragraph?"** —
37
+ UC-7's step 4, annotating the element a report points at. Measured end to end: a rectangle from
38
+ here goes into `add_annotation` unchanged and comes back out of `inspect_annotations` identical.
39
+
40
+ Added to the existing tool rather than as a nineteenth: it already resolves MCID → text, so the
41
+ extra cost is small, and "which element, what it says, where it is" arrives in one call.
42
+ Off by default; it costs a second pass over every page.
43
+
44
+ Each element gains `boxes` — **one rectangle per page**, because an element that spans pages has
45
+ no single rectangle and merging them would place content on a page it is not on. Rectangles are
46
+ in PDF default user space (origin bottom-left, pt, normalised), unaffected by `/Rotate` or by a
47
+ `/CropBox` whose origin is not (0, 0).
48
+
49
+ **Each names its `basis`, and the two are different kinds of claim:**
50
+
51
+ | basis | what it is |
52
+ | --- | --- |
53
+ | `layout-attribute-bbox` | the `/BBox` the file **declares** (ISO 32000-2 Table 379), read through `/A` and through `/C` + `/ClassMap` (§14.7.6.2). A producer's statement about its own geometry — and the only source for content that has no text |
54
+ | `text-extent` | **measured** from the element's text: the run's baseline origin (§9.4.4's Trm without the device transform) plus the font's ascent/descent. The line box, not the glyph outlines. Images and vector art contribute nothing |
55
+
56
+ **A declaration is reported as-is, and cross-checked.** Files state nonsense: the cover `Figure`
57
+ of *both* Well-Tagged PDF 1.0 and the Tagged PDF Best Practice Guide declares
58
+ `/BBox [-32768 -32768 32767 32767]` — int16 sentinels where a rectangle should be — and
59
+ PDF32000_2008 has 131 of its 545 declarations reaching past the page edge. Since the whole point
60
+ of this output is that it goes straight into `add_annotation`, a declaration is checked against
61
+ the page box (§7.7.3.3) and against the element's own text; either contradiction is reported in
62
+ `boxNote`, with the rectangle still returned unaltered. An element with no rectangle says why
63
+ instead of returning a zero-sized one — a `Figure` holding one image is the usual case
64
+ (§14.8.4.8.5: such an element "should have a BBox attribute").
65
+
66
+ Two things are deliberately not done, because getting them wrong yields a *plausible* rectangle
67
+ rather than an error: text is measured along the **run's own axes**, not the page's (an
68
+ axis-aligned `x + width` puts 20 pt text rotated 45° at x2 = 317.8 instead of 300.9); and an
69
+ element containing **vertical writing** gets no rectangle at all, since pdfjs reports the advance
70
+ in `height` for those and a box covering only the horizontal part would be wrong, not absent.
71
+
72
+ Validated against independent ground truth rather than against fixtures: on *Well-Tagged PDF
73
+ (WTPDF) 1.0*, the 166 `Link` structure elements were compared with the 173 `Link` **annotation**
74
+ `/Rect` values the producer placed for the same links — median IoU **0.972**, none disjoint.
75
+ The invariant "an element that has text has a rectangle" holds over 78,198 elements across
76
+ WTPDF 1.0, the Tagged PDF Best Practice Guide, PDF32000_2008 and ISO 32000-2.
77
+
8
78
  ## [0.10.0] - 2026-07-27
9
79
 
10
80
  ### Added
package/README.ja.md CHANGED
@@ -45,7 +45,7 @@ PDF 内部構造解析に特化した MCP (Model Context Protocol) サーバー
45
45
  | `inspect_fonts` | フォント一覧(埋め込み/サブセット/Type判定) |
46
46
  | `inspect_annotations` | 注釈一覧(タイプ別分類) |
47
47
  | `inspect_signatures` | 電子署名フィールドの構造解析 |
48
- | `extract_structured_text` | Tagged PDF のテキストを**論理コンテンツ順**(ISO 32000-2 §14.8.2.5)で、構造タイプ(`H1` / `P` / `Table` …)のラベル付きで抽出。`/ActualText` を解決し、`/Alt`・箇条書き記号は本文と分離、ページ跨ぎ要素は 1 要素のまま |
48
+ | `extract_structured_text` | Tagged PDF のテキストを**論理コンテンツ順**(ISO 32000-2 §14.8.2.5)で、構造タイプ(`H1` / `P` / `Table` …)のラベル付きで抽出。`/ActualText` を解決し、`/Alt`・箇条書き記号は本文と分離、ページ跨ぎ要素は 1 要素のまま。`include_bbox: true` で**各要素の描画位置**(ページごとに 1 矩形・`add_annotation` がそのまま取る形)を追加 |
49
49
  | `extract_tables` | Tagged PDF の `<Table>` を Markdown テーブルとして抽出。ページを跨ぐ表は 1 つの表(`pages` 配列)として返す |
50
50
  | `locate_objects` | オブジェクト番号 → ページ + 矩形。座標は [pdf-writer-mcp](https://github.com/shuji-bonji/pdf-writer-mcp) の `add_annotation` がそのまま受け取る形(PDF 座標系・左下原点・pt・正規化済み)。[pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) の `verify_integrity` が返す「どのオブジェクトが変わったか」を「どこにあるか」に繋ぐ。各位置は根拠(`basis`)を明示する — 注釈自身の `/Rect` は正確、コンテンツストリームは「ページ全体」までしか言えない |
51
51
 
@@ -189,6 +189,44 @@ extract_structured_text({ file_path: "/path/to/report.pdf", pages: "1-2" })
189
189
  `roles: ["H1", "H2"]` でアウトラインだけの取得も可能。タグ無し文書は座標から
190
190
  推測せず `isTagged: false` と理由を返します。
191
191
 
192
+ #### `include_bbox`: 要素がどこに描かれているか
193
+
194
+ ```
195
+ extract_structured_text({ file_path: "/doc.pdf", roles: ["P"], include_bbox: true })
196
+ → - **P** (page 1) — Measured paragraph
197
+ - *bbox* p1 `(50.0, 297.5, 161.4, 308.6)` — text-extent
198
+ - **Figure** (page 1)
199
+ - *bbox* p1 `(50.0, 150.0, 110.0, 190.0)` — layout-attribute-bbox
200
+ ```
201
+
202
+ 矩形は PDF default user space(左下原点・pt・正規化済み)=
203
+ [pdf-writer-mcp](https://github.com/shuji-bonji/pdf-writer-mcp) `add_annotation`
204
+ がそのまま取る形なので、「この段落に注釈を付ける」の途中で座標系を解釈し直す
205
+ 必要がありません。`/Rotate` や原点がずれた `/CropBox` の影響も受けません。
206
+
207
+ `basis` は主張の強さを表し、2 つは**種類が違う**:
208
+
209
+ | `basis` | 中身 |
210
+ | --- | --- |
211
+ | `layout-attribute-bbox` | ファイルが**宣言**している `/BBox`(ISO 32000-2 Table 379)。`/A` と `/C` + `/ClassMap` の両経路を読む。生成者の申告をそのまま返す=**テキストを持たない内容について言える唯一の根拠** |
212
+ | `text-extent` | 要素が持つテキストからの**実測**。ベースライン原点+フォントの ascent/descent = 行ボックスであってグリフ輪郭ではない。画像・ベクター描画は一切寄与しない |
213
+
214
+ ページを跨ぐ要素は**ページごとに 1 矩形**(1 つに潰すと、その要素が無いページに
215
+ 矩形を置くことになる)。矩形が出せない要素は 0 幅の矩形ではなく `boxNote` で
216
+ 理由を述べます。
217
+
218
+ **宣言はそのまま返した上で、突き合わせます。** ファイルは平気で嘘を書きます —
219
+ *Well-Tagged PDF 1.0* と *Tagged PDF Best Practice Guide* の**両方**の表紙 `Figure` が
220
+ `/BBox [-32768 -32768 32767 32767]`(矩形であるべき場所に int16 のセンチネル)を
221
+ 宣言しており、PDF32000_2008 は 545 件中 131 件がページの外まで届きます。
222
+ この出力は `add_annotation` にそのまま渡される前提なので、宣言は**ページボックス
223
+ (§7.7.3.3)**と**要素自身の本文**の両方に突き合わせ、どちらかと矛盾すれば
224
+ `boxNote` で報告します(矩形自体は改変せずそのまま返します)。
225
+
226
+ **独立した正解との突き合わせ**: *Well-Tagged PDF (WTPDF) 1.0* で、`Link` 構造要素
227
+ 166 件の実測矩形を、生成者が同じリンクに対して置いた `Link` **注釈**の `/Rect`
228
+ 173 件と比較した結果、IoU 中央値 **0.972**・完全に外れたものは 0 件。
229
+
192
230
  ### Tagged PDF からテーブル抽出
193
231
 
194
232
  ```
package/README.md CHANGED
@@ -45,7 +45,7 @@ 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_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 |
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. `include_bbox: true` adds **where each element is drawn** — one rectangle per page, in the form `add_annotation` takes |
49
49
  | `extract_tables` | Tagged PDF `<Table>` subtree → Markdown table (preserves columns). A table continuing across a page break is ONE table (`pages` array) |
50
50
  | `locate_objects` | Object number → page and rectangle, in the coordinate form [pdf-writer-mcp](https://github.com/shuji-bonji/pdf-writer-mcp) `add_annotation` takes. Bridges [pdf-verify-mcp](https://github.com/shuji-bonji/pdf-verify-mcp) `verify_integrity`'s "which objects changed" to "where they are". Each location names its `basis`: an annotation's own `/Rect` is exact, a content stream can only say "the whole page" |
51
51
 
@@ -191,6 +191,46 @@ separately, and an element spanning a page break stays ONE element. Use
191
191
  `roles: ["H1", "H2"]` to pull an outline. Untagged PDFs return
192
192
  `isTagged: false` with a reason — nothing is guessed from coordinates.
193
193
 
194
+ #### `include_bbox`: where the element is drawn
195
+
196
+ ```
197
+ extract_structured_text({ file_path: "/doc.pdf", roles: ["P"], include_bbox: true })
198
+ → - **P** (page 1) — Measured paragraph
199
+ - *bbox* p1 `(50.0, 297.5, 161.4, 308.6)` — text-extent
200
+ - **Figure** (page 1)
201
+ - *bbox* p1 `(50.0, 150.0, 110.0, 190.0)` — layout-attribute-bbox
202
+ ```
203
+
204
+ Rectangles are in PDF default user space (origin bottom-left, pt, normalised) —
205
+ exactly what [pdf-writer-mcp](https://github.com/shuji-bonji/pdf-writer-mcp)
206
+ `add_annotation` takes, so "annotate this paragraph" needs no coordinate
207
+ conversion in between. `/Rotate` and a shifted `/CropBox` do not move them.
208
+
209
+ `basis` says how strong the claim is, and the two are different in kind:
210
+
211
+ | `basis` | What it is |
212
+ | --- | --- |
213
+ | `layout-attribute-bbox` | The `/BBox` the file **declares** (ISO 32000-2 Table 379), read through `/A` or `/C` + `/ClassMap`. A statement by the producer, reported as-is — and the only source for content that has no text |
214
+ | `text-extent` | **Measured** from the element's text: baseline origin plus the font's ascent/descent. The line box, not the glyph outlines. Images and vector art contribute nothing |
215
+
216
+ An element spanning pages gets ONE RECTANGLE PER PAGE — merging them would put
217
+ content on a page it is not on. An element with no rectangle says why in
218
+ `boxNote` rather than returning a zero-sized one.
219
+
220
+ **A declaration is reported as-is, and cross-checked.** Files state nonsense:
221
+ the cover `Figure` of *both* Well-Tagged PDF 1.0 and the Tagged PDF Best Practice
222
+ Guide declares `/BBox [-32768 -32768 32767 32767]` — int16 sentinels where a
223
+ rectangle should be — and PDF32000_2008 has 131 of its 545 declarations reaching
224
+ past the page edge. Since this output is meant to go straight into
225
+ `add_annotation`, a declaration is checked against the page box (§7.7.3.3) and
226
+ against the element's own text; either contradiction is reported in `boxNote`,
227
+ with the rectangle still returned unaltered.
228
+
229
+ Measured against independent ground truth: on *Well-Tagged PDF (WTPDF) 1.0*, the
230
+ 166 `Link` structure elements were compared with the 173 `Link` **annotation**
231
+ `/Rect` values the producer placed for the same links — median IoU **0.972**,
232
+ none disjoint.
233
+
194
234
  ### Extract Tables (Tagged PDF)
195
235
 
196
236
  ```
package/dist/index.js CHANGED
@@ -36,7 +36,13 @@ What it does NOT do:
36
36
  (verify_signatures / verify_integrity).
37
37
  - No conformance judgement. validate_tagged / validate_metadata are deprecated in favour of
38
38
  pdf-verify-mcp's validate_conformance, which delegates to veraPDF.
39
- - No incremental-update history, no object-ID-to-coordinate mapping, no OCR.
39
+ - No incremental-update history (that is pdf-verify-mcp verify_integrity), and no OCR.
40
+
41
+ It DOES map content to coordinates: locate_objects turns an object number into a page and a
42
+ rectangle, and extract_structured_text with include_bbox does the same for a structure element.
43
+ Both answer in the form pdf-writer-mcp add_annotation takes, so "annotate the thing that
44
+ changed" needs no coordinate conversion in between. Every rectangle names its basis — a
45
+ measurement and a rectangle the file merely declares are not the same claim.
40
46
 
41
47
  Where an observation here and a verdict from pdf-verify-mcp disagree, the verdict wins —
42
48
  this server reads the file, the validator applies the rules.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,8CAA8C;AAC9C,sEAAsE;AACtE,sEAAsE;AACtE,MAAM,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC;AACxC,MAAM,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;AAC1C,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,CA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ema: z.ZodObject<{
68
68
  file_path: z.ZodString;
69
69
  pages: z.ZodOptional<z.ZodString>;
70
70
  roles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
71
+ include_bbox: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
71
72
  response_format: z.ZodDefault<z.ZodNativeEnum<typeof import("../constants.js").ResponseFormat>>;
72
73
  }, "strict", z.ZodTypeAny, {
73
74
  file_path: string;
74
75
  response_format: import("../constants.js").ResponseFormat;
76
+ include_bbox: boolean;
75
77
  pages?: string | undefined;
76
78
  roles?: string[] | undefined;
77
79
  }, {
@@ -79,6 +81,7 @@ export declare const ExtractStructuredTextSchema: z.ZodObject<{
79
81
  response_format?: import("../constants.js").ResponseFormat | undefined;
80
82
  pages?: string | undefined;
81
83
  roles?: string[] | undefined;
84
+ include_bbox?: boolean | undefined;
82
85
  }>;
83
86
  /** inspect_signatures */
84
87
  export declare const InspectSignaturesSchema: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"tier2.d.ts","sourceRoot":"","sources":["../../src/schemas/tier2.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,wBAAwB;AACxB,eAAO,MAAM,sBAAsB;;;;;;;;;EAKxB,CAAC;AAEZ,mBAAmB;AACnB,eAAO,MAAM,iBAAiB;;;;;;;;;EAKnB,CAAC;AAEZ,oBAAoB;AACpB,eAAO,MAAM,kBAAkB;;;;;;;;;EAKpB,CAAC;AAEZ,0BAA0B;AAC1B,eAAO,MAAM,wBAAwB;;;;;;;;;;;;EAM1B,CAAC;AAEZ,qBAAqB;AACrB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAarB,CAAC;AAEZ,8BAA8B;AAC9B,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;EAe7B,CAAC;AAEZ,yBAAyB;AACzB,eAAO,MAAM,uBAAuB;;;;;;;;;EAKzB,CAAC;AAEZ,mDAAmD;AACnD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;;;;;;;;;;;;;;;;;EA2B7B,CAAC;AAEZ,yBAAyB;AACzB,eAAO,MAAM,uBAAuB;;;;;;;;;EAKzB,CAAC;AAEZ,mDAAmD;AACnD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAMrB,CAAC;AAGZ,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAC3E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACnE,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC/E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACrE,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AACrF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
@@ -55,6 +55,16 @@ export const ExtractStructuredTextSchema = z
55
55
  .array(z.string())
56
56
  .optional()
57
57
  .describe('Structure types to include, e.g. ["H1","H2"] to extract an outline. Omit for all roles.'),
58
+ include_bbox: z
59
+ .boolean()
60
+ .optional()
61
+ .default(false)
62
+ .describe('Also report where each element is drawn, as boxes: one rectangle per page in PDF ' +
63
+ 'default user space (origin bottom-left, pt, normalised) — the form pdf-writer-mcp ' +
64
+ 'add_annotation takes. Each carries a basis: "layout-attribute-bbox" (the /BBox the ' +
65
+ 'file declares) or "text-extent" (measured from the element\'s text; images and ' +
66
+ 'vector art contribute nothing). Elements with no rectangle carry boxNote saying why. ' +
67
+ 'Off by default: it costs a second pass over every page.'),
58
68
  response_format: ResponseFormatSchema,
59
69
  })
60
70
  .strict();
@@ -1 +1 @@
1
- {"version":3,"file":"tier2.js","sourceRoot":"","sources":["../../src/schemas/tier2.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEhF,wBAAwB;AACxB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC;KACpC,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,mBAAmB;AACnB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC;KAC/B,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,oBAAoB;AACpB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,0BAA0B;AAC1B,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC;KACtC,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,KAAK,EAAE,WAAW;IAClB,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,qBAAqB;AACrB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,cAAc,EAAE,CAAC;SACd,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9B,GAAG,CAA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AO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CACP,mFAAmF;QACjF,oFAAoF;QACpF,qFAAqF;QACrF,iFAAiF;QACjF,uFAAuF;QACvF,yDAAyD,CAC5D;IACH,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,yBAAyB;AACzB,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC;KACrC,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,mDAAmD;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,SAAS,EAAE,cAAc;IACzB,KAAK,EAAE,WAAW;IAClB,eAAe,EAAE,oBAAoB;CACtC,CAAC;KACD,MAAM,EAAE,CAAC"}
@@ -197,6 +197,67 @@ export declare function resolveLineBreaks(text: string): string;
197
197
  * (`p7R_mc0`) — so merging the per-page maps is safe.
198
198
  */
199
199
  export declare function buildDocumentIdToTextMap(doc: PDFDocumentProxy): Promise<Map<string, string>>;
200
+ /** An axis-aligned rectangle accumulated in default user space. */
201
+ export interface RunBox {
202
+ minX: number;
203
+ minY: number;
204
+ maxX: number;
205
+ maxY: number;
206
+ }
207
+ /** What a marked-content sequence's text occupies, and what could not be measured. */
208
+ export interface MarkedContentExtent {
209
+ /** null when nothing measurable was found inside the sequence. */
210
+ box: RunBox | null;
211
+ /**
212
+ * True when a run in vertical writing mode was seen. Vertical runs are NOT
213
+ * folded into `box` — pdfjs reports the advance in `height` rather than
214
+ * `width` for them, and guessing which way the glyphs grow would produce a
215
+ * rectangle that is wrong rather than absent. The flag makes the caller
216
+ * suppress the box instead of returning a silently shrunken one.
217
+ */
218
+ hasUnmeasurableRun: boolean;
219
+ }
220
+ /** A `getTextContent` item, with the geometry fields this module needs. */
221
+ interface PositionedTextItem extends TextContentItemLike {
222
+ transform?: number[];
223
+ width?: number;
224
+ height?: number;
225
+ fontName?: string;
226
+ }
227
+ /** `styles` from `getTextContent`: font metrics, normalised to the em square. */
228
+ export interface TextStyleLike {
229
+ ascent?: number;
230
+ descent?: number;
231
+ vertical?: boolean;
232
+ }
233
+ /**
234
+ * Build a map from a marked-content `id` to the rectangle its text occupies.
235
+ *
236
+ * The same walk as `buildIdToTextMap`, and deliberately the same skips, so that
237
+ * "the text of this element" and "where that text is" cannot disagree: nested
238
+ * sequences count toward every active id, and `Artifact` sequences are excluded
239
+ * (§14.8.2.5 NOTE 3 puts artifacts outside the logical content order).
240
+ *
241
+ * Two further exclusions belong to geometry rather than text:
242
+ *
243
+ * - **Whitespace-only runs.** Table 379 defines `BBox` as the rectangle that
244
+ * "completely encloses its **visible** content", and a run of spaces is not
245
+ * visible. pdfjs does emit wide ones for inter-cell gaps: measured on
246
+ * `spanning-table.pdf`, a `TH` carries a 75 pt run of spaces that reaches
247
+ * into the neighbouring column. That particular one arrives with
248
+ * `height: 0` and `runBox` rejects it on those grounds alone; this check is
249
+ * what covers a spacer that comes with a height.
250
+ * - **EOL markers** (`str: ''`, `hasEOL: true`), which carry no geometry.
251
+ */
252
+ export declare function buildIdToBoxMap(items: PositionedTextItem[], styles?: Record<string, TextStyleLike>): Map<string, MarkedContentExtent>;
253
+ /**
254
+ * Build the marked-content id → rectangle map across the whole document.
255
+ *
256
+ * Document-wide for the same reason as `buildDocumentIdToTextMap`: a structure
257
+ * element can own content on several pages (§14.8.2.5 NOTE 2), and the ids are
258
+ * globally unique because pdfjs builds them from the page object number.
259
+ */
260
+ export declare function buildDocumentIdToBoxMap(doc: PDFDocumentProxy): Promise<Map<string, MarkedContentExtent>>;
200
261
  /**
201
262
  * Normalise raw cell text:
202
263
  * 0. Resolve line breaks (CJK-aware) — a break between two CJK characters is
@@ -1 +1 @@
1
- {"version":3,"file":"pdfjs-service.d.ts","sourceRoot":"","sources":["../../src/services/pdfjs-service.ts"],"names":[],"mappings":"AA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E,kBAAkB,EAAE,EAC3B,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAM,GACzC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CA+ClC;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAiB3C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAcjD;AA4CD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,mBAAmB,CAAC,CAgF9B"}
@@ -762,6 +762,166 @@ export async function buildDocumentIdToTextMap(doc) {
762
762
  }
763
763
  return merged;
764
764
  }
765
+ /** Default em-square ascent/descent, used when pdfjs reports none for a font. */
766
+ const FALLBACK_ASCENT = 0.75;
767
+ const FALLBACK_DESCENT = -0.25;
768
+ /**
769
+ * The rectangle one text run occupies, in default user space.
770
+ *
771
+ * `item.transform` is the run's mapping from em units to user space — §9.4.4's
772
+ * Trm without the device transform, so its translation is the baseline origin
773
+ * and its linear part carries font size, horizontal scaling and any rotation.
774
+ * Measured against pdfjs-dist 4.10: text drawn at 45° reports
775
+ * `[14.14, 14.14, -14.14, 14.14, x, y]` for a 20 pt font, i.e. `|(a,b)| = 20`.
776
+ *
777
+ * So the box is built along the run's own axes rather than the page's:
778
+ *
779
+ * - **u** = `(a,b)` normalised — the baseline direction; the run extends
780
+ * `item.width` along it (pdfjs reports the advance already in user space).
781
+ * - **v** = `(c,d)` normalised — the up direction; the run extends from
782
+ * `descent × height` to `ascent × height` along it.
783
+ *
784
+ * The vertical extent therefore comes from the font's ascent/descent, not from
785
+ * glyph outlines: a glyph that overshoots its ascent (an accent, a swash) can
786
+ * exceed this rectangle. It is the line box, measured, not the ink.
787
+ */
788
+ function runBox(item, style) {
789
+ const t = item.transform;
790
+ if (!t || t.length < 6 || t.some((v) => !Number.isFinite(v)))
791
+ return null;
792
+ const width = item.width ?? 0;
793
+ const height = item.height ?? 0;
794
+ if (!Number.isFinite(width) || !Number.isFinite(height))
795
+ return null;
796
+ const [a, b, c, d, e, f] = t;
797
+ const baselineLength = Math.hypot(a, b);
798
+ const upLength = Math.hypot(c, d);
799
+ // A degenerate matrix draws nothing measurable; a zero-height run is a pdfjs
800
+ // spacing artefact (str: " " with height 0), not visible content.
801
+ if (baselineLength === 0 || upLength === 0 || height === 0)
802
+ return null;
803
+ const ux = a / baselineLength;
804
+ const uy = b / baselineLength;
805
+ const vx = c / upLength;
806
+ const vy = d / upLength;
807
+ const ascent = style?.ascent ?? FALLBACK_ASCENT;
808
+ const descent = style?.descent ?? FALLBACK_DESCENT;
809
+ const top = ascent * height;
810
+ const bottom = descent * height;
811
+ const xs = [];
812
+ const ys = [];
813
+ for (const along of [0, width]) {
814
+ for (const up of [bottom, top]) {
815
+ xs.push(e + ux * along + vx * up);
816
+ ys.push(f + uy * along + vy * up);
817
+ }
818
+ }
819
+ return {
820
+ minX: Math.min(...xs),
821
+ minY: Math.min(...ys),
822
+ maxX: Math.max(...xs),
823
+ maxY: Math.max(...ys),
824
+ };
825
+ }
826
+ function mergeBox(into, add) {
827
+ if (!into)
828
+ return { ...add };
829
+ return {
830
+ minX: Math.min(into.minX, add.minX),
831
+ minY: Math.min(into.minY, add.minY),
832
+ maxX: Math.max(into.maxX, add.maxX),
833
+ maxY: Math.max(into.maxY, add.maxY),
834
+ };
835
+ }
836
+ /**
837
+ * Build a map from a marked-content `id` to the rectangle its text occupies.
838
+ *
839
+ * The same walk as `buildIdToTextMap`, and deliberately the same skips, so that
840
+ * "the text of this element" and "where that text is" cannot disagree: nested
841
+ * sequences count toward every active id, and `Artifact` sequences are excluded
842
+ * (§14.8.2.5 NOTE 3 puts artifacts outside the logical content order).
843
+ *
844
+ * Two further exclusions belong to geometry rather than text:
845
+ *
846
+ * - **Whitespace-only runs.** Table 379 defines `BBox` as the rectangle that
847
+ * "completely encloses its **visible** content", and a run of spaces is not
848
+ * visible. pdfjs does emit wide ones for inter-cell gaps: measured on
849
+ * `spanning-table.pdf`, a `TH` carries a 75 pt run of spaces that reaches
850
+ * into the neighbouring column. That particular one arrives with
851
+ * `height: 0` and `runBox` rejects it on those grounds alone; this check is
852
+ * what covers a spacer that comes with a height.
853
+ * - **EOL markers** (`str: ''`, `hasEOL: true`), which carry no geometry.
854
+ */
855
+ export function buildIdToBoxMap(items, styles = {}) {
856
+ const map = new Map();
857
+ const stack = [];
858
+ const touch = (id) => {
859
+ const existing = map.get(id);
860
+ if (existing)
861
+ return existing;
862
+ const created = { box: null, hasUnmeasurableRun: false };
863
+ map.set(id, created);
864
+ return created;
865
+ };
866
+ for (const item of items) {
867
+ const t = item.type;
868
+ if (t === 'beginMarkedContent' || t === 'beginMarkedContentProps') {
869
+ stack.push({ id: item.id ?? null, isArtifact: item.tag === 'Artifact' });
870
+ continue;
871
+ }
872
+ if (t === 'endMarkedContent') {
873
+ stack.pop();
874
+ continue;
875
+ }
876
+ if (t !== undefined)
877
+ continue; // unknown marker
878
+ if (stack.some((s) => s.isArtifact))
879
+ continue;
880
+ if (item.hasEOL)
881
+ continue;
882
+ const str = item.str ?? '';
883
+ if (str.trim() === '')
884
+ continue;
885
+ const style = item.fontName ? styles[item.fontName] : undefined;
886
+ if (style?.vertical) {
887
+ for (const frame of stack) {
888
+ if (frame.id)
889
+ touch(frame.id).hasUnmeasurableRun = true;
890
+ }
891
+ continue;
892
+ }
893
+ const box = runBox(item, style);
894
+ if (!box)
895
+ continue;
896
+ for (const frame of stack) {
897
+ if (frame.id) {
898
+ const extent = touch(frame.id);
899
+ extent.box = mergeBox(extent.box, box);
900
+ }
901
+ }
902
+ }
903
+ return map;
904
+ }
905
+ /**
906
+ * Build the marked-content id → rectangle map across the whole document.
907
+ *
908
+ * Document-wide for the same reason as `buildDocumentIdToTextMap`: a structure
909
+ * element can own content on several pages (§14.8.2.5 NOTE 2), and the ids are
910
+ * globally unique because pdfjs builds them from the page object number.
911
+ */
912
+ export async function buildDocumentIdToBoxMap(doc) {
913
+ const perPage = await Promise.all(Array.from({ length: doc.numPages }, async (_, i) => {
914
+ const page = await doc.getPage(i + 1);
915
+ const content = await page.getTextContent({ includeMarkedContent: true });
916
+ return buildIdToBoxMap(content.items, content.styles);
917
+ }));
918
+ const merged = new Map();
919
+ for (const map of perPage) {
920
+ for (const [id, extent] of map)
921
+ merged.set(id, extent);
922
+ }
923
+ return merged;
924
+ }
765
925
  /**
766
926
  * Normalise raw cell text:
767
927
  * 0. Resolve line breaks (CJK-aware) — a break between two CJK characters is