@shuji-bonji/pdf-reader-mcp 0.14.0 → 0.15.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 (74) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/README.ja.md +11 -6
  3. package/README.md +13 -6
  4. package/dist/services/actual-text-service.d.ts +4 -3
  5. package/dist/services/actual-text-service.d.ts.map +1 -1
  6. package/dist/services/actual-text-service.js +5 -4
  7. package/dist/services/actual-text-service.js.map +1 -1
  8. package/dist/services/content-stream-service.d.ts +45 -13
  9. package/dist/services/content-stream-service.d.ts.map +1 -1
  10. package/dist/services/content-stream-service.js +209 -174
  11. package/dist/services/content-stream-service.js.map +1 -1
  12. package/dist/services/font-service.d.ts +35 -0
  13. package/dist/services/font-service.d.ts.map +1 -0
  14. package/dist/services/font-service.js +127 -0
  15. package/dist/services/font-service.js.map +1 -0
  16. package/dist/services/object-locator.d.ts.map +1 -1
  17. package/dist/services/object-locator.js +163 -107
  18. package/dist/services/object-locator.js.map +1 -1
  19. package/dist/services/pdfjs-service.d.ts +18 -14
  20. package/dist/services/pdfjs-service.d.ts.map +1 -1
  21. package/dist/services/pdfjs-service.js +19 -14
  22. package/dist/services/pdfjs-service.js.map +1 -1
  23. package/dist/services/recover-service.d.ts +64 -0
  24. package/dist/services/recover-service.d.ts.map +1 -0
  25. package/dist/services/recover-service.js +104 -0
  26. package/dist/services/recover-service.js.map +1 -0
  27. package/dist/services/signature-service.d.ts +28 -0
  28. package/dist/services/signature-service.d.ts.map +1 -0
  29. package/dist/services/signature-service.js +200 -0
  30. package/dist/services/signature-service.js.map +1 -0
  31. package/dist/services/struct-tree-service.d.ts +0 -6
  32. package/dist/services/struct-tree-service.d.ts.map +1 -1
  33. package/dist/services/struct-tree-service.js +56 -49
  34. package/dist/services/struct-tree-service.js.map +1 -1
  35. package/dist/services/struct-tree-walker.d.ts +13 -4
  36. package/dist/services/struct-tree-walker.d.ts.map +1 -1
  37. package/dist/services/struct-tree-walker.js +133 -87
  38. package/dist/services/struct-tree-walker.js.map +1 -1
  39. package/dist/services/structure-service.d.ts +57 -0
  40. package/dist/services/structure-service.d.ts.map +1 -0
  41. package/dist/services/structure-service.js +237 -0
  42. package/dist/services/structure-service.js.map +1 -0
  43. package/dist/services/text-extractability-service.d.ts +11 -0
  44. package/dist/services/text-extractability-service.d.ts.map +1 -1
  45. package/dist/services/text-extractability-service.js +83 -52
  46. package/dist/services/text-extractability-service.js.map +1 -1
  47. package/dist/services/validation-service.d.ts.map +1 -1
  48. package/dist/services/validation-service.js +4 -3
  49. package/dist/services/validation-service.js.map +1 -1
  50. package/dist/tools/tier1/search-text.js +1 -1
  51. package/dist/tools/tier1/search-text.js.map +1 -1
  52. package/dist/tools/tier1/summarize.d.ts.map +1 -1
  53. package/dist/tools/tier1/summarize.js +16 -4
  54. package/dist/tools/tier1/summarize.js.map +1 -1
  55. package/dist/tools/tier2/inspect-fonts.js +2 -2
  56. package/dist/tools/tier2/inspect-fonts.js.map +1 -1
  57. package/dist/tools/tier2/inspect-signatures.js +1 -1
  58. package/dist/tools/tier2/inspect-signatures.js.map +1 -1
  59. package/dist/tools/tier2/inspect-structure.d.ts.map +1 -1
  60. package/dist/tools/tier2/inspect-structure.js +9 -2
  61. package/dist/tools/tier2/inspect-structure.js.map +1 -1
  62. package/dist/types.d.ts +25 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/utils/error-handler.d.ts.map +1 -1
  65. package/dist/utils/error-handler.js +24 -5
  66. package/dist/utils/error-handler.js.map +1 -1
  67. package/dist/utils/formatter.d.ts.map +1 -1
  68. package/dist/utils/formatter.js +13 -1
  69. package/dist/utils/formatter.js.map +1 -1
  70. package/package.json +4 -2
  71. package/dist/services/pdflib-service.d.ts +0 -81
  72. package/dist/services/pdflib-service.d.ts.map +0 -1
  73. package/dist/services/pdflib-service.js +0 -504
  74. package/dist/services/pdflib-service.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,137 @@ 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.15.1] - 2026-09-15
