@shuji-bonji/pdf-reader-mcp 0.13.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 +249 -4
- package/README.ja.md +11 -6
- package/README.md +13 -6
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- 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/page-renderer.d.ts +25 -0
- package/dist/services/page-renderer.d.ts.map +1 -1
- package/dist/services/page-renderer.js +160 -62
- package/dist/services/page-renderer.js.map +1 -1
- package/dist/services/page-renderer.worker.mjs +104 -0
- 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/reading-scope.d.ts +115 -0
- package/dist/services/reading-scope.d.ts.map +1 -0
- package/dist/services/reading-scope.js +123 -0
- package/dist/services/reading-scope.js.map +1 -0
- 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 +80 -16
- package/dist/services/validation-service.js.map +1 -1
- package/dist/tools/tier1/read-text.d.ts.map +1 -1
- package/dist/tools/tier1/read-text.js +49 -34
- package/dist/tools/tier1/read-text.js.map +1 -1
- package/dist/tools/tier1/read-url.d.ts.map +1 -1
- package/dist/tools/tier1/read-url.js +62 -38
- package/dist/tools/tier1/read-url.js.map +1 -1
- package/dist/tools/tier1/render-page.d.ts.map +1 -1
- package/dist/tools/tier1/render-page.js +2 -0
- package/dist/tools/tier1/render-page.js.map +1 -1
- package/dist/tools/tier1/search-text.d.ts.map +1 -1
- package/dist/tools/tier1/search-text.js +66 -55
- package/dist/tools/tier1/search-text.js.map +1 -1
- package/dist/tools/tier1/summarize.d.ts.map +1 -1
- package/dist/tools/tier1/summarize.js +71 -37
- package/dist/tools/tier1/summarize.js.map +1 -1
- package/dist/tools/tier2/extract-structured-text.d.ts.map +1 -1
- package/dist/tools/tier2/extract-structured-text.js +38 -28
- package/dist/tools/tier2/extract-structured-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/tools/tier3/compare-structure.d.ts.map +1 -1
- package/dist/tools/tier3/compare-structure.js +2 -0
- package/dist/tools/tier3/compare-structure.js.map +1 -1
- package/dist/tools/tier3/validate-tagged.d.ts.map +1 -1
- package/dist/tools/tier3/validate-tagged.js +2 -0
- package/dist/tools/tier3/validate-tagged.js.map +1 -1
- package/dist/types.d.ts +81 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +34 -2
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +54 -18
- package/dist/utils/formatter.js.map +1 -1
- package/package.json +5 -3
- 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,247 @@ 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
|
+
|
|
113
|
+
## [0.14.0] - 2026-08-30
|
|
114
|
+
|
|
115
|
+
Text-returning tools now say which of the readings behind their answer were
|
|
116
|
+
actually done. Output shapes change — read **Changed** before upgrading.
|
|
117
|
+
|
|
118
|
+
### Fixed
|
|
119
|
+
|
|
120
|
+
- **`read_url` returned an error for every input.** The bytes fetched from the
|
|
121
|
+
URL were handed to pdfjs and then, concurrently, to the extractability
|
|
122
|
+
observation. pdfjs takes ownership of the `Uint8Array` it is given and moves
|
|
123
|
+
its buffer to a worker, so the second reader saw zero bytes and reported
|
|
124
|
+
`Failed to parse PDF document (line:0 col:0 offset=0): No PDF header found`.
|
|
125
|
+
Measured over the 40-specimen smoke set: 40 of 40 calls were `isError`. Each
|
|
126
|
+
reader now gets its own copy of the bytes.
|
|
127
|
+
|
|
128
|
+
- **The error a caller received for an unreadable file was decided by a race.**
|
|
129
|
+
`read_text`, `read_url`, `search_text`, `summarize` and
|
|
130
|
+
`extract_structured_text` each ran two readings inside `Promise.all`, which
|
|
131
|
+
rejects with whichever rejected first. Twelve calls with the same file
|
|
132
|
+
returned `INVALID_PDF` ten times and `INTERNAL_ERROR` twice, with different
|
|
133
|
+
`hint` and `next_actions` each way. Taking the same golden twice, with
|
|
134
|
+
nothing changed, produced three differences.
|
|
135
|
+
|
|
136
|
+
- **A damaged file was reported as this server's fault.** pdf-lib's parse
|
|
137
|
+
failures (`Failed to parse ...`, `No PDF header found`,
|
|
138
|
+
`Expected instance of PDF...`) fell through to `INTERNAL_ERROR`; they are
|
|
139
|
+
`INVALID_PDF`.
|
|
140
|
+
|
|
141
|
+
- **A 3.4 KB file could stop the server for good.** `render_page` called PDFium
|
|
142
|
+
on the main thread, and PDFium runs synchronously inside WebAssembly. Two
|
|
143
|
+
files in the veraPDF corpus (`TWG test suite A018-pdfa2-pass-b.pdf` and
|
|
144
|
+
`-fail-b.pdf`) never came back: twenty minutes in, the process still had to be
|
|
145
|
+
killed. A timer set to fire every second during the call fired zero times —
|
|
146
|
+
the event loop was blocked, so no timeout written in JavaScript could have
|
|
147
|
+
interrupted it.
|
|
148
|
+
|
|
149
|
+
The cause is in the file, and it is not a violation. The page is filled with a
|
|
150
|
+
tiling pattern (ISO 32000-2 §8.7.3.1) whose `/YStep` is `-1.175e-38`. Table 74
|
|
151
|
+
says `XStep` and `YStep` "may be either positive or negative but shall not be
|
|
152
|
+
zero"; this is not zero. It is the smallest magnitude a float32 can hold, so
|
|
153
|
+
tiling 500 points at that step asks for more than 10^38 tiles.
|
|
154
|
+
|
|
155
|
+
Rendering now runs in a worker thread with a **20-second budget per page**
|
|
156
|
+
(`PDF_READER_RENDER_TIMEOUT_MS` overrides it, or `pageTimeoutMs` in-process).
|
|
157
|
+
`worker.terminate()` does stop a wedged PDFium — measured. Pages rendered
|
|
158
|
+
before the stuck one are still returned; the stuck page is named in `omitted`
|
|
159
|
+
with the reason; pages after it are reported separately as `not attempted`,
|
|
160
|
+
because "could not be rendered" and "never started" are different answers.
|
|
161
|
+
|
|
162
|
+
The worker is `src/services/page-renderer.worker.mjs` — plain JavaScript, not
|
|
163
|
+
TypeScript, and it imports nothing from `src`. Node runs it as it is: Node 20
|
|
164
|
+
has no type stripping and Node 22 does not enable it in every release, so a
|
|
165
|
+
`.ts` worker fails with `Unknown file extension ".ts"` (it did, on both CI Node
|
|
166
|
+
versions). For the same reason the worker only produces pixels; the BGRA-to-RGB
|
|
167
|
+
conversion, the downscale and the encoding stay on the calling side, with the
|
|
168
|
+
bitmap handed over as a transferable so nothing is copied. `npm run build`
|
|
169
|
+
copies the worker into `dist` (`scripts/copy-worker.mjs`), and a test fails if
|
|
170
|
+
that coupling is broken.
|
|
171
|
+
|
|
172
|
+
### Changed
|
|
173
|
+
|
|
174
|
+
- **Two readings, reported separately (#26).** Taking the characters off a page
|
|
175
|
+
(pdfjs) and observing whether those characters have a route to Unicode
|
|
176
|
+
(ISO 32000-2 §9.10.1, pdf-lib) are separate questions that fail separately.
|
|
177
|
+
Over 2,931 corpus files: 2,927 both succeeded, 3 had the text but not the
|
|
178
|
+
observation, and 1 had neither. In those 3 the tool returned an error and
|
|
179
|
+
**threw away text it had already extracted** — 13, 0 and 86 characters.
|
|
180
|
+
|
|
181
|
+
Every text-returning tool now carries `scope`:
|
|
182
|
+
|
|
183
|
+
```jsonc
|
|
184
|
+
{ "scope": { "textExtraction": { "status": "read" },
|
|
185
|
+
"extractabilityObservation": {
|
|
186
|
+
"status": "failed", "code": "INVALID_PDF", "reason": "..." } },
|
|
187
|
+
"pages": [ … ] }
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Only when *neither* reading could be done is the call an error, and it then
|
|
191
|
+
names both reasons in `detail.cause`.
|
|
192
|
+
|
|
193
|
+
- **Output shapes.** `read_text` and `read_url` return `{ scope, pages }` where
|
|
194
|
+
they returned a bare array of pages. `search_text`,
|
|
195
|
+
`extract_structured_text` and `summarize` gain `scope`.
|
|
196
|
+
|
|
197
|
+
- **`null` where a reading did not happen — never `0`, `false` or `""`.**
|
|
198
|
+
"Not read" and "read and found nothing" are different answers.
|
|
199
|
+
|
|
200
|
+
| Field | `null` means | The observed answer |
|
|
201
|
+
| --- | --- | --- |
|
|
202
|
+
| `PageText.text` | the extraction did not run | `""` — it ran and produced no characters |
|
|
203
|
+
| `SearchResult.totalMatches` / `matches` | the search did not run | `0` / `[]` — searched, nothing found |
|
|
204
|
+
| `StructuredTextResult.isTagged` / `elements` | the structure tree was not read | `false` / `[]` — read, no tags |
|
|
205
|
+
| `PdfSummary.metadata` / `textPreview` / `imageCount` / `hasText` / `textExtractability` / `unreadablePages` | that reading did not run | the value it measured |
|
|
206
|
+
|
|
207
|
+
When the observation could not run, pages carry no `extractability` field at
|
|
208
|
+
all rather than one filled with zeros: `0` fonts observed and "not observed"
|
|
209
|
+
are different answers.
|
|
210
|
+
|
|
211
|
+
- **`summarize.next` stays silent about a premise it did not observe.** It used
|
|
212
|
+
to derive its suggestions from metadata; with metadata unread it now suggests
|
|
213
|
+
nothing rather than reasoning from absence.
|
|
214
|
+
|
|
215
|
+
- **`validate_tagged` no longer passes a check it could not make.** TAG-005
|
|
216
|
+
judges Figure tags against the number of images the page draws. When that
|
|
217
|
+
count could not be observed, the check previously fell into the branch for
|
|
218
|
+
"no images", which counted as a pass. It is now excluded from `totalChecks`
|
|
219
|
+
and listed in the new `notChecked` field with the reason.
|
|
220
|
+
|
|
221
|
+
- **`compare_structure` names which file it could not read.** The comparison
|
|
222
|
+
still needs both files, but the error says which of the two failed, and that
|
|
223
|
+
the other one was fine.
|
|
224
|
+
|
|
225
|
+
- **The message for a password-protected file describes what happened.** It
|
|
226
|
+
said "pdf-reader-mcp does not support encrypted PDFs"; the text cannot be
|
|
227
|
+
extracted because the file encryption key is derived from the user password
|
|
228
|
+
(ISO 32000-2 §7.6.4.3.2), while the structure observation continues over what
|
|
229
|
+
is not encrypted.
|
|
230
|
+
|
|
231
|
+
### Added
|
|
232
|
+
|
|
233
|
+
- `src/services/reading-scope.ts` — the shared shape for the above.
|
|
234
|
+
- `tests/e2e/15-reading-scope.test.ts` — 15 tests pinning all four combinations
|
|
235
|
+
of the two readings, including that twelve identical calls return one code.
|
|
236
|
+
- `scripts/probe-read-halves.mjs` — runs the two readings separately and counts
|
|
237
|
+
the four combinations over a corpus.
|
|
238
|
+
- `scripts/golden-specimens-halves.mjs` — one specimen per combination. The
|
|
239
|
+
`fail/ok` case did not exist anywhere in the 2,931-file corpus; it needs a
|
|
240
|
+
document with a non-empty user password, so it is built with qpdf under
|
|
241
|
+
`--static-id` to keep the bytes identical run to run.
|
|
242
|
+
- `scripts/golden.mjs` — freezes the output of all 19 tools across 23 calls, so
|
|
243
|
+
the pdf-lib removal that follows can be attributed difference by difference.
|
|
244
|
+
- `scripts/golden-specimens-render.mjs` and
|
|
245
|
+
`tests/e2e/16-render-timeout.test.ts` — a three-page specimen whose second
|
|
246
|
+
page never finishes rasterising, built from the clause rather than copied from
|
|
247
|
+
the corpus, plus the four tests that pin the behaviour above.
|
|
248
|
+
|
|
8
249
|
## [0.13.0] - 2026-08-27
|
|
9
250
|
|
|
10
251
|
Infrastructure only: no tool gained or lost a capability, and no tool's output
|
|
@@ -31,10 +272,14 @@ changed. Four things reach callers — read **Changed** before upgrading.
|
|
|
31
272
|
- **`inputSchema` in `tools/list`**: `$schema` is now
|
|
32
273
|
`https://json-schema.org/draft/2020-12/schema` (was draft-07) for all 19
|
|
33
274
|
tools. `additionalProperties: false` is unchanged in the response — what
|
|
34
|
-
changed is that it is now true of the running server.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
275
|
+
changed is that it is now true of the running server. One bound moved:
|
|
276
|
+
`locate_objects`' `object_numbers` items now carry
|
|
277
|
+
`maximum: 9007199254740991` alongside `minimum: 1` — zod 4 writes the safe
|
|
278
|
+
integer bound that zod 3 left out. It is the only property in the 19 tools
|
|
279
|
+
whose schema body changed. Tool names, descriptions and `required` are
|
|
280
|
+
unchanged — measured tool by tool against 0.12.0 with
|
|
281
|
+
`scripts/tools-list-snapshot.mjs`, which speaks raw JSON-RPC over stdio
|
|
282
|
+
rather than using an SDK client.
|
|
38
283
|
- `zod` moves from `^3.23.8` to `^4.2.0` — the version all four servers in the
|
|
39
284
|
family now share. `typescript` moves to `^7.0.2` (a devDependency).
|
|
40
285
|
|
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)
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,12 @@ What it does NOT do:
|
|
|
45
45
|
therefore never on its own evidence that a page has no text. When a page cannot be read as
|
|
46
46
|
text, render_page rasterises it (PDFium-WASM, optional dependency) so a vision model can
|
|
47
47
|
read the pixels instead.
|
|
48
|
+
- No collapsing of two readings into one verdict. Taking the characters off a page and
|
|
49
|
+
observing whether those characters have a route to Unicode are separate readings that
|
|
50
|
+
can fail separately, so every text-returning tool reports which of them were done under
|
|
51
|
+
\`scope\`, and a field whose reading did not happen is \`null\` — never zero, false or an
|
|
52
|
+
empty string. "Not read" and "read and found nothing" are different answers, and this
|
|
53
|
+
server keeps them apart.
|
|
48
54
|
|
|
49
55
|
It DOES map content to coordinates: locate_objects turns an object number into a page and a
|
|
50
56
|
rectangle, and extract_structured_text with include_bbox does the same for a structure element.
|
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,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE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AM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,GAAG,WAAW,KAAK,cAAc,oBAAoB,CAAC,CAAC;AACvE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -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,CAC5C,GAAgB,EAChB,SAAkB;IAElB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACnD,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,CAA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E,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5C,yBAAyB,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
|
-
|
|
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"}
|