@shuji-bonji/pdf-reader-mcp 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/README.ja.md +11 -6
- package/README.md +13 -6
- package/dist/services/actual-text-service.d.ts +4 -3
- package/dist/services/actual-text-service.d.ts.map +1 -1
- package/dist/services/actual-text-service.js +5 -4
- package/dist/services/actual-text-service.js.map +1 -1
- package/dist/services/content-stream-service.d.ts +45 -13
- package/dist/services/content-stream-service.d.ts.map +1 -1
- package/dist/services/content-stream-service.js +209 -174
- package/dist/services/content-stream-service.js.map +1 -1
- package/dist/services/font-service.d.ts +35 -0
- package/dist/services/font-service.d.ts.map +1 -0
- package/dist/services/font-service.js +127 -0
- package/dist/services/font-service.js.map +1 -0
- package/dist/services/object-locator.d.ts.map +1 -1
- package/dist/services/object-locator.js +163 -107
- package/dist/services/object-locator.js.map +1 -1
- package/dist/services/pdfjs-service.d.ts +18 -14
- package/dist/services/pdfjs-service.d.ts.map +1 -1
- package/dist/services/pdfjs-service.js +19 -14
- package/dist/services/pdfjs-service.js.map +1 -1
- package/dist/services/recover-service.d.ts +64 -0
- package/dist/services/recover-service.d.ts.map +1 -0
- package/dist/services/recover-service.js +104 -0
- package/dist/services/recover-service.js.map +1 -0
- package/dist/services/signature-service.d.ts +28 -0
- package/dist/services/signature-service.d.ts.map +1 -0
- package/dist/services/signature-service.js +200 -0
- package/dist/services/signature-service.js.map +1 -0
- package/dist/services/struct-tree-service.d.ts +0 -6
- package/dist/services/struct-tree-service.d.ts.map +1 -1
- package/dist/services/struct-tree-service.js +56 -49
- package/dist/services/struct-tree-service.js.map +1 -1
- package/dist/services/struct-tree-walker.d.ts +13 -4
- package/dist/services/struct-tree-walker.d.ts.map +1 -1
- package/dist/services/struct-tree-walker.js +133 -87
- package/dist/services/struct-tree-walker.js.map +1 -1
- package/dist/services/structure-service.d.ts +57 -0
- package/dist/services/structure-service.d.ts.map +1 -0
- package/dist/services/structure-service.js +237 -0
- package/dist/services/structure-service.js.map +1 -0
- package/dist/services/text-extractability-service.d.ts +11 -0
- package/dist/services/text-extractability-service.d.ts.map +1 -1
- package/dist/services/text-extractability-service.js +83 -52
- package/dist/services/text-extractability-service.js.map +1 -1
- package/dist/services/validation-service.d.ts.map +1 -1
- package/dist/services/validation-service.js +4 -3
- package/dist/services/validation-service.js.map +1 -1
- package/dist/tools/tier1/search-text.js +1 -1
- package/dist/tools/tier1/search-text.js.map +1 -1
- package/dist/tools/tier2/inspect-fonts.js +2 -2
- package/dist/tools/tier2/inspect-fonts.js.map +1 -1
- package/dist/tools/tier2/inspect-signatures.js +1 -1
- package/dist/tools/tier2/inspect-signatures.js.map +1 -1
- package/dist/tools/tier2/inspect-structure.d.ts.map +1 -1
- package/dist/tools/tier2/inspect-structure.js +9 -2
- package/dist/tools/tier2/inspect-structure.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +24 -5
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +13 -1
- package/dist/utils/formatter.js.map +1 -1
- package/package.json +4 -2
- package/dist/services/pdflib-service.d.ts +0 -81
- package/dist/services/pdflib-service.d.ts.map +0 -1
- package/dist/services/pdflib-service.js +0 -504
- package/dist/services/pdflib-service.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,111 @@ 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.0] - 2026-08-31
|
|
9
|
+
|
|
10
|
+
pdf-lib is gone. Every reading that used it now goes through
|
|
11
|
+
[`@normativepdf/recover`](https://www.npmjs.com/package/@normativepdf/recover),
|
|
12
|
+
which reports **how far it got** instead of returning a partial answer silently.
|
|
13
|
+
`inspect_structure` changes shape — read **Changed** before upgrading.
|
|
14
|
+
|
|
15
|
+
The removal was measured against a frozen baseline of 2,942 specimens ×
|
|
16
|
+
67,666 tool calls (veraPDF corpus, pdf20examples, and this repository's own
|
|
17
|
+
specimens), in four stages. Every difference in every stage is attributed in
|
|
18
|
+
`docs/handoff/pdflib-removal.md`; none of them is a wrong `pass`.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **BREAKING — `inspect_structure` reports COS types, not library class names.**
|
|
23
|
+
`objectStats.byType` and `catalog[].type` used to carry pdf-lib's internal
|
|
24
|
+
class names (`PDFCatalog`, `PDFPageTree`, `PDFPageLeaf`, `PDFRawStream`,
|
|
25
|
+
`PDFNumber`, `PDFInvalidObject`). None of those is a type in ISO 32000-2 §7.3 —
|
|
26
|
+
they are how pdf-lib chose to model the file — so the vocabulary could not
|
|
27
|
+
survive the removal. It is now the ten COS types of §7.3: `dict`, `stream`,
|
|
28
|
+
`array`, `name`, `string`, `integer`, `real`, `boolean`, `null`, `ref`.
|
|
29
|
+
|
|
30
|
+
What pdf-lib's `PDFCatalog` / `PDFPageTree` / `PDFPageLeaf` actually carried
|
|
31
|
+
was the dictionary's `/Type`, so that is now reported separately as
|
|
32
|
+
`objectStats.byDocType` (`Catalog`, `Pages`, `Page`, `Font`, `ObjStm`,
|
|
33
|
+
`XRef`, …). Counting the two in one field made "51,237 dictionaries" and
|
|
34
|
+
"13,001 pages" compete for the same slot.
|
|
35
|
+
|
|
36
|
+
`PDFNumber` folded integers and reals together; R-7.3.3-6 ("A real number
|
|
37
|
+
shall not be present when an integer is expected") asks for the distinction,
|
|
38
|
+
so `integer` and `real` are counted apart.
|
|
39
|
+
|
|
40
|
+
- **BREAKING — `inspect_structure` no longer counts objects the cross-reference
|
|
41
|
+
table does not name.** pdf-lib scanned the whole file, so a `N 0 obj` written
|
|
42
|
+
into the bytes but absent from the table was counted. 3,308 calls change.
|
|
43
|
+
Checked against an independent implementation on seven specimens:
|
|
44
|
+
`qpdf --show-object=N` answers `null` for every one of them.
|
|
45
|
+
|
|
46
|
+
- **`inspect_signatures` no longer says "No AcroForm found" when it could not
|
|
47
|
+
look.** When a document is encrypted and the key cannot be derived from the
|
|
48
|
+
empty user password (§7.6.4.3.2), not one indirect object is readable — the
|
|
49
|
+
catalogue included. Reporting "0 signature fields" there tells the caller a
|
|
50
|
+
signed document is unsigned. `inspect_structure` and `inspect_fonts` said the
|
|
51
|
+
same kind of thing with page and font counts; all three now name the reason.
|
|
52
|
+
|
|
53
|
+
- **Encrypted documents whose key *can* be derived are now read.** pdf-lib was
|
|
54
|
+
loaded with `ignoreEncryption`, which ignores encryption rather than undoing
|
|
55
|
+
it, so a document with an empty user password was treated as unreadable.
|
|
56
|
+
§7.6.4.3.2 says to try the empty password first; `@normativepdf/recover` does,
|
|
57
|
+
and decrypts. `read_text` on such a file now returns its `/ActualText`
|
|
58
|
+
replacements (§14.9.4) instead of raw glyphs, and `search_text` finds them.
|
|
59
|
+
|
|
60
|
+
- **Text strings are decoded by the core's one implementation.** The private
|
|
61
|
+
copy in this package stripped a leading `ESC <lang> ESC` sequence from
|
|
62
|
+
PDFDocEncoded bytes as well. §7.9.2.2.2 places language escapes in *Unicode*
|
|
63
|
+
text strings and names only UTF-16BE and UTF-8; in PDFDocEncoding, byte 0x1B
|
|
64
|
+
is U+02D9 (Table D.3), so what was being stripped was content.
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
|
|
68
|
+
- **`objectStats.unreadable`** — objects the cross-reference table names but
|
|
69
|
+
that could not be read. Counted apart from `totalObjects`, because folding
|
|
70
|
+
them in produces a number that is neither "how many were read" nor "how many
|
|
71
|
+
the table names". `0` is the result of looking, not the absence of looking.
|
|
72
|
+
|
|
73
|
+
- **Cycle guards on the signature field walk.** pdf-lib's `getAllFields()` has
|
|
74
|
+
none, so a document whose `/Kids` point back at an ancestor never terminates —
|
|
75
|
+
and a walk that does not terminate is not an exception: it is caught by no
|
|
76
|
+
`try`/`catch` and by no test timeout. A specimen is checked in.
|
|
77
|
+
|
|
78
|
+
### Fixed
|
|
79
|
+
|
|
80
|
+
- **Embedded fonts reported as not embedded.** pdf-lib's `PDFDict.has` misses
|
|
81
|
+
keys that come from an object stream (`get` finds them, `has` does not), so
|
|
82
|
+
`inspect_fonts` said "not embedded" for fonts whose `FontDescriptor` carries a
|
|
83
|
+
`FontFile*`. Seven calls change.
|
|
84
|
+
|
|
85
|
+
- **`#xx` escapes in name objects are resolved** (§7.3.5). `/BaseFont` values
|
|
86
|
+
such as `FreeMonoBold#c4` were reported verbatim rather than decoded.
|
|
87
|
+
|
|
88
|
+
- **Documents pdf-lib could not open at all are now read.** Ten tool calls
|
|
89
|
+
across two specimens (a header with no version number, `%PDF-`) stop being
|
|
90
|
+
errors. Over the whole corpus, `isError` falls from 75 to 61 and **no call
|
|
91
|
+
became an error that was not one before**.
|
|
92
|
+
|
|
93
|
+
### Removed
|
|
94
|
+
|
|
95
|
+
- `pdf-lib` as a runtime dependency. It remains in `devDependencies`, where the
|
|
96
|
+
two test-fixture generators use it. `npm ls --omit=dev pdf-lib` reports
|
|
97
|
+
`(empty)`.
|
|
98
|
+
|
|
99
|
+
### Known limitations
|
|
100
|
+
|
|
101
|
+
- `inspect_structure` and the other Tier 2 tools do not yet report the
|
|
102
|
+
`ReadingScope` that `read_text` and friends gained in 0.14.0. When the newest
|
|
103
|
+
cross-reference section cannot be read and an older one is used instead, the
|
|
104
|
+
library says so but this server does not pass it on — measured on one
|
|
105
|
+
specimen, where a catalogue entry added by an incremental update disappears
|
|
106
|
+
from the answer without a word.
|
|
107
|
+
- `normativepdf` does not implement `/LZWDecode` (§7.4.4), and its inflate
|
|
108
|
+
refuses a stream with trailing bytes after the ADLER32 checksum. Three
|
|
109
|
+
specimens whose content streams pdf-lib could decode are now reported as
|
|
110
|
+
`not_observed` rather than as text-free pages. Both are gaps in the core, not
|
|
111
|
+
in this server; neither turns a failed check into a passing one.
|
|
112
|
+
|
|
8
113
|
## [0.14.0] - 2026-08-30
|
|
9
114
|
|
|
10
115
|
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
|
-
- **
|
|
369
|
-
|
|
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:
|
|
377
|
-
npm run test:e2e # E2E のみ(
|
|
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
|
-
│ │ ├──
|
|
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 (
|
|
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
|
-
- **
|
|
375
|
-
-
|
|
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:
|
|
383
|
-
npm run test:e2e # E2E tests only (
|
|
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
|
-
│ │ ├──
|
|
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 (
|
|
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 {
|
|
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:
|
|
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:
|
|
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,
|
|
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,
|
|
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,CAAC,KAAK,UAAU,wBAAwB,C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AAI,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
|
-
|
|
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,
|
|
99
|
+
usedFonts: Map<string, CosDict | null>;
|
|
70
100
|
}
|
|
71
101
|
/**
|
|
72
|
-
*
|
|
102
|
+
* この文書のページ数。**木に届かなかったときは `null`** を返す。
|
|
73
103
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
104
|
+
* 🔴 `0` を返さない。`0` は「ページが 1 つも無い木を読んだ」という観測結果であり、
|
|
105
|
+
* 「木を読めなかった」ではない。同じ数で両方を言うと、後者が前者の顔をする
|
|
106
|
+
* (このファイルの `scanPage` が `null` と空の観測を分けているのと同じ理由)。
|
|
77
107
|
*/
|
|
78
|
-
export declare function
|
|
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:
|
|
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 —
|
|
96
|
-
*
|
|
97
|
-
* "not observed", never "no text": the difference is the whole
|
|
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:
|
|
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
|
|
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"}
|