9
+
10
+ ### Fixed
11
+
12
+ - **`summarize` told the caller to decrypt a file it had already decrypted.**
13
+ The `next` suggestion for an encrypted document was derived from
14
+ `metadata.isEncrypted` alone, so it kept saying "content streams and strings
15
+ are ciphertext to this server (§7.6.2) … Decrypt the file first" even after
16
+ 0.15.0 began deriving the file encryption key from the empty user password
17
+ (§7.6.4.3.2) and reading the content. On
18
+ `tests/fixtures/encrypted-actualtext.pdf` the same response reported
19
+ `textExtractability: "extracted"`, an empty `unreadablePages` and the page's
20
+ text — the advice contradicted the observation printed beside it.
21
+
22
+ The suggestion now follows the observation that says whether anything was
23
+ read. A document whose content was read is told the key was derived and that
24
+ no separate decryption step is needed; one where `textExtractability` is
25
+ `not_observed` or `null` keeps the original advice, which is what that state
26
+ means.
27
+
28
+ - **An encrypted document was given no other advice.** The same branch returned
29
+ early, so the `isTagged`, `pageCount` and `textExtractability` suggestions
30
+ were withheld from documents that were fully readable — the fixture above is
31
+ tagged, and the pointer to `extract_structured_text` never appeared. Only the
32
+ branch where nothing could be read returns early now.
33
+
34
+ ## [0.15.0] - 2026-08-31
35
+
36
+ pdf-lib is gone. Every reading that used it now goes through
37
+ [`@normativepdf/recover`](https://www.npmjs.com/package/@normativepdf/recover),
38
+ which reports **how far it got** instead of returning a partial answer silently.
39
+ `inspect_structure` changes shape — read **Changed** before upgrading.
40
+
41
+ The removal was measured against a frozen baseline of 2,942 specimens ×
42
+ 67,666 tool calls (veraPDF corpus, pdf20examples, and this repository's own
43
+ specimens), in four stages. Every difference in every stage is attributed in
44
+ `docs/handoff/pdflib-removal.md`; none of them is a wrong `pass`.
45
+
46
+ ### Changed
47
+
48
+ - **BREAKING — `inspect_structure` reports COS types, not library class names.**
49
+ `objectStats.byType` and `catalog[].type` used to carry pdf-lib's internal
50
+ class names (`PDFCatalog`, `PDFPageTree`, `PDFPageLeaf`, `PDFRawStream`,
51
+ `PDFNumber`, `PDFInvalidObject`). None of those is a type in ISO 32000-2 §7.3 —
52
+ they are how pdf-lib chose to model the file — so the vocabulary could not
53
+ survive the removal. It is now the ten COS types of §7.3: `dict`, `stream`,
54
+ `array`, `name`, `string`, `integer`, `real`, `boolean`, `null`, `ref`.
55
+
56
+ What pdf-lib's `PDFCatalog` / `PDFPageTree` / `PDFPageLeaf` actually carried
57
+ was the dictionary's `/Type`, so that is now reported separately as
58
+ `objectStats.byDocType` (`Catalog`, `Pages`, `Page`, `Font`, `ObjStm`,
59
+ `XRef`, …). Counting the two in one field made "51,237 dictionaries" and
60
+ "13,001 pages" compete for the same slot.
61
+
62
+ `PDFNumber` folded integers and reals together; R-7.3.3-6 ("A real number
63
+ shall not be present when an integer is expected") asks for the distinction,
64
+ so `integer` and `real` are counted apart.
65
+
66
+ - **BREAKING — `inspect_structure` no longer counts objects the cross-reference
67
+ table does not name.** pdf-lib scanned the whole file, so a `N 0 obj` written
68
+ into the bytes but absent from the table was counted. 3,308 calls change.
69
+ Checked against an independent implementation on seven specimens:
70
+ `qpdf --show-object=N` answers `null` for every one of them.
71
+
72
+ - **`inspect_signatures` no longer says "No AcroForm found" when it could not
73
+ look.** When a document is encrypted and the key cannot be derived from the
74
+ empty user password (§7.6.4.3.2), not one indirect object is readable — the
75
+ catalogue included. Reporting "0 signature fields" there tells the caller a
76
+ signed document is unsigned. `inspect_structure` and `inspect_fonts` said the
77
+ same kind of thing with page and font counts; all three now name the reason.
78
+
79
+ - **Encrypted documents whose key *can* be derived are now read.** pdf-lib was
80
+ loaded with `ignoreEncryption`, which ignores encryption rather than undoing
81
+ it, so a document with an empty user password was treated as unreadable.
82
+ §7.6.4.3.2 says to try the empty password first; `@normativepdf/recover` does,
83
+ and decrypts. `read_text` on such a file now returns its `/ActualText`
84
+ replacements (§14.9.4) instead of raw glyphs, and `search_text` finds them.
85
+
86
+ - **Text strings are decoded by the core's one implementation.** The private
87
+ copy in this package stripped a leading `ESC <lang> ESC` sequence from
88
+ PDFDocEncoded bytes as well. §7.9.2.2.2 places language escapes in *Unicode*
89
+ text strings and names only UTF-16BE and UTF-8; in PDFDocEncoding, byte 0x1B
90
+ is U+02D9 (Table D.3), so what was being stripped was content.
91
+
92
+ ### Added
93
+
94
+ - **`objectStats.unreadable`** — objects the cross-reference table names but
95
+ that could not be read. Counted apart from `totalObjects`, because folding
96
+ them in produces a number that is neither "how many were read" nor "how many
97
+ the table names". `0` is the result of looking, not the absence of looking.
98
+
99
+ - **Cycle guards on the signature field walk.** pdf-lib's `getAllFields()` has
100
+ none, so a document whose `/Kids` point back at an ancestor never terminates —
101
+ and a walk that does not terminate is not an exception: it is caught by no
102
+ `try`/`catch` and by no test timeout. A specimen is checked in.
103
+
104
+ ### Fixed
105
+
106
+ - **Embedded fonts reported as not embedded.** pdf-lib's `PDFDict.has` misses
107
+ keys that come from an object stream (`get` finds them, `has` does not), so
108
+ `inspect_fonts` said "not embedded" for fonts whose `FontDescriptor` carries a
109
+ `FontFile*`. Seven calls change.
110
+
111
+ - **`#xx` escapes in name objects are resolved** (§7.3.5). `/BaseFont` values
112
+ such as `FreeMonoBold#c4` were reported verbatim rather than decoded.
113
+
114
+ - **Documents pdf-lib could not open at all are now read.** Ten tool calls
115
+ across two specimens (a header with no version number, `%PDF-`) stop being
116
+ errors. Over the whole corpus, `isError` falls from 75 to 61 and **no call
117
+ became an error that was not one before**.
118
+
119
+ ### Removed
120
+
121
+ - `pdf-lib` as a runtime dependency. It remains in `devDependencies`, where the
122
+ two test-fixture generators use it. `npm ls --omit=dev pdf-lib` reports
123
+ `(empty)`.
124
+
125
+ ### Known limitations
126
+
127
+ - `inspect_structure` and the other Tier 2 tools do not yet report the
128
+ `ReadingScope` that `read_text` and friends gained in 0.14.0. When the newest
129
+ cross-reference section cannot be read and an older one is used instead, the
130
+ library says so but this server does not pass it on — measured on one
131
+ specimen, where a catalogue entry added by an incremental update disappears
132
+ from the answer without a word.
133
+ - `normativepdf` does not implement `/LZWDecode` (§7.4.4), and its inflate
134
+ refuses a stream with trailing bytes after the ADLER32 checksum. Three
135
+ specimens whose content streams pdf-lib could decode are now reported as
136
+ `not_observed` rather than as text-free pages. Both are gaps in the core, not
137
+ in this server; neither turns a failed check into a passing one.
138
+
8
139
  ## [0.14.0] - 2026-08-30
9
140
 
10
141
  Text-returning tools now say which of the readings behind their answer were
package/README.ja.md CHANGED
@@ -365,16 +365,17 @@ read_text({ file_path: "/path/to/form.pdf", compact_whitespace: true })
365
365
 
366
366
  - **TypeScript** + MCP TypeScript SDK
367
367
  - **pdfjs-dist** (Mozilla) — テキスト/画像抽出、タグツリー、注釈
368
- - **pdf-lib** — 低レベルオブジェクト構造解析
369
- - **Vitest** — Unit + E2E テスト(171 tests)
368
+ - **normativepdf** + **@normativepdf/recover** — COS オブジェクトの読み口。
369
+ 相互参照表が ISO 32000-2 §7.5 のとおりでないファイルも読める範囲まで読む
370
+ - **Vitest** — Unit + E2E テスト(483 tests)
370
371
  - **Biome** — lint + format
371
372
  - **Zod** — 入力バリデーション
372
373
 
373
374
  ## テスト
374
375
 
375
376
  ```bash
376
- npm test # 全テスト実行(Unit: 39 tests)
377
- npm run test:e2e # E2E のみ(132 tests)
377
+ npm test # 全テスト実行(Unit + E2E: 483 tests)
378
+ npm run test:e2e # E2E のみ(283 tests)
378
379
  npm run test:watch # ウォッチモード
379
380
  ```
380
381
 
@@ -393,7 +394,11 @@ pdf-reader-mcp/
393
394
  │ │ └── index.ts # ツール登録
394
395
  │ ├── services/
395
396
  │ │ ├── pdfjs-service.ts # pdfjs-dist ラッパー(並列ページ処理)
396
- │ │ ├── pdflib-service.ts # pdf-lib ラッパー
397
+ │ │ ├── recover-service.ts # @normativepdf/recover。文書を開く口と、
398
+ │ │ │ # どこまで読めたかの申告(DocumentScope)
399
+ │ │ ├── structure-service.ts # 目録・ページ木・オブジェクトの数え上げ
400
+ │ │ ├── font-service.ts # 各ページの /Resources に載っているフォント
401
+ │ │ ├── signature-service.ts # AcroForm の署名フィールド(構造のみ)
397
402
  │ │ ├── validation-service.ts # 検証・比較ロジック
398
403
  │ │ └── url-fetcher.ts # URL 取得
399
404
  │ ├── schemas/ # Zod バリデーションスキーマ
@@ -404,7 +409,7 @@ pdf-reader-mcp/
404
409
  │ └── error-handler.ts # エラーハンドリング
405
410
  └── tests/
406
411
  ├── tier1/ # Unit tests
407
- └── e2e/ # E2E tests (9 suites, 132 tests)
412
+ └── e2e/ # E2E tests (16 suites, 283 tests)
408
413
  ```
409
414
 
410
415
  ## エラー応答 (houki-hub family contract)
package/README.md CHANGED
@@ -371,16 +371,17 @@ read_text({ file_path: "/path/to/form.pdf", compact_whitespace: true })
371
371
 
372
372
  - **TypeScript** + MCP TypeScript SDK
373
373
  - **pdfjs-dist** (Mozilla) — text/image extraction, tag tree, annotations
374
- - **pdf-lib** — low-level object structure analysis
375
- - **Vitest** — unit + E2E testing (171 tests)
374
+ - **normativepdf** + **@normativepdf/recover** — COS object access, read from
375
+ files whose cross-reference table does not follow ISO 32000-2 §7.5
376
+ - **Vitest** — unit + E2E testing (483 tests)
376
377
  - **Biome** — linting + formatting
377
378
  - **Zod** — input validation
378
379
 
379
380
  ## Testing
380
381
 
381
382
  ```bash
382
- npm test # Run all tests (unit: 39 tests)
383
- npm run test:e2e # E2E tests only (132 tests)
383
+ npm test # Run all tests (unit + E2E: 483 tests)
384
+ npm run test:e2e # E2E tests only (283 tests)
384
385
  npm run test:watch # Watch mode
385
386
  ```
386
387
 
@@ -399,7 +400,13 @@ pdf-reader-mcp/
399
400
  │ │ └── index.ts # Tool registration
400
401
  │ ├── services/
401
402
  │ │ ├── pdfjs-service.ts # pdfjs-dist wrapper (parallel page processing)
402
- │ │ ├── pdflib-service.ts # pdf-lib wrapper
403
+ │ │ ├── recover-service.ts # @normativepdf/recover — opening a document,
404
+ │ │ │ # and how far it could be read (DocumentScope)
405
+ │ │ ├── structure-service.ts # Catalog, page tree, object statistics
406
+ │ │ ├── font-service.ts # Fonts named in each page's /Resources
407
+ │ │ ├── signature-service.ts # Signature fields of the AcroForm (structure only)
408
+ │ │ ├── content-stream-service.ts # Marked-content operators, text-showing tally
409
+ │ │ ├── struct-tree-service.ts # Logical structure (tags, structured text)
403
410
  │ │ ├── validation-service.ts # Validation & comparison logic
404
411
  │ │ └── url-fetcher.ts # URL fetching
405
412
  │ ├── schemas/ # Zod validation schemas
@@ -410,7 +417,7 @@ pdf-reader-mcp/
410
417
  │ └── error-handler.ts # Error handling
411
418
  └── tests/
412
419
  ├── tier1/ # Unit tests
413
- └── e2e/ # E2E tests (9 suites, 132 tests)
420
+ └── e2e/ # E2E tests (16 suites, 283 tests)
414
421
  ```
415
422
 
416
423
  ## Error Contract (houki-hub family)
@@ -32,7 +32,7 @@
32
32
  * pdfjs supplies itself). Returning raw glyphs is the old, documented
33
33
  * behaviour; attaching replacement text to the wrong glyphs would be new damage.
34
34
  */
35
- import type { PDFDocument as PdfLibDocument } from 'pdf-lib';
35
+ import type { PdfDocument } from 'normativepdf';
36
36
  /** A pdfjs text item, reduced to what reading order and joining need. */
37
37
  export interface PositionedText {
38
38
  str: string;
@@ -71,7 +71,7 @@ interface RawItem {
71
71
  * replaced. Keyed by pdfjs's marked-content id (`p7R_mc3`) so no page bookkeeping
72
72
  * is needed at lookup time.
73
73
  */
74
- export declare function buildStructActualTextMap(doc: PdfLibDocument): Map<string, string>;
74
+ export declare function buildStructActualTextMap(doc: PdfDocument, lockedOut: boolean): Promise<Map<string, string>>;
75
75
  /**
76
76
  * Fold a page's pdfjs items into positioned text, substituting `/ActualText`.
77
77
  *
@@ -93,7 +93,8 @@ export declare function foldActualText(rawItems: RawItem[], structActualText: Re
93
93
  *
94
94
  * @param pageIndex 0-based.
95
95
  * @param pdfjsBeginCount How many begin markers pdfjs reported for the page.
96
+ * @param lockedOut 暗号化されていて鍵が導けなかった(`lockedOut(scope)`)。
96
97
  */
97
- export declare function buildSpanActualTextMap(doc: PdfLibDocument, pageIndex: number, pdfjsBeginCount: number): Map<number, string> | undefined;
98
+ export declare function buildSpanActualTextMap(doc: PdfDocument, pageIndex: number, pdfjsBeginCount: number, lockedOut: boolean): Promise<Map<number, string> | undefined>;
98
99
  export {};
99
100
  //# sourceMappingURL=actual-text-service.d.ts.map
@@ -1 +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"}
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,EAAE,MAAM,cAAc,CAAC;AAKhD,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,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkB9B;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;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAY1C"}
@@ -43,9 +43,9 @@ import { collectContentRefs, walkStructTree } from './struct-tree-walker.js';
43
43
  * replaced. Keyed by pdfjs's marked-content id (`p7R_mc3`) so no page bookkeeping
44
44
  * is needed at lookup time.
45
45
  */
46
- export function buildStructActualTextMap(doc) {
46
+ export async function buildStructActualTextMap(doc, lockedOut) {
47
47
  const map = new Map();
48
- const roots = walkStructTree(doc);
48
+ const roots = await walkStructTree(doc, lockedOut);
49
49
  if (!roots)
50
50
  return map;
51
51
  const visit = (element) => {
@@ -178,9 +178,10 @@ export function foldActualText(rawItems, structActualText, spanActualText) {
178
178
  *
179
179
  * @param pageIndex 0-based.
180
180
  * @param pdfjsBeginCount How many begin markers pdfjs reported for the page.
181
+ * @param lockedOut 暗号化されていて鍵が導けなかった(`lockedOut(scope)`)。
181
182
  */
182
- export function buildSpanActualTextMap(doc, pageIndex, pdfjsBeginCount) {
183
- const events = scanPageMarkedContent(doc, pageIndex);
183
+ export async function buildSpanActualTextMap(doc, pageIndex, pdfjsBeginCount, lockedOut) {
184
+ const events = await scanPageMarkedContent(doc, pageIndex, lockedOut);
184
185
  if (!events)
185
186
  return pdfjsBeginCount === 0 ? new Map() : undefined;
186
187
  const begins = events.filter((e) => e.kind === 'begin');
@@ -1 +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,MAAM,yBAAyB,CAAC;AA+B7E;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAmB;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK;QAAE,OAAO,GAAG,CAAC;IAEvB,MAAM,KAAK,GAAG,CAAC,OAAsB,EAAQ,EAAE;QAC7C,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;YACzC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,OAAO,GAAG,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;YACnE,CAAC;YACD,gEAAgE;YAChE,OAAO;QACT,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ;YAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAmB,EACnB,gBAA6C,EAC7C,cAAuD;IAEvD,MAAM,GAAG,GAAqB,EAAE,CAAC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B,GAAG,KAAK,CAAC;QAClC,uBAAuB,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,SAAS,EAAE,CAAC;IACZ,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,GAAgB,EAChB,SAAiB,EACjB,eAAuB,EACvB,SAAkB;IAElB,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACtE,IAAI,CAAC,MAAM;QAAE,OAAO,eAAe,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAElE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;IACxD,IAAI,MAAM,CAAC,MAAM,KAAK,eAAe;QAAE,OAAO,SAAS,CAAC;IAExD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC9B,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -31,8 +31,38 @@
31
31
  * - `Do` on a **Form** XObject is walked inline at that point, using the
32
32
  * form's own `/Resources` and falling back to the parent's — exactly what
33
33
  * pdfjs's `case OPS.paintXObject` does.
34
+ *
35
+ * ## COS の読み口(S3・2026-08-31)
36
+ *
37
+ * pdf-lib の `PDFDict` / `PDFRef` / `PDFStream` を `@normativepdf/recover` の
38
+ * `asDict` / `asRef` / `asStream` に替えた。違いは 2 つある。
39
+ *
40
+ * 1. **参照の解決とストリームの復号が非同期になった。** `doc.context.lookup()` は
41
+ * 同期だったが `resolved(doc, …)` は Promise を返す。演算子ごとに `await` を
42
+ * 置くと、内容ストリームのトークン 1 つごとにマイクロタスクが 1 つ入る
43
+ * (本文 1 ページで数万件)。そこで**走査の本体は同期のまま**にし、
44
+ * `handleOperator` は解決が要るときだけ Promise を返す
45
+ * (`BDC` の名前が初出のとき・`Do`・`Tf` のフォントが初出のとき)。
46
+ * それ以外の演算子は 1 つも `await` を通らない。
47
+ * 2. **暗号化された文書が読めるようになった。** pdf-lib は `ignoreEncryption` で
48
+ * 開いていたので内容ストリームは暗号文のままで、`doc.isEncrypted` が真なら
49
+ * 走査を諦めていた。recover は鍵が導ければ復号するので、諦めるのは
50
+ * **鍵が導けなかったとき**だけになった(`lockedOut(scope)`)。
51
+ */
52
+ import { type CosDict, decodeTextString, type PdfDocument } from 'normativepdf';
53
+ /**
54
+ * テキスト文字列(§7.9.2.2)の復号。**コアの 1 本を使う。**
55
+ *
56
+ * pdf-lib 版はここに自前の実装を持っており、`PDFDocEncoding` のバイト列からも
57
+ * 先頭の `ESC <lang> ESC` を落としていた。§7.9.2.2.2 は
58
+ * 「Escape sequences may appear anywhere in a **Unicode** text string」と書き、
59
+ * 要素 a) で「for strings encoded in UTF-16BE … for strings encoded in UTF-8」と
60
+ * 名指ししている。PDFDocEncoding は名指しされていない —— そして Table D.3 では
61
+ * バイト 0x1B は U+02D9(DOT ABOVE)なので、落としていたのは本文の文字だった。
62
+ * 再輸出しているのは、コアの版が上がってこの復号が変わったときに
63
+ * reader の試験が気づくようにするためである。
34
64
  */
35
- import { PDFDict, type PDFDocument } from 'pdf-lib';
65
+ export { decodeTextString };
36
66
  /**
37
67
  * One `BMC` / `BDC` / `EMC` operator, in content-stream order.
38
68
  *
@@ -66,16 +96,16 @@ export interface TextOperatorTally {
66
96
  textShowingOperators: number;
67
97
  /** `Do` on an Image XObject, plus `BI` inline images. */
68
98
  imageOperators: number;
69
- usedFonts: Map<string, PDFDict | null>;
99
+ usedFonts: Map<string, CosDict | null>;
70
100
  }
71
101
  /**
72
- * Decode a PDF *text string* (§7.9.2.2) from its raw bytes.
102
+ * この文書のページ数。**木に届かなかったときは `null`** を返す。
73
103
  *
74
- * Mirrors pdf-lib's `PDFString.decodeText` (UTF-16BE when the BOM is present,
75
- * else PDFDocEncoding) and adds the UTF-8 BOM that PDF 2.0 introduced, which
76
- * pdf-lib 1.x does not handle.
104
+ * 🔴 `0` を返さない。`0` は「ページが 1 つも無い木を読んだ」という観測結果であり、
105
+ * 「木を読めなかった」ではない。同じ数で両方を言うと、後者が前者の顔をする
106
+ * (このファイルの `scanPage` が `null` と空の観測を分けているのと同じ理由)。
77
107
  */
78
- export declare function decodeTextString(bytes: Uint8Array): string;
108
+ export declare function pageCountOf(doc: PdfDocument): Promise<number | null>;
79
109
  /**
80
110
  * Scan one page's content for marked-content operators, in stream order.
81
111
  *
@@ -87,17 +117,19 @@ export declare function decodeTextString(bytes: Uint8Array): string;
87
117
  * the #15 note); mis-resolving it would be a new and worse failure.
88
118
  *
89
119
  * @param pageIndex 0-based page index.
120
+ * @param lockedOut 暗号化されていて鍵が導けなかった(`lockedOut(scope)`)。
90
121
  */
91
- export declare function scanPageMarkedContent(doc: PDFDocument, pageIndex: number): MarkedContentEvent[] | null;
122
+ export declare function scanPageMarkedContent(doc: PdfDocument, pageIndex: number, lockedOut: boolean): Promise<MarkedContentEvent[] | null>;
92
123
  /**
93
124
  * The same scan, with the text-showing tally #21 needs kept as well.
94
125
  *
95
- * Returns `null` for the same reasons `scanPageMarkedContent` does — an
96
- * encrypted document, a missing or undecodable content stream. A `null` here is
97
- * "not observed", never "no text": the difference is the whole point of #21.
126
+ * Returns `null` for the same reasons `scanPageMarkedContent` does — a document
127
+ * whose key could not be derived, a missing or undecodable content stream. A
128
+ * `null` here is "not observed", never "no text": the difference is the whole
129
+ * point of #21.
98
130
  */
99
- export declare function scanPageTextOperators(doc: PDFDocument, pageIndex: number): {
131
+ export declare function scanPageTextOperators(doc: PdfDocument, pageIndex: number, lockedOut: boolean): Promise<{
100
132
  tally: TextOperatorTally;
101
133
  actualTextEntries: number;
102
- } | null;
134
+ } | null>;
103
135
  //# sourceMappingURL=content-stream-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"content-stream-service.d.ts","sourceRoot":"","sources":["../../src/services/content-stream-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAGL,OAAO,EACP,KAAK,WAAW,EAUjB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,GAAG,KAAK,CAAC;IACtB,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,yDAAyD;IACzD,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC;CACxC;AA6DD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAQ1D;AA2aD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,GAChB,kBAAkB,EAAE,GAAG,IAAI,CAE7B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,GAChB;IAAE,KAAK,EAAE,iBAAiB,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAOhE"}
1
+ {"version":3,"file":"content-stream-service.d.ts","sourceRoot":"","sources":["../../src/services/content-stream-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAcH,OAAO,EACL,KAAK,OAAO,EACZ,gBAAgB,EAGhB,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,GAAG,KAAK,CAAC;IACtB,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,yDAAyD;IACzD,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC,CAAC;CACxC;AAmfD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAI1E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAEtC;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC;IAAE,KAAK,EAAE,iBAAiB,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAOzE"}