@shuji-bonji/pdf-reader-mcp 0.9.0 → 0.9.2
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 +65 -0
- package/README.ja.md +2 -2
- package/README.md +4 -3
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/dist/services/actual-text-service.d.ts +99 -0
- package/dist/services/actual-text-service.d.ts.map +1 -0
- package/dist/services/actual-text-service.js +196 -0
- package/dist/services/actual-text-service.js.map +1 -0
- package/dist/services/content-stream-service.d.ts +70 -0
- package/dist/services/content-stream-service.d.ts.map +1 -0
- package/dist/services/content-stream-service.js +524 -0
- package/dist/services/content-stream-service.js.map +1 -0
- package/dist/services/pdfjs-service.d.ts +50 -5
- package/dist/services/pdfjs-service.d.ts.map +1 -1
- package/dist/services/pdfjs-service.js +145 -29
- package/dist/services/pdfjs-service.js.map +1 -1
- package/dist/services/struct-tree-service.d.ts +2 -61
- package/dist/services/struct-tree-service.d.ts.map +1 -1
- package/dist/services/struct-tree-service.js +6 -131
- package/dist/services/struct-tree-service.js.map +1 -1
- package/dist/services/struct-tree-walker.d.ts +93 -0
- package/dist/services/struct-tree-walker.d.ts.map +1 -0
- package/dist/services/struct-tree-walker.js +177 -0
- package/dist/services/struct-tree-walker.js.map +1 -0
- package/dist/tools/tier1/read-text.d.ts.map +1 -1
- package/dist/tools/tier1/read-text.js +3 -1
- package/dist/tools/tier1/read-text.js.map +1 -1
- package/dist/tools/tier1/search-text.d.ts.map +1 -1
- package/dist/tools/tier1/search-text.js +20 -10
- package/dist/tools/tier1/search-text.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-stream scanner for marked-content property lists (#18).
|
|
3
|
+
*
|
|
4
|
+
* ISO 32000-2 §14.9.4 puts replacement text in exactly two places:
|
|
5
|
+
*
|
|
6
|
+
* 1. a **structure element**'s `/ActualText` (PDF 1.4), reachable from the
|
|
7
|
+
* structure tree — see `struct-tree-service`;
|
|
8
|
+
* 2. a **marked-content sequence**'s `/ActualText` (PDF 1.5), carried in the
|
|
9
|
+
* property list of a `Span` tag — which lives only in the content stream.
|
|
10
|
+
*
|
|
11
|
+
* Case 2 occurs in **untagged** documents too, so no amount of structure-tree
|
|
12
|
+
* work reaches it, and pdfjs does not hand it over either: its
|
|
13
|
+
* `getTextContent({ includeMarkedContent: true })` reports where each
|
|
14
|
+
* marked-content sequence begins and ends and keeps `/MCID`, but discards the
|
|
15
|
+
* rest of the property list (pdfjs-dist 4.x, `case OPS.beginMarkedContentProps`
|
|
16
|
+
* in `getTextContent` reads `args[1].get("MCID")` and nothing else).
|
|
17
|
+
*
|
|
18
|
+
* So the property lists have to be read from the content stream directly. This
|
|
19
|
+
* scanner does **not** decode glyphs — it only records the *order* of
|
|
20
|
+
* `BMC` / `BDC` / `EMC` operators. That order is 1:1 with the markers pdfjs
|
|
21
|
+
* emits, so the two streams are aligned by index rather than by coordinate,
|
|
22
|
+
* which is what makes the approach cheap to verify: if the counts differ, the
|
|
23
|
+
* alignment is known to be wrong and the caller falls back instead of
|
|
24
|
+
* corrupting the text.
|
|
25
|
+
*
|
|
26
|
+
* Two ordering rules are mirrored from pdfjs so the indices line up:
|
|
27
|
+
*
|
|
28
|
+
* - a page's `/Contents` array is one stream, concatenated with white space
|
|
29
|
+
* between the parts (§7.8.2: the division may occur only between lexical
|
|
30
|
+
* tokens);
|
|
31
|
+
* - `Do` on a **Form** XObject is walked inline at that point, using the
|
|
32
|
+
* form's own `/Resources` and falling back to the parent's — exactly what
|
|
33
|
+
* pdfjs's `case OPS.paintXObject` does.
|
|
34
|
+
*/
|
|
35
|
+
import { decodePDFRawStream, PDFArray, PDFDict, PDFHexString, PDFName, PDFRawStream, PDFRef, PDFStream, PDFString, pdfDocEncodingDecode, utf16Decode, } from 'pdf-lib';
|
|
36
|
+
/**
|
|
37
|
+
* How deep `Do` on a Form XObject is followed.
|
|
38
|
+
*
|
|
39
|
+
* A form may legitimately draw another form; a *cycle* is malformed but does
|
|
40
|
+
* occur in the wild and would otherwise recurse forever. The `visiting` set
|
|
41
|
+
* already blocks cycles — this bounds the pathological deep-nesting case too.
|
|
42
|
+
*/
|
|
43
|
+
const MAX_XOBJECT_DEPTH = 16;
|
|
44
|
+
/** Bytes that PDF treats as white space (§7.2.3 Table 1). */
|
|
45
|
+
const WHITESPACE = new Set([0x00, 0x09, 0x0a, 0x0c, 0x0d, 0x20]);
|
|
46
|
+
/** Bytes that delimit a token (§7.2.3 Table 2). */
|
|
47
|
+
const DELIMITER = new Set([0x28, 0x29, 0x3c, 0x3e, 0x5b, 0x5d, 0x7b, 0x7d, 0x2f, 0x25]);
|
|
48
|
+
function isWhitespace(b) {
|
|
49
|
+
return WHITESPACE.has(b);
|
|
50
|
+
}
|
|
51
|
+
function isRegular(b) {
|
|
52
|
+
return !WHITESPACE.has(b) && !DELIMITER.has(b);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The optional language escape sequence at the head of a text string
|
|
56
|
+
* (§7.9.2.2): `ESC`, a language code, `ESC`.
|
|
57
|
+
*
|
|
58
|
+
* §14.9.4 defers to that clause — such a sequence "shall override the prevailing
|
|
59
|
+
* Lang entry" — so it is metadata *about* the replacement text, not part of it,
|
|
60
|
+
* and is stripped rather than emitted as control characters in `read_text`
|
|
61
|
+
* output.
|
|
62
|
+
*
|
|
63
|
+
* It has to come off before PDFDocEncoding decoding: that encoding maps 0x1B to
|
|
64
|
+
* U+02D9 (dot above), not U+001B, so a string-level strip would run after the
|
|
65
|
+
* delimiters had already turned into content.
|
|
66
|
+
*/
|
|
67
|
+
const MAX_LANGUAGE_CODE_BYTES = 8;
|
|
68
|
+
const ESCAPE = 0x1b;
|
|
69
|
+
/** Drop a leading `ESC <lang> ESC` from single-byte-encoded bytes. */
|
|
70
|
+
function stripLanguageEscapeBytes(bytes) {
|
|
71
|
+
if (bytes[0] !== ESCAPE)
|
|
72
|
+
return bytes;
|
|
73
|
+
const close = bytes.indexOf(ESCAPE, 1);
|
|
74
|
+
if (close === -1 || close > MAX_LANGUAGE_CODE_BYTES + 1)
|
|
75
|
+
return bytes;
|
|
76
|
+
return bytes.subarray(close + 1);
|
|
77
|
+
}
|
|
78
|
+
/** The same, for text already decoded from UTF-16, where ESC survives as U+001B. */
|
|
79
|
+
const LANGUAGE_ESCAPE = new RegExp(`^\u001b[^\u001b]{1,${MAX_LANGUAGE_CODE_BYTES}}\u001b`);
|
|
80
|
+
function stripLanguageEscape(text) {
|
|
81
|
+
return text.replace(LANGUAGE_ESCAPE, '');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Decode a PDF *text string* (§7.9.2.2) from its raw bytes.
|
|
85
|
+
*
|
|
86
|
+
* Mirrors pdf-lib's `PDFString.decodeText` (UTF-16BE when the BOM is present,
|
|
87
|
+
* else PDFDocEncoding) and adds the UTF-8 BOM that PDF 2.0 introduced, which
|
|
88
|
+
* pdf-lib 1.x does not handle.
|
|
89
|
+
*/
|
|
90
|
+
export function decodeTextString(bytes) {
|
|
91
|
+
if (bytes.length >= 2 && bytes[0] === 0xfe && bytes[1] === 0xff) {
|
|
92
|
+
return stripLanguageEscape(utf16Decode(bytes));
|
|
93
|
+
}
|
|
94
|
+
if (bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) {
|
|
95
|
+
return new TextDecoder('utf-8').decode(stripLanguageEscapeBytes(bytes.subarray(3)));
|
|
96
|
+
}
|
|
97
|
+
return pdfDocEncodingDecode(stripLanguageEscapeBytes(bytes));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Scan one content stream, appending events to `out`.
|
|
101
|
+
*
|
|
102
|
+
* `resources` is the resource dictionary in effect, needed to resolve a `BDC`
|
|
103
|
+
* whose property list is named rather than inline (`/Span /P1 BDC` →
|
|
104
|
+
* `/Properties /P1`, §14.6.2) and to follow `Do` into Form XObjects.
|
|
105
|
+
*/
|
|
106
|
+
function scanStream(doc, bytes, resources, out, visiting, depth) {
|
|
107
|
+
const n = bytes.length;
|
|
108
|
+
let i = 0;
|
|
109
|
+
/** Operands accumulate until an operator consumes them (§7.8.2 postfix form). */
|
|
110
|
+
let operands = [];
|
|
111
|
+
/** `i` is on `/`. Names may carry `#xx` hex escapes (§7.3.5). */
|
|
112
|
+
const readName = () => {
|
|
113
|
+
i++;
|
|
114
|
+
const chars = [];
|
|
115
|
+
while (i < n && isRegular(bytes[i])) {
|
|
116
|
+
if (bytes[i] === 0x23 && i + 2 < n) {
|
|
117
|
+
const code = Number.parseInt(String.fromCharCode(bytes[i + 1], bytes[i + 2]), 16);
|
|
118
|
+
if (!Number.isNaN(code)) {
|
|
119
|
+
chars.push(code);
|
|
120
|
+
i += 3;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
chars.push(bytes[i]);
|
|
125
|
+
i++;
|
|
126
|
+
}
|
|
127
|
+
return String.fromCharCode(...chars);
|
|
128
|
+
};
|
|
129
|
+
/** `i` is on `(`. Resolves the escapes of §7.3.4.2 Table 3. */
|
|
130
|
+
const readLiteralString = () => {
|
|
131
|
+
i++;
|
|
132
|
+
let nesting = 1;
|
|
133
|
+
const result = [];
|
|
134
|
+
while (i < n) {
|
|
135
|
+
const b = bytes[i];
|
|
136
|
+
if (b === 0x5c) {
|
|
137
|
+
const e = bytes[i + 1];
|
|
138
|
+
i += 2;
|
|
139
|
+
if (e === 0x6e)
|
|
140
|
+
result.push(0x0a);
|
|
141
|
+
else if (e === 0x72)
|
|
142
|
+
result.push(0x0d);
|
|
143
|
+
else if (e === 0x74)
|
|
144
|
+
result.push(0x09);
|
|
145
|
+
else if (e === 0x62)
|
|
146
|
+
result.push(0x08);
|
|
147
|
+
else if (e === 0x66)
|
|
148
|
+
result.push(0x0c);
|
|
149
|
+
else if (e === 0x0a) {
|
|
150
|
+
/* line continuation */
|
|
151
|
+
}
|
|
152
|
+
else if (e === 0x0d) {
|
|
153
|
+
if (bytes[i] === 0x0a)
|
|
154
|
+
i++;
|
|
155
|
+
}
|
|
156
|
+
else if (e >= 0x30 && e <= 0x37) {
|
|
157
|
+
let octal = e - 0x30;
|
|
158
|
+
for (let k = 0; k < 2 && i < n && bytes[i] >= 0x30 && bytes[i] <= 0x37; k++) {
|
|
159
|
+
octal = octal * 8 + (bytes[i] - 0x30);
|
|
160
|
+
i++;
|
|
161
|
+
}
|
|
162
|
+
result.push(octal & 0xff);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
result.push(e);
|
|
166
|
+
}
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (b === 0x28)
|
|
170
|
+
nesting++;
|
|
171
|
+
if (b === 0x29) {
|
|
172
|
+
nesting--;
|
|
173
|
+
if (nesting === 0) {
|
|
174
|
+
i++;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
result.push(b);
|
|
179
|
+
i++;
|
|
180
|
+
}
|
|
181
|
+
return new Uint8Array(result);
|
|
182
|
+
};
|
|
183
|
+
/** `i` is on a `<` that does not begin `<<`. */
|
|
184
|
+
const readHexString = () => {
|
|
185
|
+
i++;
|
|
186
|
+
const digits = [];
|
|
187
|
+
while (i < n && bytes[i] !== 0x3e) {
|
|
188
|
+
const c = bytes[i];
|
|
189
|
+
const d = c >= 0x30 && c <= 0x39
|
|
190
|
+
? c - 0x30
|
|
191
|
+
: c >= 0x41 && c <= 0x46
|
|
192
|
+
? c - 0x37
|
|
193
|
+
: c >= 0x61 && c <= 0x66
|
|
194
|
+
? c - 0x57
|
|
195
|
+
: -1;
|
|
196
|
+
if (d >= 0)
|
|
197
|
+
digits.push(d);
|
|
198
|
+
i++;
|
|
199
|
+
}
|
|
200
|
+
i++; // past `>`
|
|
201
|
+
if (digits.length % 2 === 1)
|
|
202
|
+
digits.push(0); // §7.3.4.3: an odd final digit is padded
|
|
203
|
+
const result = new Uint8Array(digits.length / 2);
|
|
204
|
+
for (let k = 0; k < result.length; k++)
|
|
205
|
+
result[k] = digits[k * 2] * 16 + digits[k * 2 + 1];
|
|
206
|
+
return result;
|
|
207
|
+
};
|
|
208
|
+
/** `i` is on the first `<` of `<<`. */
|
|
209
|
+
const readDict = () => {
|
|
210
|
+
i += 2;
|
|
211
|
+
const map = new Map();
|
|
212
|
+
let key = null;
|
|
213
|
+
while (i < n) {
|
|
214
|
+
if (isWhitespace(bytes[i])) {
|
|
215
|
+
i++;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (bytes[i] === 0x3e && bytes[i + 1] === 0x3e) {
|
|
219
|
+
i += 2;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
const before = i;
|
|
223
|
+
const value = readValue();
|
|
224
|
+
if (i === before)
|
|
225
|
+
i++; // never stall on junk
|
|
226
|
+
if (value === null)
|
|
227
|
+
continue;
|
|
228
|
+
if (key === null)
|
|
229
|
+
key = value.type === 'name' ? value.value : '';
|
|
230
|
+
else {
|
|
231
|
+
map.set(key, value);
|
|
232
|
+
key = null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return map;
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Parse one *value* at `i`, advancing past it.
|
|
239
|
+
*
|
|
240
|
+
* Deliberately distinct from the top-level loop: a bare keyword nested inside
|
|
241
|
+
* a dictionary or array (`true`, `null`) is data, not an operator, and must
|
|
242
|
+
* not be routed to `handleOperator` — which clears the operand stack and
|
|
243
|
+
* would drop the `/Span` tag of the very `BDC` being parsed.
|
|
244
|
+
*/
|
|
245
|
+
const readValue = () => {
|
|
246
|
+
const b = bytes[i];
|
|
247
|
+
if (b === 0x2f)
|
|
248
|
+
return { type: 'name', value: readName() };
|
|
249
|
+
if (b === 0x28)
|
|
250
|
+
return { type: 'string', bytes: readLiteralString() };
|
|
251
|
+
if (b === 0x3c && bytes[i + 1] === 0x3c)
|
|
252
|
+
return { type: 'dict', value: readDict() };
|
|
253
|
+
if (b === 0x3c)
|
|
254
|
+
return { type: 'string', bytes: readHexString() };
|
|
255
|
+
if (b === 0x5b) {
|
|
256
|
+
i++;
|
|
257
|
+
let guard = 0;
|
|
258
|
+
while (i < n && bytes[i] !== 0x5d && guard++ < 100_000) {
|
|
259
|
+
if (isWhitespace(bytes[i])) {
|
|
260
|
+
i++;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const before = i;
|
|
264
|
+
readValue();
|
|
265
|
+
if (i === before)
|
|
266
|
+
i++;
|
|
267
|
+
}
|
|
268
|
+
i++;
|
|
269
|
+
return { type: 'other' };
|
|
270
|
+
}
|
|
271
|
+
if (b === 0x25) {
|
|
272
|
+
while (i < n && bytes[i] !== 0x0a && bytes[i] !== 0x0d)
|
|
273
|
+
i++;
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
if (b === 0x5d || b === 0x7b || b === 0x7d || b === 0x29 || b === 0x3e) {
|
|
277
|
+
i++;
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
const word = readKeyword();
|
|
281
|
+
return word === null ? null : { type: 'other' };
|
|
282
|
+
};
|
|
283
|
+
/** Read a run of regular characters (a number, keyword or operator). */
|
|
284
|
+
const readKeyword = () => {
|
|
285
|
+
let j = i;
|
|
286
|
+
while (j < n && isRegular(bytes[j]))
|
|
287
|
+
j++;
|
|
288
|
+
if (j === i)
|
|
289
|
+
return null;
|
|
290
|
+
const word = String.fromCharCode(...bytes.subarray(i, j));
|
|
291
|
+
i = j;
|
|
292
|
+
return word;
|
|
293
|
+
};
|
|
294
|
+
const handleOperator = (op) => {
|
|
295
|
+
switch (op) {
|
|
296
|
+
case 'BMC': {
|
|
297
|
+
const tag = operands.at(-1);
|
|
298
|
+
out.push({ kind: 'begin', tag: tag?.type === 'name' ? tag.value : undefined });
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case 'BDC': {
|
|
302
|
+
const tag = operands.at(-2);
|
|
303
|
+
const actualText = resolveActualText(doc, operands.at(-1), resources);
|
|
304
|
+
out.push({
|
|
305
|
+
kind: 'begin',
|
|
306
|
+
tag: tag?.type === 'name' ? tag.value : undefined,
|
|
307
|
+
actualText,
|
|
308
|
+
});
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case 'EMC':
|
|
312
|
+
out.push({ kind: 'end' });
|
|
313
|
+
break;
|
|
314
|
+
case 'Do': {
|
|
315
|
+
const name = operands.at(-1);
|
|
316
|
+
if (name?.type === 'name')
|
|
317
|
+
scanFormXObject(doc, name.value, resources, out, visiting, depth);
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
case 'BI':
|
|
321
|
+
// Inline image (§8.9.7): the bytes between `ID` and `EI` are arbitrary
|
|
322
|
+
// binary and cannot be tokenized, so skip the object wholesale.
|
|
323
|
+
i = skipInlineImage(bytes, i);
|
|
324
|
+
break;
|
|
325
|
+
default:
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
operands = [];
|
|
329
|
+
};
|
|
330
|
+
while (i < n) {
|
|
331
|
+
const b = bytes[i];
|
|
332
|
+
if (isWhitespace(b)) {
|
|
333
|
+
i++;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const before = i;
|
|
337
|
+
if (isRegular(b) && !(b >= 0x30 && b <= 0x39) && b !== 0x2b && b !== 0x2d && b !== 0x2e) {
|
|
338
|
+
// A keyword at operand position is an operator.
|
|
339
|
+
const word = readKeyword();
|
|
340
|
+
if (word !== null) {
|
|
341
|
+
handleOperator(word);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const operand = readValue();
|
|
346
|
+
if (operand !== null)
|
|
347
|
+
operands.push(operand);
|
|
348
|
+
if (i === before)
|
|
349
|
+
i++; // never stall
|
|
350
|
+
// Bound pathological input: no operator takes more than a handful of
|
|
351
|
+
// operands, and `BDC` only ever looks at the last two.
|
|
352
|
+
if (operands.length > 64)
|
|
353
|
+
operands = operands.slice(-8);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Resolve the `/ActualText` of a `BDC` property list, which is either an inline
|
|
358
|
+
* dictionary or a name looked up in the resource dictionary's `/Properties`
|
|
359
|
+
* (§14.6.2).
|
|
360
|
+
*/
|
|
361
|
+
function resolveActualText(doc, props, resources) {
|
|
362
|
+
if (props?.type === 'dict') {
|
|
363
|
+
const actual = props.value.get('ActualText');
|
|
364
|
+
return actual?.type === 'string' ? decodeTextString(actual.bytes) : undefined;
|
|
365
|
+
}
|
|
366
|
+
if (props?.type !== 'name' || !resources)
|
|
367
|
+
return undefined;
|
|
368
|
+
const properties = deref(doc, resources.get(PDFName.of('Properties')));
|
|
369
|
+
if (!(properties instanceof PDFDict))
|
|
370
|
+
return undefined;
|
|
371
|
+
const entry = deref(doc, properties.get(PDFName.of(props.value)));
|
|
372
|
+
if (!(entry instanceof PDFDict))
|
|
373
|
+
return undefined;
|
|
374
|
+
const actual = deref(doc, entry.get(PDFName.of('ActualText')));
|
|
375
|
+
if (actual instanceof PDFString || actual instanceof PDFHexString) {
|
|
376
|
+
return decodeTextString(actual.asBytes());
|
|
377
|
+
}
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
/** Follow `Do` into a Form XObject, in place, like pdfjs's `paintXObject`. */
|
|
381
|
+
function scanFormXObject(doc, name, resources, out, visiting, depth) {
|
|
382
|
+
if (depth >= MAX_XOBJECT_DEPTH || !resources)
|
|
383
|
+
return;
|
|
384
|
+
const xobjects = deref(doc, resources.get(PDFName.of('XObject')));
|
|
385
|
+
if (!(xobjects instanceof PDFDict))
|
|
386
|
+
return;
|
|
387
|
+
const ref = xobjects.get(PDFName.of(name));
|
|
388
|
+
const key = ref instanceof PDFRef ? ref.toString() : `${name}@${depth}`;
|
|
389
|
+
if (visiting.has(key))
|
|
390
|
+
return;
|
|
391
|
+
const stream = deref(doc, ref);
|
|
392
|
+
if (!(stream instanceof PDFStream))
|
|
393
|
+
return;
|
|
394
|
+
const subtype = deref(doc, stream.dict.get(PDFName.of('Subtype')));
|
|
395
|
+
if (!(subtype instanceof PDFName) || subtype.decodeText() !== 'Form')
|
|
396
|
+
return;
|
|
397
|
+
const contents = decodeStream(stream);
|
|
398
|
+
if (!contents)
|
|
399
|
+
return;
|
|
400
|
+
const formResources = deref(doc, stream.dict.get(PDFName.of('Resources')));
|
|
401
|
+
visiting.add(key);
|
|
402
|
+
try {
|
|
403
|
+
scanStream(doc, contents, formResources instanceof PDFDict ? formResources : resources, out, visiting, depth + 1);
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
visiting.delete(key);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Skip an inline image, from just past `BI` to just past the closing `EI`.
|
|
411
|
+
*
|
|
412
|
+
* The data after `ID` is arbitrary binary, so `EI` is found by scanning for the
|
|
413
|
+
* keyword delimited by white space — the same heuristic every PDF consumer uses,
|
|
414
|
+
* because the format offers nothing better without decoding the image.
|
|
415
|
+
*/
|
|
416
|
+
function skipInlineImage(bytes, from) {
|
|
417
|
+
const n = bytes.length;
|
|
418
|
+
let i = from;
|
|
419
|
+
while (i < n - 1) {
|
|
420
|
+
if (bytes[i] === 0x49 && bytes[i + 1] === 0x44 && (i === 0 || !isRegular(bytes[i - 1]))) {
|
|
421
|
+
i += 2;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
i++;
|
|
425
|
+
}
|
|
426
|
+
i++; // the single white-space byte that follows `ID`
|
|
427
|
+
while (i < n - 1) {
|
|
428
|
+
if (bytes[i] === 0x45 &&
|
|
429
|
+
bytes[i + 1] === 0x49 &&
|
|
430
|
+
isWhitespace(bytes[i - 1]) &&
|
|
431
|
+
(i + 2 >= n || !isRegular(bytes[i + 2]))) {
|
|
432
|
+
return i + 2;
|
|
433
|
+
}
|
|
434
|
+
i++;
|
|
435
|
+
}
|
|
436
|
+
return n;
|
|
437
|
+
}
|
|
438
|
+
/** Resolve a value that may be an indirect reference. */
|
|
439
|
+
function deref(doc, obj) {
|
|
440
|
+
return obj instanceof PDFRef ? doc.context.lookup(obj) : obj;
|
|
441
|
+
}
|
|
442
|
+
/** Decode a stream's bytes, tolerating filters pdf-lib cannot handle. */
|
|
443
|
+
function decodeStream(stream) {
|
|
444
|
+
try {
|
|
445
|
+
if (stream instanceof PDFRawStream)
|
|
446
|
+
return decodePDFRawStream(stream).decode();
|
|
447
|
+
return stream.getContents();
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Scan one page's content for marked-content operators, in stream order.
|
|
455
|
+
*
|
|
456
|
+
* Returns `null` when the page's content cannot be read (missing or undecodable
|
|
457
|
+
* stream). Callers must treat `null` — and any count that disagrees with pdfjs's
|
|
458
|
+
* marker count — as "alignment unknown" and skip replacement: a scanner that is
|
|
459
|
+
* off by one sequence would move replacement text onto the wrong glyphs. Failing
|
|
460
|
+
* to resolve `/ActualText` leaves the pre-existing behaviour (raw glyphs, plus
|
|
461
|
+
* the #15 note); mis-resolving it would be a new and worse failure.
|
|
462
|
+
*
|
|
463
|
+
* @param pageIndex 0-based page index.
|
|
464
|
+
*/
|
|
465
|
+
export function scanPageMarkedContent(doc, pageIndex) {
|
|
466
|
+
// An encrypted document's content streams are ciphertext to pdf-lib, which
|
|
467
|
+
// loads with `ignoreEncryption` and so never decrypts them (§7.6.2 encrypts
|
|
468
|
+
// strings and streams). Inflate would fail anyway — "Unknown compression
|
|
469
|
+
// method" — but saying so here keeps the reason from looking like corruption.
|
|
470
|
+
if (doc.isEncrypted)
|
|
471
|
+
return null;
|
|
472
|
+
let node;
|
|
473
|
+
try {
|
|
474
|
+
node = doc.getPage(pageIndex).node;
|
|
475
|
+
}
|
|
476
|
+
catch {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
const contents = node.Contents();
|
|
480
|
+
if (!contents)
|
|
481
|
+
return null;
|
|
482
|
+
const streams = [];
|
|
483
|
+
if (contents instanceof PDFArray) {
|
|
484
|
+
for (const item of contents.asArray()) {
|
|
485
|
+
const resolved = deref(doc, item);
|
|
486
|
+
if (resolved instanceof PDFStream) {
|
|
487
|
+
const decoded = decodeStream(resolved);
|
|
488
|
+
if (decoded)
|
|
489
|
+
streams.push(decoded);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else if (contents instanceof PDFStream) {
|
|
494
|
+
const decoded = decodeStream(contents);
|
|
495
|
+
if (decoded)
|
|
496
|
+
streams.push(decoded);
|
|
497
|
+
}
|
|
498
|
+
if (streams.length === 0)
|
|
499
|
+
return null;
|
|
500
|
+
const resources = node.Resources();
|
|
501
|
+
const events = [];
|
|
502
|
+
try {
|
|
503
|
+
// §7.8.2: the parts of a /Contents array form one stream, and the division
|
|
504
|
+
// may occur only between lexical tokens — a single separator restores it.
|
|
505
|
+
scanStream(doc, joinWithNewline(streams), resources ?? undefined, events, new Set(), 0);
|
|
506
|
+
}
|
|
507
|
+
catch {
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
return events;
|
|
511
|
+
}
|
|
512
|
+
function joinWithNewline(streams) {
|
|
513
|
+
const total = streams.reduce((sum, s) => sum + s.length + 1, 0);
|
|
514
|
+
const joined = new Uint8Array(total);
|
|
515
|
+
let offset = 0;
|
|
516
|
+
for (const s of streams) {
|
|
517
|
+
joined.set(s, offset);
|
|
518
|
+
offset += s.length;
|
|
519
|
+
joined[offset] = 0x0a;
|
|
520
|
+
offset += 1;
|
|
521
|
+
}
|
|
522
|
+
return joined;
|
|
523
|
+
}
|
|
524
|
+
//# sourceMappingURL=content-stream-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-stream-service.js","sourceRoot":"","sources":["../../src/services/content-stream-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH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C,CAAC;IACrC,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IACnC,MAAM,MAAM,GAAyB,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,2EAA2E;QAC3E,0EAA0E;QAC1E,UAAU,CAAC,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,SAAS,IAAI,SAAS,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,eAAe,CAAC,OAAqB;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACtB,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC;QACnB,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;QACtB,MAAM,IAAI,CAAC,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Centralizes all pdfjs-dist interactions for reuse across tools.
|
|
5
5
|
*/
|
|
6
|
+
import type { PDFDocument as PdfLibDocument } from 'pdf-lib';
|
|
6
7
|
import { type PDFDocumentProxy } from 'pdfjs-dist/legacy/build/pdf.mjs';
|
|
7
8
|
import type { AnnotationsAnalysis, ImageExtractionResult, PageText, PdfMetadata, SearchMatch, TagsAnalysis } from '../types.js';
|
|
8
9
|
/**
|
|
@@ -37,19 +38,60 @@ export interface ExtractTextOptions {
|
|
|
37
38
|
splitColumns?: number;
|
|
38
39
|
compactWhitespace?: boolean;
|
|
39
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Everything `/ActualText` resolution needs that pdfjs cannot supply (#18):
|
|
43
|
+
* a pdf-lib view of the same file, for the structure tree and the content
|
|
44
|
+
* streams. Absent when the file could not be opened with pdf-lib, in which case
|
|
45
|
+
* extraction falls back to raw glyphs.
|
|
46
|
+
*/
|
|
47
|
+
interface ActualTextResolution {
|
|
48
|
+
libDoc: PdfLibDocument;
|
|
49
|
+
structActualText: ReadonlyMap<string, string>;
|
|
50
|
+
/**
|
|
51
|
+
* The document is encrypted, so neither path can run: §7.6.2 encrypts strings
|
|
52
|
+
* and streams, and pdf-lib is loaded with `ignoreEncryption`. Recorded so the
|
|
53
|
+
* caller can say *why* nothing was resolved — "the content stream did not
|
|
54
|
+
* line up" would be a wrong and unactionable explanation here.
|
|
55
|
+
*/
|
|
56
|
+
encrypted: boolean;
|
|
57
|
+
}
|
|
40
58
|
/**
|
|
41
59
|
* Extract text from a pre-loaded PDFDocumentProxy.
|
|
42
60
|
* Does NOT destroy the document — caller is responsible for lifecycle.
|
|
43
61
|
*/
|
|
44
|
-
export declare function extractTextFromDoc(doc: PDFDocumentProxy, pages?: string, options?: ExtractTextOptions): Promise<PageText[]>;
|
|
62
|
+
export declare function extractTextFromDoc(doc: PDFDocumentProxy, pages?: string, options?: ExtractTextOptions, resolution?: ActualTextResolution): Promise<PageText[]>;
|
|
45
63
|
/**
|
|
46
64
|
* Extract text from specified pages (1-based).
|
|
65
|
+
*
|
|
66
|
+
* Resolves `/ActualText` (ISO 32000-2 §14.9.4) on both of the paths the clause
|
|
67
|
+
* defines — see `actual-text-service`. The pdf-lib load that makes this possible
|
|
68
|
+
* is best-effort: a file it cannot parse still extracts, as raw glyphs.
|
|
47
69
|
*/
|
|
48
70
|
export declare function extractText(filePath: string, pages?: string, options?: ExtractTextOptions): Promise<PageText[]>;
|
|
71
|
+
/** What `search_text` gets back: the matches, and how complete the text was. */
|
|
72
|
+
export interface SearchTextResult {
|
|
73
|
+
matches: SearchMatch[];
|
|
74
|
+
/**
|
|
75
|
+
* Pages where `/ActualText` could not be resolved (§14.9.4). A miss on one of
|
|
76
|
+
* these pages may still be a replacement the search could not see — which is
|
|
77
|
+
* what #15 warned about, now narrowed to the cases where it is actually true.
|
|
78
|
+
*/
|
|
79
|
+
unresolvedPages: number[];
|
|
80
|
+
/**
|
|
81
|
+
* Why `unresolvedPages` is non-empty. `encrypted` means the whole document is
|
|
82
|
+
* out of reach and no other tool of this server will do better; `unaligned`
|
|
83
|
+
* means the content stream of those particular pages could not be matched up
|
|
84
|
+
* with the extracted text.
|
|
85
|
+
*/
|
|
86
|
+
unresolvedReason?: 'encrypted' | 'unaligned';
|
|
87
|
+
}
|
|
49
88
|
/**
|
|
50
89
|
* Search for text across all pages.
|
|
90
|
+
*
|
|
91
|
+
* Searches the same text `read_text` returns, `/ActualText` included (#18), so
|
|
92
|
+
* the two tools can no longer disagree about whether a word is in the document.
|
|
51
93
|
*/
|
|
52
|
-
export declare function searchText(filePath: string, query: string, contextChars?: number, pages?: string): Promise<
|
|
94
|
+
export declare function searchText(filePath: string, query: string, contextChars?: number, pages?: string): Promise<SearchTextResult>;
|
|
53
95
|
/**
|
|
54
96
|
* Count images from a pre-loaded PDFDocumentProxy.
|
|
55
97
|
* Does NOT destroy the document — caller is responsible for lifecycle.
|
|
@@ -82,9 +124,11 @@ export declare function extractImages(filePath: string, pages?: string): Promise
|
|
|
82
124
|
/**
|
|
83
125
|
* Whether the document claims to be tagged (`/MarkInfo /Marked true`).
|
|
84
126
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
127
|
+
* Was used by search_text to explain empty results on tagged documents (#15).
|
|
128
|
+
* Since #18 resolves `/ActualText` on both of its paths, an empty result no
|
|
129
|
+
* longer implies replacement text was missed, and the warning is keyed off the
|
|
130
|
+
* pages where resolution was actually skipped instead. Kept as a public probe:
|
|
131
|
+
* `get_metadata` reports the same flag, and the tests assert it.
|
|
88
132
|
*/
|
|
89
133
|
export declare function isTaggedPdf(filePath: string): Promise<boolean>;
|
|
90
134
|
/**
|
|
@@ -175,4 +219,5 @@ export declare function isMarkupAnnotation(subtype: string): boolean;
|
|
|
175
219
|
* Analyze annotations across all pages.
|
|
176
220
|
*/
|
|
177
221
|
export declare function analyzeAnnotations(filePath: string, pages?: string): Promise<AnnotationsAnalysis>;
|
|
222
|
+
export {};
|
|
178
223
|
//# sourceMappingURL=pdfjs-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfjs-service.d.ts","sourceRoot":"","sources":["../../src/services/pdfjs-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"pdfjs-service.d.ts","sourceRoot":"","sources":["../../src/services/pdfjs-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EACrB,QAAQ,EACR,WAAW,EACX,WAAW,EAEX,YAAY,EACb,MAAM,aAAa,CAAC;AAyBrB;;GAEG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAI9E;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGtF;AAED;;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