@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.
- package/CHANGELOG.md +131 -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/tier1/summarize.d.ts.map +1 -1
- package/dist/tools/tier1/summarize.js +16 -4
- package/dist/tools/tier1/summarize.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
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* so once merged there is no way to recover that page 1's `L` and page 2's `L`
|
|
28
28
|
* are the same list. Walking the document tree keeps them whole.
|
|
29
29
|
*/
|
|
30
|
-
import {
|
|
30
|
+
import { asArray, asDict, asRef, get, nameOf, numberOf, resolved, textOf, } from '@normativepdf/recover';
|
|
31
31
|
/**
|
|
32
32
|
* Build the pdfjs marked-content id for a `/Pg` + `/MCID` pair.
|
|
33
33
|
*
|
|
@@ -43,32 +43,41 @@ import { PDFArray, PDFDict, PDFHexString, PDFName, PDFNumber, PDFRef, PDFString,
|
|
|
43
43
|
export function pdfjsMarkedContentId(ref) {
|
|
44
44
|
return `p${ref.pageObjNum}R_mc${ref.mcid}`;
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a value that may be an indirect reference.
|
|
48
|
+
*
|
|
49
|
+
* 読めなかったときは `null` に畳む。pdf-lib 版の `context.lookup` は投げるか
|
|
50
|
+
* `undefined` を返していたので、ここは同じ範囲である —— **読めなかったことを
|
|
51
|
+
* 申告したい場所ではこれを使わない**(`tryResolve` が `unreadable` を返す)。
|
|
52
|
+
*/
|
|
53
|
+
export async function deref(doc, obj) {
|
|
54
|
+
return resolved(doc, obj);
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
51
|
-
* Read a text-ish value (
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
57
|
+
* Read a text-ish value (a string object) from a dictionary.
|
|
58
|
+
*
|
|
59
|
+
* **鍵が導けなかった文書は何も返さない。** ISO 32000-2 §7.6.2 が暗号化するのは
|
|
60
|
+
* *文字列とストリーム*だけなので、構造木そのものは歩ける —— 名前も数も参照も
|
|
61
|
+
* 平文である —— が、その中の文字列は暗号文である。
|
|
62
|
+
*
|
|
63
|
+
* 暗号文をそのまま返すのは、何も返さないより悪い: `PDF32000_2008.pdf`
|
|
64
|
+
* (所有者パスワードつき・どの閲覧器でも読める)で数えると、木は
|
|
65
|
+
* `/ActualText` を **18026 件**持ち、そのどれもが読めないバイト列だった。
|
|
66
|
+
* #18 以降そのエントリはページの文字を*置き換える*ので、そういう文書すべての
|
|
67
|
+
* 本文が化けることになる。
|
|
68
|
+
*
|
|
69
|
+
* 🔴 **見るのは「暗号化されているか」ではなく「鍵が導けたか」である**
|
|
70
|
+
* (S3・2026-08-31 に直した)。pdf-lib は `ignoreEncryption` で開いていて
|
|
71
|
+
* 復号しなかったので、`/Encrypt` があれば必ず暗号文だった。recover は鍵が
|
|
72
|
+
* 導ければ復号する(ADR-0008)ので、利用者パスワードが空の文書では
|
|
73
|
+
* `/ActualText` は平文で返る。`scope.encrypted` で切ると、読めている文字を
|
|
74
|
+
* 捨てたうえで `search_text` が「見つからなかった」と自信を持って答える ——
|
|
75
|
+
* 実測 `tests/fixtures/encrypted-actualtext.pdf` の "Difficult"。
|
|
64
76
|
*/
|
|
65
|
-
function textEntry(doc, dict, key) {
|
|
66
|
-
if (
|
|
77
|
+
async function textEntry(doc, lockedOut, dict, key) {
|
|
78
|
+
if (lockedOut)
|
|
67
79
|
return null;
|
|
68
|
-
|
|
69
|
-
if (value instanceof PDFString || value instanceof PDFHexString)
|
|
70
|
-
return value.decodeText();
|
|
71
|
-
return null;
|
|
80
|
+
return textOf(await resolved(doc, get(dict, key)));
|
|
72
81
|
}
|
|
73
82
|
// ─── Layout attributes (Issue #20, stage 2) ─────────────────────────────────
|
|
74
83
|
/**
|
|
@@ -78,23 +87,31 @@ function textEntry(doc, dict, key) {
|
|
|
78
87
|
* reading it anyway would be borrowing a key across namespaces.
|
|
79
88
|
*/
|
|
80
89
|
const LAYOUT_OWNER = 'Layout';
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 構造木を降りる深さの上限。
|
|
92
|
+
*
|
|
93
|
+
* 🔴 参照番号の見張り(下の `ancestors`)だけでは足りない。**直接オブジェクトで
|
|
94
|
+
* 書かれた枝は番号を持たない**ので見張りに載らず、そこに循環があると止まらない。
|
|
95
|
+
* 止まらないのは例外ではないので、try/catch にも試験の timeout にも掛からない ——
|
|
96
|
+
* マイクロタスクが詰まってタイマーすら動かず、サーバごと応答しなくなる
|
|
97
|
+
* (0.14.0 の `render_page` と同じ形)。
|
|
98
|
+
*
|
|
99
|
+
* 200 は §14.7 の木としては十分深い。PDF/UA の実文書はふつう 20 を超えない。
|
|
100
|
+
*/
|
|
101
|
+
const MAX_STRUCT_DEPTH = 200;
|
|
102
|
+
async function bboxOfAttributeObject(doc, value) {
|
|
103
|
+
const dict = asDict(await resolved(doc, value ?? undefined));
|
|
104
|
+
if (!dict)
|
|
84
105
|
return null;
|
|
85
|
-
|
|
86
|
-
if (!(owner instanceof PDFName) || owner.decodeText() !== LAYOUT_OWNER)
|
|
106
|
+
if (nameOf(await resolved(doc, get(dict, 'O'))) !== LAYOUT_OWNER)
|
|
87
107
|
return null;
|
|
88
|
-
const bbox =
|
|
89
|
-
if (
|
|
108
|
+
const bbox = asArray(await resolved(doc, get(dict, 'BBox')));
|
|
109
|
+
if (bbox?.items.length !== 4)
|
|
90
110
|
return null;
|
|
91
111
|
const numbers = [];
|
|
92
|
-
for (
|
|
93
|
-
const
|
|
94
|
-
if (!(
|
|
95
|
-
return null;
|
|
96
|
-
const n = entry.asNumber();
|
|
97
|
-
if (!Number.isFinite(n))
|
|
112
|
+
for (const item of bbox.items) {
|
|
113
|
+
const n = numberOf(await resolved(doc, item));
|
|
114
|
+
if (n === null || !Number.isFinite(n))
|
|
98
115
|
return null;
|
|
99
116
|
numbers.push(n);
|
|
100
117
|
}
|
|
@@ -114,39 +131,50 @@ function bboxOfAttributeObject(doc, value) {
|
|
|
114
131
|
* present and a given attribute is specified by both, the one specified by the A
|
|
115
132
|
* entry shall take precedence."
|
|
116
133
|
*/
|
|
117
|
-
function layoutBBoxOf(doc, dict, classMap) {
|
|
118
|
-
const fromEntry = (value, resolve) => {
|
|
119
|
-
const entry =
|
|
120
|
-
const
|
|
134
|
+
async function layoutBBoxOf(doc, dict, classMap) {
|
|
135
|
+
const fromEntry = async (value, resolve) => {
|
|
136
|
+
const entry = await resolved(doc, value);
|
|
137
|
+
const array = asArray(entry);
|
|
138
|
+
const candidates = array ? [...array.items] : [entry];
|
|
121
139
|
let found = null;
|
|
122
140
|
for (const candidate of candidates) {
|
|
141
|
+
if (candidate === null)
|
|
142
|
+
continue;
|
|
123
143
|
// Revision numbers sit between the objects; they are not attribute objects.
|
|
124
|
-
if (
|
|
144
|
+
if (numberOf(await resolved(doc, candidate)) !== null)
|
|
125
145
|
continue;
|
|
126
|
-
const bbox = bboxOfAttributeObject(doc, resolve(candidate));
|
|
146
|
+
const bbox = await bboxOfAttributeObject(doc, await resolve(candidate));
|
|
127
147
|
if (bbox)
|
|
128
148
|
found = bbox;
|
|
129
149
|
}
|
|
130
150
|
return found;
|
|
131
151
|
};
|
|
132
|
-
const fromA = fromEntry(
|
|
152
|
+
const fromA = await fromEntry(get(dict, 'A'), async (v) => v);
|
|
133
153
|
if (fromA)
|
|
134
154
|
return fromA;
|
|
135
155
|
if (!classMap)
|
|
136
156
|
return null;
|
|
137
|
-
return fromEntry(
|
|
138
|
-
const
|
|
139
|
-
return
|
|
157
|
+
return fromEntry(get(dict, 'C'), async (name) => {
|
|
158
|
+
const named = nameOf(await resolved(doc, name));
|
|
159
|
+
return named === null ? null : (get(classMap, named) ?? null);
|
|
140
160
|
});
|
|
141
161
|
}
|
|
142
162
|
/** Normalise `/K` — it may be absent, a single object, or an array. */
|
|
143
|
-
function kidsOf(doc, dict) {
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
async function kidsOf(doc, dict) {
|
|
164
|
+
// 🔴 `/K` の**生の値**も要る。要素が参照なら、その参照番号が巡回の見張りになる
|
|
165
|
+
// (recover の resolve は呼ぶたびに値を作るので、オブジェクト同一性では止まらない)。
|
|
166
|
+
const raw = get(dict, 'K');
|
|
167
|
+
const array = asArray(raw);
|
|
168
|
+
if (array)
|
|
169
|
+
return [...array.items];
|
|
170
|
+
const k = await resolved(doc, raw);
|
|
171
|
+
if (k === null)
|
|
146
172
|
return [];
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
const resolvedArray = asArray(k);
|
|
174
|
+
if (resolvedArray)
|
|
175
|
+
return [...resolvedArray.items];
|
|
176
|
+
// 参照 1 個のときは、番号を残すために生の値を返す
|
|
177
|
+
return [raw ?? k];
|
|
150
178
|
}
|
|
151
179
|
/**
|
|
152
180
|
* Walk one structure element.
|
|
@@ -162,39 +190,49 @@ function kidsOf(doc, dict) {
|
|
|
162
190
|
*
|
|
163
191
|
* `/Pg` is inherited: an element without one uses its nearest ancestor's.
|
|
164
192
|
*/
|
|
165
|
-
function walkElement(doc, dict, inheritedPg, classMap
|
|
166
|
-
|
|
167
|
-
|
|
193
|
+
async function walkElement(doc, lockedOut, dict, inheritedPg, classMap,
|
|
194
|
+
/**
|
|
195
|
+
* この要素までに通った参照番号(**この枝の祖先だけ**)。
|
|
196
|
+
*
|
|
197
|
+
* 🔴 pdf-lib 版には巡回の見張りが無く、`/K` が循環している文書では
|
|
198
|
+
* 再帰が止まらなかった。番号で見張るのは、recover の `resolve` が呼ぶたびに
|
|
199
|
+
* 値を作るのでオブジェクト同一性では止まらないためである(verify で同じ轍)。
|
|
200
|
+
* 木全体ではなく**枝**で見張るので、非循環の文書では出力が 1 バイトも変わらない。
|
|
201
|
+
*/
|
|
202
|
+
ancestors, depth) {
|
|
203
|
+
if (depth > MAX_STRUCT_DEPTH)
|
|
168
204
|
return null;
|
|
169
|
-
const
|
|
170
|
-
|
|
205
|
+
const role = nameOf(await resolved(doc, get(dict, 'S')));
|
|
206
|
+
if (role === null)
|
|
207
|
+
return null;
|
|
208
|
+
const pg = asRef(get(dict, 'Pg')) ?? inheritedPg;
|
|
171
209
|
const element = {
|
|
172
|
-
role
|
|
173
|
-
actualText: textEntry(doc, dict, 'ActualText'),
|
|
174
|
-
alt: textEntry(doc, dict, 'Alt'),
|
|
175
|
-
lang: textEntry(doc, dict, 'Lang'),
|
|
210
|
+
role,
|
|
211
|
+
actualText: await textEntry(doc, lockedOut, dict, 'ActualText'),
|
|
212
|
+
alt: await textEntry(doc, lockedOut, dict, 'Alt'),
|
|
213
|
+
lang: await textEntry(doc, lockedOut, dict, 'Lang'),
|
|
176
214
|
contentRefs: [],
|
|
177
215
|
children: [],
|
|
178
|
-
layoutBBox: layoutBBoxOf(doc, dict, classMap),
|
|
216
|
+
layoutBBox: await layoutBBoxOf(doc, dict, classMap),
|
|
179
217
|
};
|
|
180
|
-
for (const kid of kidsOf(doc, dict)) {
|
|
218
|
+
for (const kid of await kidsOf(doc, dict)) {
|
|
181
219
|
// An MCID written directly, on this element's page.
|
|
182
|
-
|
|
220
|
+
const direct = numberOf(kid);
|
|
221
|
+
if (direct !== null) {
|
|
183
222
|
if (pg)
|
|
184
|
-
element.contentRefs.push({ pageObjNum: pg.objectNumber, mcid:
|
|
223
|
+
element.contentRefs.push({ pageObjNum: pg.objectNumber, mcid: direct });
|
|
185
224
|
continue;
|
|
186
225
|
}
|
|
187
|
-
const
|
|
188
|
-
|
|
226
|
+
const kidRef = asRef(kid);
|
|
227
|
+
const child = asDict(await resolved(doc, kid));
|
|
228
|
+
if (!child)
|
|
189
229
|
continue;
|
|
190
|
-
const
|
|
191
|
-
const typeName = type instanceof PDFName ? type.decodeText() : null;
|
|
230
|
+
const typeName = nameOf(get(child, 'Type'));
|
|
192
231
|
if (typeName === 'MCR') {
|
|
193
|
-
const mcid =
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
element.contentRefs.push({ pageObjNum: mcrPg.objectNumber, mcid: mcid.asNumber() });
|
|
232
|
+
const mcid = numberOf(await resolved(doc, get(child, 'MCID')));
|
|
233
|
+
const mcrPg = asRef(get(child, 'Pg')) ?? pg;
|
|
234
|
+
if (mcid !== null && mcrPg) {
|
|
235
|
+
element.contentRefs.push({ pageObjNum: mcrPg.objectNumber, mcid });
|
|
198
236
|
}
|
|
199
237
|
continue;
|
|
200
238
|
}
|
|
@@ -204,10 +242,13 @@ function walkElement(doc, dict, inheritedPg, classMap) {
|
|
|
204
242
|
// Anything with an /S is a child structure element. Checking /S rather than
|
|
205
243
|
// Type == StructElem on purpose: Type is optional in practice and plenty of
|
|
206
244
|
// producers omit it.
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
245
|
+
if (get(child, 'S') !== undefined) {
|
|
246
|
+
if (kidRef && ancestors.has(kidRef.objectNumber))
|
|
247
|
+
continue; // 循環(§14.7.2 は木を求める)
|
|
248
|
+
const next = kidRef ? new Set(ancestors).add(kidRef.objectNumber) : ancestors;
|
|
249
|
+
const walked = await walkElement(doc, lockedOut, child, pg, classMap, next, depth + 1);
|
|
250
|
+
if (walked)
|
|
251
|
+
element.children.push(walked);
|
|
211
252
|
}
|
|
212
253
|
}
|
|
213
254
|
return element;
|
|
@@ -221,20 +262,25 @@ function walkElement(doc, dict, inheritedPg, classMap) {
|
|
|
221
262
|
*
|
|
222
263
|
* Note this reads only `StructTreeRoot`; it needs neither `/ParentTree` nor
|
|
223
264
|
* `/StructParents`, which pdfjs's per-page `getStructTree()` does require.
|
|
265
|
+
*
|
|
266
|
+
* @param lockedOut 暗号化されていて鍵が導けなかった(`lockedOut(scope)`)。
|
|
267
|
+
* 木の形は歩けるが、その中の文字列は返さない(`textEntry`)。
|
|
224
268
|
*/
|
|
225
|
-
export function walkStructTree(doc) {
|
|
226
|
-
const
|
|
227
|
-
|
|
269
|
+
export async function walkStructTree(doc, lockedOut) {
|
|
270
|
+
const catalog = asDict(await doc.getCatalog().catch(() => null));
|
|
271
|
+
const root = asDict(await resolved(doc, get(catalog, 'StructTreeRoot')));
|
|
272
|
+
if (!root)
|
|
228
273
|
return null;
|
|
229
274
|
// §14.7.6.2: attribute classes named by an element's /C are resolved through
|
|
230
275
|
// the structure tree root's /ClassMap, so it has to be read before the walk.
|
|
231
|
-
const
|
|
232
|
-
const classMap = classMapValue instanceof PDFDict ? classMapValue : null;
|
|
276
|
+
const classMap = asDict(await resolved(doc, get(root, 'ClassMap')));
|
|
233
277
|
const elements = [];
|
|
234
|
-
for (const kid of kidsOf(doc, root)) {
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
278
|
+
for (const kid of await kidsOf(doc, root)) {
|
|
279
|
+
const kidRef = asRef(kid);
|
|
280
|
+
const child = asDict(await resolved(doc, kid));
|
|
281
|
+
if (child && get(child, 'S') !== undefined) {
|
|
282
|
+
const seed = new Set(kidRef ? [kidRef.objectNumber] : []);
|
|
283
|
+
const element = await walkElement(doc, lockedOut, child, undefined, classMap, seed, 0);
|
|
238
284
|
if (element)
|
|
239
285
|
elements.push(element);
|
|
240
286
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"struct-tree-walker.js","sourceRoot":"","sources":["../../src/services/struct-tree-walker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"struct-tree-walker.js","sourceRoot":"","sources":["../../src/services/struct-tree-walker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,GAAG,EACH,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,MAAM,GACP,MAAM,uBAAuB,CAAC;AAoD/B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAe;IAClD,OAAO,IAAI,GAAG,CAAC,UAAU,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AAC7C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,GAAgB,EAChB,GAA0B;IAE1B,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,KAAK,UAAU,SAAS,CACtB,GAAgB,EAChB,SAAkB,EAClB,IAAa,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IAAI,GAAiB,EAAE;IAChF,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAClC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ;QAAE,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文書の骨格を読む(`inspect_structure`)。
|
|
3
|
+
*
|
|
4
|
+
* 目録・ページ木・間接オブジェクトの数え上げ・版を返す。判定は書かない ——
|
|
5
|
+
* ここが答えるのは「この文書には何が何個あるか」だけである。
|
|
6
|
+
*
|
|
7
|
+
* ## 型名の語彙(S4・2026-08-31)
|
|
8
|
+
*
|
|
9
|
+
* pdf-lib 版はここで `obj.constructor.name` をそのまま出していたので、出力の
|
|
10
|
+
* 語彙が `PDFCatalog` / `PDFPageTree` / `PDFPageLeaf` / `PDFRawStream` という
|
|
11
|
+
* **pdf-lib の内部クラス名**になっていた。撤去するとその語彙は作れない。
|
|
12
|
+
*
|
|
13
|
+
* COS の型(§7.3)に替えた。`byType` は `kind` —— `dict` / `stream` / `array` /
|
|
14
|
+
* `name` / `string` / `integer` / `real` / `boolean` / `null` / `ref` の 10 種で、
|
|
15
|
+
* `@normativepdf/recover` が返す綴りそのままである。family の中で同じものを
|
|
16
|
+
* 2 つの名前で呼ばないための選び方で、条文の分類でもある。
|
|
17
|
+
*
|
|
18
|
+
* pdf-lib の `PDFCatalog` / `PDFPageTree` / `PDFPageLeaf` が運んでいたのは
|
|
19
|
+
* 辞書の `/Type` そのものなので、それは `byDocType` に分けて出す。
|
|
20
|
+
* §7.3 の型と `/Type` は別の問いで、1 つの数に畳むと
|
|
21
|
+
* 「dict が 51,237 個」と「Page が 13,001 個」が同じ欄を取り合う。
|
|
22
|
+
*
|
|
23
|
+
* 🔴 pdf-lib は `PDFNumber` 1 つで整数と実数を畳んでいた。R-7.3.3-6 は
|
|
24
|
+
* 「A real number shall not be present when an integer is expected」と書いて
|
|
25
|
+
* 区別を要求しているので、`integer` と `real` は分けて数える。
|
|
26
|
+
*/
|
|
27
|
+
import type { StructureAnalysis } from '../types.js';
|
|
28
|
+
/**
|
|
29
|
+
* Analyze PDF internal structure (catalog, page tree, objects).
|
|
30
|
+
*
|
|
31
|
+
* ページ木に届かなかったときは `note` でそう言い、ページ数だけ pdfjs から取る。
|
|
32
|
+
* pdf-lib 版が Linearized PDF のために持っていた退路で、recover でも
|
|
33
|
+
* 「目録から `/Pages` に届かない」文書は同じ形になる。
|
|
34
|
+
*/
|
|
35
|
+
export declare function analyzeStructure(filePath: string): Promise<StructureAnalysis>;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the PDF version the document conforms to.
|
|
38
|
+
*
|
|
39
|
+
* ISO 32000-2 Table 29 (Version) makes the catalog entry conditional, not
|
|
40
|
+
* authoritative: it is the version "to which the document conforms … **if later
|
|
41
|
+
* than the version specified in the file's header**. If the header specifies a
|
|
42
|
+
* later version, or if this entry is absent, the document shall conform to the
|
|
43
|
+
* version specified in the header."
|
|
44
|
+
*
|
|
45
|
+
* So the answer is the later of the two. The previous code returned the catalog
|
|
46
|
+
* entry unconditionally whenever it existed, which reports the wrong version for
|
|
47
|
+
* a file whose header is newer — the exact case Table 29 calls out. (The entry
|
|
48
|
+
* exists so a version can be *raised* by an incremental update; see §7.5.6.)
|
|
49
|
+
*
|
|
50
|
+
* A malformed catalog entry cannot be shown to specify a later version, so the
|
|
51
|
+
* header wins by default.
|
|
52
|
+
*
|
|
53
|
+
* Exported for unit testing — the interesting cases (header newer, versions
|
|
54
|
+
* equal, catalog malformed) would each need a hand-built PDF otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolvePdfVersion(headerVersion: string | null, catalogVersion: string | null): string | null;
|
|
57
|
+
//# sourceMappingURL=structure-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure-service.d.ts","sourceRoot":"","sources":["../../src/services/structure-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAaH,OAAO,KAAK,EAA2C,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAkB9F;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqEnF;AAmED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,GAC5B,MAAM,GAAG,IAAI,CAIf"}
|