@shuji-bonji/pdf-reader-mcp 0.15.5 → 0.16.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 +88 -0
- package/README.ja.md +5 -4
- package/README.md +4 -3
- package/dist/schemas/tier2.d.ts +8 -0
- package/dist/schemas/tier2.d.ts.map +1 -1
- package/dist/schemas/tier2.js +18 -0
- package/dist/schemas/tier2.js.map +1 -1
- package/dist/services/catalog-service.d.ts +30 -0
- package/dist/services/catalog-service.d.ts.map +1 -0
- package/dist/services/catalog-service.js +436 -0
- package/dist/services/catalog-service.js.map +1 -0
- package/dist/services/reading-scope.d.ts +8 -1
- package/dist/services/reading-scope.d.ts.map +1 -1
- package/dist/services/reading-scope.js +1 -0
- package/dist/services/reading-scope.js.map +1 -1
- package/dist/services/xmp-service.d.ts +66 -0
- package/dist/services/xmp-service.d.ts.map +1 -0
- package/dist/services/xmp-service.js +160 -0
- package/dist/services/xmp-service.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/tier1/summarize.d.ts +10 -0
- package/dist/tools/tier1/summarize.d.ts.map +1 -1
- package/dist/tools/tier1/summarize.js +31 -5
- package/dist/tools/tier1/summarize.js.map +1 -1
- package/dist/tools/tier2/inspect-catalog.d.ts +6 -0
- package/dist/tools/tier2/inspect-catalog.d.ts.map +1 -0
- package/dist/tools/tier2/inspect-catalog.js +63 -0
- package/dist/tools/tier2/inspect-catalog.js.map +1 -0
- package/dist/types.d.ts +197 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/formatter.d.ts +2 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +143 -5
- package/dist/utils/formatter.js.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文書レベルの XMP メタデータストリーム(ISO 32000-2 §14.3.2)を読む。
|
|
3
|
+
*
|
|
4
|
+
* `get_metadata` が返しているのは Info 辞書(§14.3.3)で、XMP ではない。PDF/A・PDF/UA の
|
|
5
|
+
* 適合宣言(`pdfaid:*` / `pdfuaid:part`)と、著者の TDM(text and data mining)に対する
|
|
6
|
+
* 権利表明(W3C TDMRep)は XMP にしか書かれないので、ここで別に読む(#27 / #28 / #29)。
|
|
7
|
+
*
|
|
8
|
+
* 🔴 ここで返すのは**書いてある値**である。`pdfuaid:part = 1` は「PDF/UA-1 を宣言している」
|
|
9
|
+
* であって「PDF/UA-1 に適合している」ではない。適合の判定は pdf-verify-mcp の
|
|
10
|
+
* `validate_conformance` が行う。同じく `tdm:reservation = 1` は「著者が留保を表明している」
|
|
11
|
+
* で、この server はそれを読んで返すだけであり、読む・読まないの判断を呼び出し側から奪わない。
|
|
12
|
+
*
|
|
13
|
+
* XML は正規表現で読む。XMP は RDF/XML で、同じプロパティを属性(`pdfuaid:part="1"`)と
|
|
14
|
+
* 要素(`<pdfuaid:part>1</pdfuaid:part>`)のどちらでも書けるので(XMP Part 1 §7.9.2)、
|
|
15
|
+
* 両方の形を見る。XML パーサを足さないのは、依存を増やさないためと、必要なのが
|
|
16
|
+
* 数個の既知プロパティの値だけだからである。
|
|
17
|
+
*/
|
|
18
|
+
import { asDict, decodedBytes, get, nameOf, tryGet } from '@normativepdf/recover';
|
|
19
|
+
import { lockedOut, openPdf } from './recover-service.js';
|
|
20
|
+
/**
|
|
21
|
+
* 名前空間 URI。XMP は prefix ではなく URI で名前空間を識別する(prefix は書き手が選べる)。
|
|
22
|
+
*
|
|
23
|
+
* TDMRep は 2 つ書いてある。W3C Final Community Group Report(2024-05-10)の §6.6(PDF)は
|
|
24
|
+
* `http://www.w3.org/ns/tdmrep/`(末尾スラッシュ)、§6.5(EPUB 3)は `http://www.w3.org/ns/tdmrep#`
|
|
25
|
+
* と書いていて、文書の中で揃えていない。PDF の書き手がどちらを写すかは決められないので両方を受ける。
|
|
26
|
+
*/
|
|
27
|
+
export const XMP_NAMESPACES = {
|
|
28
|
+
pdfaid: ['http://www.aiim.org/pdfa/ns/id/'],
|
|
29
|
+
pdfuaid: ['http://www.aiim.org/pdfua/ns/id/'],
|
|
30
|
+
tdm: ['http://www.w3.org/ns/tdmrep/', 'http://www.w3.org/ns/tdmrep#'],
|
|
31
|
+
};
|
|
32
|
+
/** `include_xmp` で本体を返すときの上限(バイト)。XMP は通常数 KB、パケット全体でも数十 KB。 */
|
|
33
|
+
export const XMP_RETURN_LIMIT = 65_536;
|
|
34
|
+
/**
|
|
35
|
+
* カタログの `/Metadata` を読む。
|
|
36
|
+
*
|
|
37
|
+
* - キーが無い → `null`(XMP が**無い**。観測できた事実)
|
|
38
|
+
* - キーはあるが解決できない・ストリームでない・復号できない → `{ status: 'unreadable', ... }`
|
|
39
|
+
* - 読めた → `{ status: 'read', ... }`
|
|
40
|
+
*
|
|
41
|
+
* 「無い」と「読めなかった」を 1 つの `null` に畳まない(#26 と同じ線)。
|
|
42
|
+
*/
|
|
43
|
+
export async function readXmpMetadata(doc, catalog) {
|
|
44
|
+
if (!catalog?.entries.has('Metadata'))
|
|
45
|
+
return null;
|
|
46
|
+
const lookup = await tryGet(doc, catalog, 'Metadata');
|
|
47
|
+
if (lookup.unreadable) {
|
|
48
|
+
return { status: 'unreadable', reason: 'the /Metadata reference could not be resolved' };
|
|
49
|
+
}
|
|
50
|
+
const value = lookup.value;
|
|
51
|
+
if (value?.kind !== 'stream') {
|
|
52
|
+
return {
|
|
53
|
+
status: 'unreadable',
|
|
54
|
+
reason: `/Metadata is ${value ? `a ${value.kind}` : 'null'}, not a stream (ISO 32000-2 §14.3.2)`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const subtype = nameOf(get(value.dict, 'Subtype'));
|
|
58
|
+
const { bytes, unreadable } = await decodedBytes(doc, value);
|
|
59
|
+
if (unreadable || !bytes) {
|
|
60
|
+
return { status: 'unreadable', reason: 'the /Metadata stream could not be decoded' };
|
|
61
|
+
}
|
|
62
|
+
const xml = new TextDecoder('utf-8', { fatal: false }).decode(bytes);
|
|
63
|
+
return {
|
|
64
|
+
status: 'read',
|
|
65
|
+
bytes: bytes.length,
|
|
66
|
+
subtype,
|
|
67
|
+
namespaces: collectNamespaces(xml),
|
|
68
|
+
declarations: parseDeclarations(xml),
|
|
69
|
+
xml,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** `xmlns:prefix="uri"` を全部集める。prefix は書き手が選ぶので、URI のほうを返す。 */
|
|
73
|
+
export function collectNamespaces(xml) {
|
|
74
|
+
const seen = new Map();
|
|
75
|
+
for (const m of xml.matchAll(/xmlns:([A-Za-z_][\w.-]*)\s*=\s*["']([^"']+)["']/g)) {
|
|
76
|
+
if (!seen.has(m[1]))
|
|
77
|
+
seen.set(m[1], m[2]);
|
|
78
|
+
}
|
|
79
|
+
return [...seen].map(([prefix, uri]) => ({ prefix, uri }));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 既知のプロパティの値を取り出す。
|
|
83
|
+
*
|
|
84
|
+
* prefix は宣言された名前空間 URI から逆引きする。`pdfuaid` という prefix を別の URI に
|
|
85
|
+
* 束ねている文書は実務上まず無いが、逆に URI が正しくて prefix が違う文書はあり得る
|
|
86
|
+
* (XMP の規則上は正当)。URI が宣言されていない prefix は慣用の綴りをそのまま使う
|
|
87
|
+
* (宣言を省いた不正な XMP でも、値そのものは読めるようにしておく)。
|
|
88
|
+
*/
|
|
89
|
+
export function parseDeclarations(xml) {
|
|
90
|
+
const prefixes = (uris, fallback) => {
|
|
91
|
+
const found = collectNamespaces(xml)
|
|
92
|
+
.filter((n) => uris.includes(n.uri))
|
|
93
|
+
.map((n) => n.prefix);
|
|
94
|
+
return found.length > 0 ? found : [fallback];
|
|
95
|
+
};
|
|
96
|
+
const pdfaid = prefixes(XMP_NAMESPACES.pdfaid, 'pdfaid');
|
|
97
|
+
const pdfuaid = prefixes(XMP_NAMESPACES.pdfuaid, 'pdfuaid');
|
|
98
|
+
const tdm = prefixes(XMP_NAMESPACES.tdm, 'tdm');
|
|
99
|
+
const pdfaPartRaw = stringProperty(xml, pdfaid, 'part');
|
|
100
|
+
const pdfaConformance = stringProperty(xml, pdfaid, 'conformance');
|
|
101
|
+
const pdfuaPartRaw = stringProperty(xml, pdfuaid, 'part');
|
|
102
|
+
const reservationRaw = stringProperty(xml, tdm, 'reservation');
|
|
103
|
+
const policy = stringProperty(xml, tdm, 'policy');
|
|
104
|
+
// ブロックの有無は「プロパティが書いてあるか」で決める。書いてあるが整数でない値は
|
|
105
|
+
// `part: null` として残す —— 「宣言が無い」と「宣言が壊れている」は別の観測である。
|
|
106
|
+
return {
|
|
107
|
+
pdfaid: pdfaPartRaw === null && pdfaConformance === null
|
|
108
|
+
? null
|
|
109
|
+
: { part: asInteger(pdfaPartRaw), conformance: pdfaConformance },
|
|
110
|
+
pdfuaid: pdfuaPartRaw === null ? null : { part: asInteger(pdfuaPartRaw) },
|
|
111
|
+
tdm: reservationRaw === null && policy === null
|
|
112
|
+
? null
|
|
113
|
+
: { reservation: asInteger(reservationRaw), policy },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** 属性形と要素形の両方を見て、最初に見つかった値を返す。 */
|
|
117
|
+
function stringProperty(xml, prefixes, local) {
|
|
118
|
+
for (const p of prefixes) {
|
|
119
|
+
const name = `${escapeRegExp(p)}:${escapeRegExp(local)}`;
|
|
120
|
+
const attr = new RegExp(`\\s${name}\\s*=\\s*["']([^"']*)["']`).exec(xml);
|
|
121
|
+
if (attr)
|
|
122
|
+
return attr[1];
|
|
123
|
+
const elem = new RegExp(`<${name}(?:\\s[^>]*)?>\\s*([^<]*?)\\s*</${name}>`).exec(xml);
|
|
124
|
+
if (elem)
|
|
125
|
+
return elem[1];
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
function asInteger(raw) {
|
|
130
|
+
if (raw === null)
|
|
131
|
+
return null;
|
|
132
|
+
return /^-?\d+$/.test(raw.trim()) ? Number(raw.trim()) : null;
|
|
133
|
+
}
|
|
134
|
+
function escapeRegExp(s) {
|
|
135
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* `summarize` 用の読み口(#29): ファイルを開いて宣言だけを返す。
|
|
139
|
+
*
|
|
140
|
+
* - `/Metadata` が無い → すべて `null` のブロック(読めた上で「宣言が無い」)
|
|
141
|
+
* - 読めなかった → 例外。呼び出し側の `half` が `failed` として射程に残す
|
|
142
|
+
* (`null` で返すと「宣言が無い」と区別できなくなる)
|
|
143
|
+
*/
|
|
144
|
+
export async function readXmpDeclarations(filePath) {
|
|
145
|
+
const { doc, scope } = await openPdf(filePath);
|
|
146
|
+
if (lockedOut(scope)) {
|
|
147
|
+
throw new Error('The document is encrypted and the key could not be derived from the empty user password ' +
|
|
148
|
+
'(ISO 32000-2 §7.6.4.3.2); the catalog and its /Metadata could not be read.');
|
|
149
|
+
}
|
|
150
|
+
const catalog = asDict(await doc.getCatalog().catch(() => null));
|
|
151
|
+
if (!catalog)
|
|
152
|
+
throw new Error('The catalog dictionary could not be read (ISO 32000-2 §7.7.2).');
|
|
153
|
+
const info = await readXmpMetadata(doc, catalog);
|
|
154
|
+
if (info === null)
|
|
155
|
+
return { pdfaid: null, pdfuaid: null, tdm: null };
|
|
156
|
+
if (info.status === 'unreadable')
|
|
157
|
+
throw new Error(`/Metadata could not be read: ${info.reason}`);
|
|
158
|
+
return info.declarations;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=xmp-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xmp-service.js","sourceRoot":"","sources":["../../src/services/xmp-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAA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AG,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,0FAA0F;YACxF,4EAA4E,CAC/E,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IAChG,MAAM,IAAI,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACjD,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IACrE,IAAI,IAAI,CAAC,MAAM,KAAK,YAAY;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACjG,OAAO,IAAI,CAAC,YAAY,CAAC;AAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAyB9D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA0BxD"}
|
package/dist/tools/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { registerSummarize } from './tier1/summarize.js';
|
|
|
11
11
|
import { registerExtractStructuredText } from './tier2/extract-structured-text.js';
|
|
12
12
|
import { registerExtractTables } from './tier2/extract-tables.js';
|
|
13
13
|
import { registerInspectAnnotations } from './tier2/inspect-annotations.js';
|
|
14
|
+
import { registerInspectCatalog } from './tier2/inspect-catalog.js';
|
|
14
15
|
import { registerInspectFonts } from './tier2/inspect-fonts.js';
|
|
15
16
|
import { registerInspectSignatures } from './tier2/inspect-signatures.js';
|
|
16
17
|
import { registerInspectStructure } from './tier2/inspect-structure.js';
|
|
@@ -35,6 +36,7 @@ export function registerAllTools(server) {
|
|
|
35
36
|
registerSummarize(server);
|
|
36
37
|
// Tier 2: Structure analysis
|
|
37
38
|
registerInspectStructure(server);
|
|
39
|
+
registerInspectCatalog(server);
|
|
38
40
|
registerInspectTags(server);
|
|
39
41
|
registerInspectFonts(server);
|
|
40
42
|
registerInspectAnnotations(server);
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,sBAAsB;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,6BAA6B;AAC7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,0BA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OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,+BAA+B;IAC/B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzB,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,eAAe,CAAC,MAAM,CAAC,CAAC;IACxB,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3B,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE1B,6BAA6B;IAC7B,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACjC,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC/B,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,0BAA0B,CAAC,MAAM,CAAC,CAAC;IACnC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAClC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC9B,6BAA6B,CAAC,MAAM,CAAC,CAAC;IACtC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE9B,gCAAgC;IAChC,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC/B,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACjC,wBAAwB,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -2,5 +2,15 @@
|
|
|
2
2
|
* summarize - Quick overview report of a PDF document.
|
|
3
3
|
*/
|
|
4
4
|
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
+
import type { PageExtractability, PdfMetadata, TextExtractabilityState, XmpDeclarations } from '../../types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Derive "what to call next" from the summary's own observations (#24).
|
|
8
|
+
*
|
|
9
|
+
* Rules, not inference: each suggestion names the observation it follows from,
|
|
10
|
+
* so the caller can check the premise instead of trusting the advice. Ordering
|
|
11
|
+
* between suggestions is not implied, and nothing here is enforced — the MCP
|
|
12
|
+
* layer observes; orchestration belongs to the Skill above it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function suggestNext(metadata: PdfMetadata | null, textExtractability: TextExtractabilityState | null, unreadablePages: PageExtractability[] | null, declared: XmpDeclarations | null): string[];
|
|
5
15
|
export declare function registerSummarize(server: McpServer): void;
|
|
6
16
|
//# sourceMappingURL=summarize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../../src/tools/tier1/summarize.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../../src/tools/tier1/summarize.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAqB9D,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EAEX,uBAAuB,EACvB,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,WAAW,GAAG,IAAI,EAC5B,kBAAkB,EAAE,uBAAuB,GAAG,IAAI,EAClD,eAAe,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAC5C,QAAQ,EAAE,eAAe,GAAG,IAAI,GAC/B,MAAM,EAAE,CA+EV;AAwBD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA8HzD"}
|
|
@@ -3,6 +3,7 @@ import { SummarizeSchema } from '../../schemas/tier1.js';
|
|
|
3
3
|
import { countImagesFromDoc, extractTextFromDoc, getMetadataFromDoc, loadDocument, } from '../../services/pdfjs-service.js';
|
|
4
4
|
import { bothFailedError, formatSummaryScope, half, } from '../../services/reading-scope.js';
|
|
5
5
|
import { foldExtractability, observeExtractability, } from '../../services/text-extractability-service.js';
|
|
6
|
+
import { readXmpDeclarations } from '../../services/xmp-service.js';
|
|
6
7
|
import { formatSummaryMarkdown } from '../../utils/formatter.js';
|
|
7
8
|
/**
|
|
8
9
|
* Derive "what to call next" from the summary's own observations (#24).
|
|
@@ -12,7 +13,7 @@ import { formatSummaryMarkdown } from '../../utils/formatter.js';
|
|
|
12
13
|
* between suggestions is not implied, and nothing here is enforced — the MCP
|
|
13
14
|
* layer observes; orchestration belongs to the Skill above it.
|
|
14
15
|
*/
|
|
15
|
-
function suggestNext(metadata, textExtractability, unreadablePages) {
|
|
16
|
+
export function suggestNext(metadata, textExtractability, unreadablePages, declared) {
|
|
16
17
|
const next = [];
|
|
17
18
|
// 🔴 観測できなかった前提からは何も勧めない。読まなかったことを
|
|
18
19
|
// 「そうではなかった」として扱うと、助言が観測の顔をする。
|
|
@@ -42,6 +43,23 @@ function suggestNext(metadata, textExtractability, unreadablePages) {
|
|
|
42
43
|
next.push(`textExtractability is ${textExtractability} (page ${pageList}): read those pages as ` +
|
|
43
44
|
'images with render_page — read_text cannot represent them.');
|
|
44
45
|
}
|
|
46
|
+
// #29: XMP の PDF/UA 宣言は「構造ツリーを信頼してよい」という書き手の合図である。
|
|
47
|
+
// MarkInfo /Marked だけを見ていた 0.15 までは、この合図が summarize から見えなかった。
|
|
48
|
+
// 🔴 宣言は宣言であって、満たしているかは別の問い(pdf-verify-mcp)。文言は declared で揃える。
|
|
49
|
+
if (declared?.pdfuaid) {
|
|
50
|
+
const part = declared.pdfuaid.part === null ? '' : `-${declared.pdfuaid.part}`;
|
|
51
|
+
if (metadata.isTagged) {
|
|
52
|
+
next.push(`declaredConformance.pdfuaid declares PDF/UA${part}: the author claims a complete structure ` +
|
|
53
|
+
'tree, so take the structure route first — extract_structured_text for the body, ' +
|
|
54
|
+
'extract_tables for tables — instead of inferring reading order from coordinates. ' +
|
|
55
|
+
'Whether the claim holds is pdf-verify-mcp validate_conformance (flavour pdfua-1/-2), not this server.');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
next.push(`declaredConformance.pdfuaid declares PDF/UA${part} but MarkInfo /Marked is not true: the ` +
|
|
59
|
+
'declaration and the catalog disagree. inspect_tags shows what structure tree exists; ' +
|
|
60
|
+
'pdf-verify-mcp validate_conformance says which side is wrong.');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
45
63
|
if (metadata.isTagged) {
|
|
46
64
|
next.push('isTagged is true: extract_structured_text returns the body in logical content order ' +
|
|
47
65
|
'(ISO 32000-2 §14.8.2.5) with real heading levels, and extract_tables returns ' +
|
|
@@ -89,12 +107,14 @@ Args:
|
|
|
89
107
|
|
|
90
108
|
\`hasText\` is decided from page 1's preview and cannot say *why* text is absent. \`textExtractability\` answers that over every page (ISO 32000-2 §9.10.1): \`extracted\`, \`no_text_layer\` (image content, no text-showing operator — the page needs OCR or a rendered image), \`not_extractable\` (a font used offers no route to Unicode), or \`not_observed\` (encrypted or unreadable content stream). \`unreadablePages\` lists the pages that are not \`extracted\`, with the reason.
|
|
91
109
|
|
|
92
|
-
|
|
110
|
+
\`declaredConformance\` is what the XMP packet (ISO 32000-2 §14.3.2) declares — PDF/A (\`pdfaid\`), PDF/UA (\`pdfuaid\`) and the W3C TDMRep rights statement (\`tdm\`) — as written. A PDF/UA declaration is the author's claim that the structure tree is complete, which is the cue to read through it rather than infer reading order; it is not a verdict (that is pdf-verify-mcp validate_conformance). All-null blocks mean the catalog has no /Metadata; \`null\` means the packet could not be read (see \`scope\`).
|
|
111
|
+
|
|
112
|
+
The summary ends with a \`next\` list: tool suggestions derived from the observations themselves (hasText false → render_page; PDF/UA declared or tagged → extract_structured_text / extract_tables; large page count → search_text before read_text). Each line names the observation it follows from; nothing is enforced and no ordering is implied.
|
|
93
113
|
|
|
94
114
|
Returns:
|
|
95
115
|
Summary including: page count, PDF version, file size, tagged/encrypted/signature flags, text presence, per-document text extractability, the pages that are not fully extractable, image count, a text preview from page 1, and the \`next\` suggestions.
|
|
96
116
|
|
|
97
|
-
|
|
117
|
+
Five separate readings produce that summary — the document information, the text of page 1, the image count, the extractability observation, and the XMP declarations — and any of them can fail on its own. \`scope\` says which were done. A field whose reading did not happen is \`null\`, never \`0\`, \`false\` or \`""\`: "not read" and "read and found nothing" are different answers, and \`next\` stays silent about any premise that was not observed.
|
|
98
118
|
|
|
99
119
|
Examples:
|
|
100
120
|
- Quick overview: { file_path: "/path/to/doc.pdf" }
|
|
@@ -139,12 +159,17 @@ Examples:
|
|
|
139
159
|
// #21: over ALL pages, not just page 1. `hasText` is decided from the
|
|
140
160
|
// first page's preview, so a document whose page 1 happens to carry a
|
|
141
161
|
// title would otherwise report "has text" for 400 scanned pages behind it.
|
|
142
|
-
|
|
162
|
+
// #29: the XMP declarations are a 5th reading, through recover rather than pdfjs.
|
|
163
|
+
const [obs, xmp] = await Promise.all([
|
|
164
|
+
half(() => observeExtractability(params.file_path)),
|
|
165
|
+
half(() => readXmpDeclarations(params.file_path)),
|
|
166
|
+
]);
|
|
143
167
|
const scope = {
|
|
144
168
|
metadata: metadataOutcome,
|
|
145
169
|
textPreview: previewOutcome,
|
|
146
170
|
imageCount: imagesOutcome,
|
|
147
171
|
extractabilityObservation: obs.outcome,
|
|
172
|
+
xmpDeclarations: xmp.outcome,
|
|
148
173
|
};
|
|
149
174
|
// どれ 1 つ読めなかったときだけ、エラーにする。
|
|
150
175
|
if (!docHalf.ok && !obs.ok) {
|
|
@@ -173,7 +198,8 @@ Examples:
|
|
|
173
198
|
hasText: textPreview === null ? null : textPreview.trim().length > 0,
|
|
174
199
|
textExtractability,
|
|
175
200
|
unreadablePages,
|
|
176
|
-
|
|
201
|
+
declaredConformance: xmp.ok ? xmp.value : null,
|
|
202
|
+
next: suggestNext(metadata, textExtractability, unreadablePages, xmp.ok ? xmp.value : null),
|
|
177
203
|
};
|
|
178
204
|
const text = params.response_format === ResponseFormat.JSON
|
|
179
205
|
? JSON.stringify(summary, null, 2)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../../src/tools/tier1/summarize.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,GACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,IAAI,GAGL,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,+CAA+C,CAAC;
|
|
1
|
+
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../../src/tools/tier1/summarize.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAuB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,GACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,IAAI,GAGL,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAQpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,QAA4B,EAC5B,kBAAkD,EAClD,eAA4C,EAC5C,QAAgC;IAEhC,MAAM,IAAI,GAAa,EAAE,CAAC;IAE1B,mCAAmC;IACnC,+BAA+B;IAC/B,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,IAAI,QAAQ,CA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G,CAAC;YACpE,kBAAkB;YAClB,eAAe;YACf,mBAAmB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;YAC9C,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;SAC5F,CAAC;QAEF,MAAM,IAAI,GACR,MAAM,CAAC,eAAe,KAAK,cAAc,CAAC,IAAI;YAC5C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpF,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC;SAC3C,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* inspect_catalog - document-level inventory from the catalog dictionary (#27).
|
|
3
|
+
*/
|
|
4
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
5
|
+
export declare function registerInspectCatalog(server: McpServer): void;
|
|
6
|
+
//# sourceMappingURL=inspect-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect-catalog.d.ts","sourceRoot":"","sources":["../../../src/tools/tier2/inspect-catalog.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAO9D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA8D9D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ResponseFormat } from '../../constants.js';
|
|
2
|
+
import { InspectCatalogSchema } from '../../schemas/tier2.js';
|
|
3
|
+
import { applyXmpPolicy, inspectCatalog } from '../../services/catalog-service.js';
|
|
4
|
+
import { handleStructuredError } from '../../utils/error-handler.js';
|
|
5
|
+
import { formatCatalogMarkdown, truncateIfNeeded } from '../../utils/formatter.js';
|
|
6
|
+
export function registerInspectCatalog(server) {
|
|
7
|
+
server.registerTool('inspect_catalog', {
|
|
8
|
+
title: 'Inspect PDF Catalog',
|
|
9
|
+
description: `List the document-level components hanging off the catalog dictionary (ISO 32000-2 §7.7.2, Table 29) — the parts of a PDF that are not page content and that page-oriented readers drop: bookmarks, layers, attachments, the XMP packet, and the actions that run when the document is opened.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
- file_path (string): Absolute path to a local PDF file
|
|
13
|
+
- max_outline_items (integer, 1-500, default 50): how many bookmark items to list (count and depth cover the whole tree)
|
|
14
|
+
- include_xmp (boolean, default false): also return the XMP packet text (capped at 64 KiB)
|
|
15
|
+
- response_format ('markdown' | 'json'): Output format (default: 'markdown')
|
|
16
|
+
|
|
17
|
+
Returns, per entry:
|
|
18
|
+
- outlines (/Outlines, §12.3.3): item count, depth, and the first items with title and target page
|
|
19
|
+
- optionalContent (/OCProperties, §8.11.4): every layer's /Name, and the default configuration's BaseState / ON / OFF counts
|
|
20
|
+
- embeddedFiles (/Names → /EmbeddedFiles, §7.7.4 / §7.11.4): file name, MIME type, size, /AFRelationship, description
|
|
21
|
+
- associatedFiles (/AF, §14.13): count at document level
|
|
22
|
+
- names: counts of the /Dests and /JavaScript name trees (document-level ECMAScript runs on open, §12.6.4.17)
|
|
23
|
+
- metadata (/Metadata, §14.3.2): packet size, namespaces present, and the DECLARED values of pdfaid:*, pdfuaid:part and the W3C TDMRep tdm:reservation / tdm:policy
|
|
24
|
+
- openAction (/OpenAction) and additionalActions (/AA, Table 200): action type (/S), target page or file or URI, whether /JS is present, length of the /Next chain
|
|
25
|
+
- collection (/Collection, §12.3.5): whether the document is a portfolio
|
|
26
|
+
|
|
27
|
+
Each entry distinguishes { status: "absent" } (the catalog has no such key — an observed fact) from { status: "unreadable", reason } (the key is there but its value could not be reached). An encrypted document whose key cannot be derived reports every entry as unreadable, never as absent.
|
|
28
|
+
|
|
29
|
+
This tool reports what is written. A pdfuaid:part declaration is a claim about the structure tree, not a verdict on it (that is pdf-verify-mcp validate_conformance); tdm:reservation is the rights holder's statement, and whether to honour it is the caller's decision; an action with /JS is reported, not judged.
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
- Find out whether a document carries attachments, layers or bookmarks before deciding how to read it
|
|
33
|
+
- Read the XMP declarations (PDF/A, PDF/UA, TDMRep) that get_metadata, which reads the Info dictionary, does not see
|
|
34
|
+
- See what a document will execute when opened (/OpenAction, /AA, document-level JavaScript)`,
|
|
35
|
+
inputSchema: InspectCatalogSchema,
|
|
36
|
+
annotations: {
|
|
37
|
+
readOnlyHint: true,
|
|
38
|
+
destructiveHint: false,
|
|
39
|
+
idempotentHint: true,
|
|
40
|
+
openWorldHint: false,
|
|
41
|
+
},
|
|
42
|
+
}, async (params) => {
|
|
43
|
+
try {
|
|
44
|
+
const inventory = await inspectCatalog(params.file_path, {
|
|
45
|
+
maxOutlineItems: params.max_outline_items,
|
|
46
|
+
});
|
|
47
|
+
const output = applyXmpPolicy(inventory, params.include_xmp);
|
|
48
|
+
const raw = params.response_format === ResponseFormat.JSON
|
|
49
|
+
? JSON.stringify(output, null, 2)
|
|
50
|
+
: formatCatalogMarkdown(output);
|
|
51
|
+
const { text } = truncateIfNeeded(raw);
|
|
52
|
+
return { content: [{ type: 'text', text }] };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const err = handleStructuredError(error);
|
|
56
|
+
return {
|
|
57
|
+
content: [{ type: 'text', text: JSON.stringify(err, null, 2) }],
|
|
58
|
+
isError: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=inspect-catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect-catalog.js","sourceRoot":"","sources":["../../../src/tools/tier2/inspect-catalog.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAA4B,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEnF,MAAM,UAAU,sBAAsB,CAAC,MAAiB;IACtD,MAAM,CAAC,YAAY,CACjB,iBAAiB,EACjB;QACE,KAAK,EAAE,qBAAqB;QAC5B,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;+FAyB4E;QACzF,WAAW,EAAE,oBAAoB;QACjC,WAAW,EAAE;YACX,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF,EACD,KAAK,EAAE,MAA2B,EAAE,EAAE;QACpC,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE;gBACvD,eAAe,EAAE,MAAM,CAAC,iBAAiB;aAC1C,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YAE7D,MAAM,GAAG,GACP,MAAM,CAAC,eAAe,KAAK,cAAc,CAAC,IAAI;gBAC5C,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBACjC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;YAEpC,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;YACvC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;YACzC,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBACxE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -184,6 +184,13 @@ export interface PdfSummary {
|
|
|
184
184
|
textExtractability: TextExtractabilityState | null;
|
|
185
185
|
/** The pages that are not `extracted`, so the caller can go straight to them. */
|
|
186
186
|
unreadablePages: PageExtractability[] | null;
|
|
187
|
+
/**
|
|
188
|
+
* What the XMP packet declares (#29): PDF/A, PDF/UA and TDMRep, **as written**. A
|
|
189
|
+
* `pdfuaid` block is the author's claim that the structure tree is complete — the cue
|
|
190
|
+
* to prefer the structure route — not a verdict on it. `null` when the packet could not
|
|
191
|
+
* be read; all-null blocks when the catalog has no `/Metadata` at all.
|
|
192
|
+
*/
|
|
193
|
+
declaredConformance: XmpDeclarations | null;
|
|
187
194
|
/**
|
|
188
195
|
* What to call next, decided from the observations above (#24).
|
|
189
196
|
*
|
|
@@ -605,4 +612,194 @@ export interface ObjectLocationResult {
|
|
|
605
612
|
isEncrypted: boolean;
|
|
606
613
|
notes: string[];
|
|
607
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* What the document-level XMP packet declares. Every value here is **as written** —
|
|
617
|
+
* a declaration, not a verified property. `null` for a block means that block's
|
|
618
|
+
* properties were not found in the packet.
|
|
619
|
+
*/
|
|
620
|
+
export interface XmpDeclarations {
|
|
621
|
+
/** PDF/A identification (`pdfaid:part` / `pdfaid:conformance`). Verified by pdf-verify-mcp, not here. */
|
|
622
|
+
pdfaid: {
|
|
623
|
+
part: number | null;
|
|
624
|
+
conformance: string | null;
|
|
625
|
+
} | null;
|
|
626
|
+
/** PDF/UA identification (`pdfuaid:part`). A claim about the structure tree, not a verdict on it. */
|
|
627
|
+
pdfuaid: {
|
|
628
|
+
part: number | null;
|
|
629
|
+
} | null;
|
|
630
|
+
/**
|
|
631
|
+
* W3C TDM Reservation Protocol (TDMRep), Final Community Group Report 2024-05-10, §6.6.
|
|
632
|
+
* Namespace `http://www.w3.org/ns/tdmrep/` (the report's EPUB section writes `…tdmrep#`;
|
|
633
|
+
* both are accepted). `reservation` is 1 when the rights holder reserves text-and-data-mining
|
|
634
|
+
* rights, 0 when they do not — the report (§5.1) says any other value is a protocol error to
|
|
635
|
+
* be treated as unset; it is returned here as written. `policy` is the URL of the TDM policy
|
|
636
|
+
* when one is given. This server reports the statement; whether to honour it is the caller's
|
|
637
|
+
* decision (#28).
|
|
638
|
+
*/
|
|
639
|
+
tdm: {
|
|
640
|
+
reservation: number | null;
|
|
641
|
+
policy: string | null;
|
|
642
|
+
} | null;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* The document-level `/Metadata` stream. `null` at the call site means the catalog has no
|
|
646
|
+
* `/Metadata` key — the packet is **absent**. `unreadable` means the key is there but the
|
|
647
|
+
* stream could not be reached or decoded; nothing can be said about what it declares.
|
|
648
|
+
*/
|
|
649
|
+
export type XmpMetadataInfo = {
|
|
650
|
+
status: 'read';
|
|
651
|
+
/** Decoded packet length in bytes. */
|
|
652
|
+
bytes: number;
|
|
653
|
+
/** `/Subtype` of the stream dictionary (`XML` per §14.3.2), or null when not written. */
|
|
654
|
+
subtype: string | null;
|
|
655
|
+
/** Every `xmlns:` declaration in the packet, so a caller can see which vocabularies are present. */
|
|
656
|
+
namespaces: {
|
|
657
|
+
prefix: string;
|
|
658
|
+
uri: string;
|
|
659
|
+
}[];
|
|
660
|
+
declarations: XmpDeclarations;
|
|
661
|
+
/** The packet text. Present from the service; dropped from the tool output unless `include_xmp` is set. */
|
|
662
|
+
xml?: string;
|
|
663
|
+
} | {
|
|
664
|
+
status: 'unreadable';
|
|
665
|
+
reason: string;
|
|
666
|
+
};
|
|
667
|
+
/** One outline item (§12.3.3), flattened with its depth. */
|
|
668
|
+
export interface OutlineItemInfo {
|
|
669
|
+
title: string | null;
|
|
670
|
+
/** 1 for a top-level item. */
|
|
671
|
+
depth: number;
|
|
672
|
+
/**
|
|
673
|
+
* Where the item points. `page` is 1-based when the destination names a page object in
|
|
674
|
+
* this document's page tree; `named` carries a named destination that was not resolved;
|
|
675
|
+
* `action` is the `/S` of an action dictionary used instead of a destination.
|
|
676
|
+
*/
|
|
677
|
+
page: number | null;
|
|
678
|
+
named: string | null;
|
|
679
|
+
action: string | null;
|
|
680
|
+
}
|
|
681
|
+
export interface OutlinesInfo {
|
|
682
|
+
/** All items in the tree, counted by walking `/First` / `/Next` (not `/Count`, which may be wrong). */
|
|
683
|
+
count: number;
|
|
684
|
+
maxDepth: number;
|
|
685
|
+
/** The first `max_outline_items` items in document order. */
|
|
686
|
+
items: OutlineItemInfo[];
|
|
687
|
+
truncated: boolean;
|
|
688
|
+
}
|
|
689
|
+
/** Optional content (layers), §8.11.4. */
|
|
690
|
+
export interface OptionalContentInfo {
|
|
691
|
+
/** `/OCGs` — every optional content group, with its `/Name`. */
|
|
692
|
+
groups: {
|
|
693
|
+
name: string | null;
|
|
694
|
+
ref: string | null;
|
|
695
|
+
}[];
|
|
696
|
+
/** The default configuration `/D` (§8.11.4.3). */
|
|
697
|
+
defaultConfig: {
|
|
698
|
+
name: string | null;
|
|
699
|
+
baseState: 'ON' | 'OFF' | 'Unchanged' | null;
|
|
700
|
+
on: number;
|
|
701
|
+
off: number;
|
|
702
|
+
} | null;
|
|
703
|
+
/** Number of alternate configurations in `/Configs`. */
|
|
704
|
+
alternateConfigs: number;
|
|
705
|
+
}
|
|
706
|
+
/** One entry of the `/EmbeddedFiles` name tree (§7.7.4, §7.11.4). */
|
|
707
|
+
export interface EmbeddedFileInfo {
|
|
708
|
+
/** The name-tree key. */
|
|
709
|
+
key: string;
|
|
710
|
+
/** `/UF` when present, else `/F`, of the file specification dictionary. */
|
|
711
|
+
fileName: string | null;
|
|
712
|
+
/** `/Subtype` of the embedded file stream — a MIME type written as a name. */
|
|
713
|
+
mimeType: string | null;
|
|
714
|
+
/** `/Params /Size` when written, else the decoded stream length when the stream was readable. */
|
|
715
|
+
size: number | null;
|
|
716
|
+
/** `/AFRelationship` of the file specification (PDF 2.0, Table 43). */
|
|
717
|
+
afRelationship: string | null;
|
|
718
|
+
description: string | null;
|
|
719
|
+
}
|
|
720
|
+
export interface EmbeddedFilesInfo {
|
|
721
|
+
count: number;
|
|
722
|
+
files: EmbeddedFileInfo[];
|
|
723
|
+
/** Leaves of the name tree whose file specification could not be read. */
|
|
724
|
+
unreadable: number;
|
|
725
|
+
}
|
|
726
|
+
/** Document-level name trees other than `/EmbeddedFiles` (§7.7.4, Table 32). Counts only. */
|
|
727
|
+
export interface NameTreesInfo {
|
|
728
|
+
/** `/Dests` — named destinations. */
|
|
729
|
+
dests: number | null;
|
|
730
|
+
/** `/JavaScript` — document-level ECMAScript actions (§12.6.4.17). Runs when the document opens. */
|
|
731
|
+
javaScript: number | null;
|
|
732
|
+
}
|
|
733
|
+
/** An action dictionary (§12.6.2) or an explicit destination, as it appears at a trigger. */
|
|
734
|
+
export interface ActionInfo {
|
|
735
|
+
/** `/S` of the action; `Destination` when the trigger holds a destination rather than an action. */
|
|
736
|
+
type: string;
|
|
737
|
+
/** For `GoTo`-like actions and destinations: the 1-based target page when resolved. */
|
|
738
|
+
page: number | null;
|
|
739
|
+
/** `/F` for `Launch` / `GoToR` / `GoToE` / `ImportData`, as a file name when readable. */
|
|
740
|
+
file: string | null;
|
|
741
|
+
/** `/URI` for `URI` actions. */
|
|
742
|
+
uri: string | null;
|
|
743
|
+
/** A named destination (§12.3.2.4) that was not resolved to a page. */
|
|
744
|
+
named: string | null;
|
|
745
|
+
/** Whether the dictionary carries `/JS` (ECMAScript). */
|
|
746
|
+
hasJavaScript: boolean;
|
|
747
|
+
/** `/S` of each further action in the `/Next` chain (§12.6.2), in order; empty when none. */
|
|
748
|
+
next: string[];
|
|
749
|
+
}
|
|
750
|
+
export interface CatalogInventory {
|
|
751
|
+
/**
|
|
752
|
+
* `absent` = the catalog has no such key (an observed fact). `unreadable` = the key is
|
|
753
|
+
* there but its value could not be resolved; nothing below it is known.
|
|
754
|
+
*/
|
|
755
|
+
outlines: OutlinesInfo | {
|
|
756
|
+
status: 'absent';
|
|
757
|
+
} | {
|
|
758
|
+
status: 'unreadable';
|
|
759
|
+
reason: string;
|
|
760
|
+
};
|
|
761
|
+
optionalContent: OptionalContentInfo | {
|
|
762
|
+
status: 'absent';
|
|
763
|
+
} | {
|
|
764
|
+
status: 'unreadable';
|
|
765
|
+
reason: string;
|
|
766
|
+
};
|
|
767
|
+
embeddedFiles: EmbeddedFilesInfo | {
|
|
768
|
+
status: 'absent';
|
|
769
|
+
} | {
|
|
770
|
+
status: 'unreadable';
|
|
771
|
+
reason: string;
|
|
772
|
+
};
|
|
773
|
+
/** Associated files at document level (`/AF`, PDF 2.0 §14.13). */
|
|
774
|
+
associatedFiles: number | null;
|
|
775
|
+
names: NameTreesInfo | {
|
|
776
|
+
status: 'absent';
|
|
777
|
+
} | {
|
|
778
|
+
status: 'unreadable';
|
|
779
|
+
reason: string;
|
|
780
|
+
};
|
|
781
|
+
/** `/Metadata`. `absent` when the catalog has no such key. */
|
|
782
|
+
metadata: XmpMetadataInfo | {
|
|
783
|
+
status: 'absent';
|
|
784
|
+
};
|
|
785
|
+
/** `/OpenAction` — what happens when the document is opened (§7.7.2). */
|
|
786
|
+
openAction: ActionInfo | {
|
|
787
|
+
status: 'absent';
|
|
788
|
+
} | {
|
|
789
|
+
status: 'unreadable';
|
|
790
|
+
reason: string;
|
|
791
|
+
};
|
|
792
|
+
/** `/AA` — document-level trigger events (§12.6.3, Table 200: WC, WS, DS, WP, DP). */
|
|
793
|
+
additionalActions: Record<string, ActionInfo> | {
|
|
794
|
+
status: 'absent';
|
|
795
|
+
} | {
|
|
796
|
+
status: 'unreadable';
|
|
797
|
+
reason: string;
|
|
798
|
+
};
|
|
799
|
+
/** `/Collection` — the document is a portfolio (§12.3.5). */
|
|
800
|
+
collection: boolean;
|
|
801
|
+
isEncrypted: boolean;
|
|
802
|
+
/** Set when nothing below the catalog could be read (encrypted, key not derivable). */
|
|
803
|
+
note?: string;
|
|
804
|
+
}
|
|
608
805
|
//# sourceMappingURL=types.d.ts.map
|