@shuji-bonji/pdf-reader-mcp 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/README.ja.md +11 -6
- package/README.md +13 -6
- package/dist/services/actual-text-service.d.ts +4 -3
- package/dist/services/actual-text-service.d.ts.map +1 -1
- package/dist/services/actual-text-service.js +5 -4
- package/dist/services/actual-text-service.js.map +1 -1
- package/dist/services/content-stream-service.d.ts +45 -13
- package/dist/services/content-stream-service.d.ts.map +1 -1
- package/dist/services/content-stream-service.js +209 -174
- package/dist/services/content-stream-service.js.map +1 -1
- package/dist/services/font-service.d.ts +35 -0
- package/dist/services/font-service.d.ts.map +1 -0
- package/dist/services/font-service.js +127 -0
- package/dist/services/font-service.js.map +1 -0
- package/dist/services/object-locator.d.ts.map +1 -1
- package/dist/services/object-locator.js +163 -107
- package/dist/services/object-locator.js.map +1 -1
- package/dist/services/pdfjs-service.d.ts +18 -14
- package/dist/services/pdfjs-service.d.ts.map +1 -1
- package/dist/services/pdfjs-service.js +19 -14
- package/dist/services/pdfjs-service.js.map +1 -1
- package/dist/services/recover-service.d.ts +64 -0
- package/dist/services/recover-service.d.ts.map +1 -0
- package/dist/services/recover-service.js +104 -0
- package/dist/services/recover-service.js.map +1 -0
- package/dist/services/signature-service.d.ts +28 -0
- package/dist/services/signature-service.d.ts.map +1 -0
- package/dist/services/signature-service.js +200 -0
- package/dist/services/signature-service.js.map +1 -0
- package/dist/services/struct-tree-service.d.ts +0 -6
- package/dist/services/struct-tree-service.d.ts.map +1 -1
- package/dist/services/struct-tree-service.js +56 -49
- package/dist/services/struct-tree-service.js.map +1 -1
- package/dist/services/struct-tree-walker.d.ts +13 -4
- package/dist/services/struct-tree-walker.d.ts.map +1 -1
- package/dist/services/struct-tree-walker.js +133 -87
- package/dist/services/struct-tree-walker.js.map +1 -1
- package/dist/services/structure-service.d.ts +57 -0
- package/dist/services/structure-service.d.ts.map +1 -0
- package/dist/services/structure-service.js +237 -0
- package/dist/services/structure-service.js.map +1 -0
- package/dist/services/text-extractability-service.d.ts +11 -0
- package/dist/services/text-extractability-service.d.ts.map +1 -1
- package/dist/services/text-extractability-service.js +83 -52
- package/dist/services/text-extractability-service.js.map +1 -1
- package/dist/services/validation-service.d.ts.map +1 -1
- package/dist/services/validation-service.js +4 -3
- package/dist/services/validation-service.js.map +1 -1
- package/dist/tools/tier1/search-text.js +1 -1
- package/dist/tools/tier1/search-text.js.map +1 -1
- package/dist/tools/tier2/inspect-fonts.js +2 -2
- package/dist/tools/tier2/inspect-fonts.js.map +1 -1
- package/dist/tools/tier2/inspect-signatures.js +1 -1
- package/dist/tools/tier2/inspect-signatures.js.map +1 -1
- package/dist/tools/tier2/inspect-structure.d.ts.map +1 -1
- package/dist/tools/tier2/inspect-structure.js +9 -2
- package/dist/tools/tier2/inspect-structure.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +24 -5
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +13 -1
- package/dist/utils/formatter.js.map +1 -1
- package/package.json +4 -2
- package/dist/services/pdflib-service.d.ts +0 -81
- package/dist/services/pdflib-service.d.ts.map +0 -1
- package/dist/services/pdflib-service.js +0 -504
- package/dist/services/pdflib-service.js.map +0 -1
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pdf-lib wrapper service.
|
|
3
|
-
*
|
|
4
|
-
* Provides low-level PDF structure access via pdf-lib for Tier 2 tools.
|
|
5
|
-
* Runs alongside pdfjs-service.ts (which handles text/image extraction).
|
|
6
|
-
*/
|
|
7
|
-
import { PDFDocument } from 'pdf-lib';
|
|
8
|
-
import type { FontInfo, SignaturesAnalysis, StructureAnalysis } from '../types.js';
|
|
9
|
-
/**
|
|
10
|
-
* Load a PDF document with pdf-lib.
|
|
11
|
-
*
|
|
12
|
-
* Uses `throwOnInvalidObject: false` so that Linearized PDFs (whose hint
|
|
13
|
-
* streams cannot be resolved by pdf-lib) still load instead of throwing.
|
|
14
|
-
* The actual page-tree access may still throw — see `trySilently` below.
|
|
15
|
-
*/
|
|
16
|
-
export declare function loadWithPdfLib(filePath: string): Promise<PDFDocument>;
|
|
17
|
-
/**
|
|
18
|
-
* The same, for bytes already in memory — `read_url` has the PDF but no path.
|
|
19
|
-
*/
|
|
20
|
-
export declare function loadWithPdfLibFromData(data: Uint8Array): Promise<PDFDocument>;
|
|
21
|
-
/**
|
|
22
|
-
* Check if a PDF is encrypted.
|
|
23
|
-
*/
|
|
24
|
-
export declare function detectEncryption(filePath: string): Promise<boolean>;
|
|
25
|
-
/**
|
|
26
|
-
* Analyze PDF internal structure (catalog, page tree, objects).
|
|
27
|
-
*
|
|
28
|
-
* Linearized PDFs (typical of public-sector publishers) confuse pdf-lib's
|
|
29
|
-
* cross-reference resolver, so `getPages()` and `getPageCount()` throw
|
|
30
|
-
* `Expected instance of PDFDict, but got instance of undefined`. We catch
|
|
31
|
-
* those failures, fall back to pdfjs-dist for the page count, and attach
|
|
32
|
-
* a `note` describing the partial result. The catalog walk and object
|
|
33
|
-
* enumeration still work in this state, so the user gets meaningful output
|
|
34
|
-
* instead of a hard error.
|
|
35
|
-
*/
|
|
36
|
-
export declare function analyzeStructure(filePath: string): Promise<StructureAnalysis>;
|
|
37
|
-
/** Font analysis result including font map and total pages scanned */
|
|
38
|
-
export interface FontAnalysisResult {
|
|
39
|
-
fontMap: Map<string, FontInfo>;
|
|
40
|
-
pagesScanned: number;
|
|
41
|
-
/**
|
|
42
|
-
* Optional human-readable note describing partial / fallback results.
|
|
43
|
-
* Set when the page tree could not be enumerated (Linearized PDFs).
|
|
44
|
-
*/
|
|
45
|
-
note?: string;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Analyze fonts across all pages using pdf-lib's low-level access.
|
|
49
|
-
* Returns font map and total pages scanned.
|
|
50
|
-
*
|
|
51
|
-
* Linearized PDFs cannot have their page tree enumerated by pdf-lib — instead
|
|
52
|
-
* of throwing, we return an empty font map with `note` describing the limitation,
|
|
53
|
-
* so that the caller can still produce a useful response.
|
|
54
|
-
*/
|
|
55
|
-
export declare function analyzeFontsWithPdfLib(filePath: string): Promise<FontAnalysisResult>;
|
|
56
|
-
/**
|
|
57
|
-
* Analyze digital signature fields.
|
|
58
|
-
*/
|
|
59
|
-
export declare function analyzeSignatures(filePath: string): Promise<SignaturesAnalysis>;
|
|
60
|
-
/**
|
|
61
|
-
* Resolve the PDF version the document conforms to.
|
|
62
|
-
*
|
|
63
|
-
* ISO 32000-2 Table 29 (Version) makes the catalog entry conditional, not
|
|
64
|
-
* authoritative: it is the version "to which the document conforms … **if later
|
|
65
|
-
* than the version specified in the file's header**. If the header specifies a
|
|
66
|
-
* later version, or if this entry is absent, the document shall conform to the
|
|
67
|
-
* version specified in the header."
|
|
68
|
-
*
|
|
69
|
-
* So the answer is the later of the two. The previous code returned the catalog
|
|
70
|
-
* entry unconditionally whenever it existed, which reports the wrong version for
|
|
71
|
-
* a file whose header is newer — the exact case Table 29 calls out. (The entry
|
|
72
|
-
* exists so a version can be *raised* by an incremental update; see §7.5.6.)
|
|
73
|
-
*
|
|
74
|
-
* A malformed catalog entry cannot be shown to specify a later version, so the
|
|
75
|
-
* header wins by default.
|
|
76
|
-
*
|
|
77
|
-
* Exported for unit testing — the interesting cases (header newer, versions
|
|
78
|
-
* equal, catalog malformed) would each need a hand-built PDF otherwise.
|
|
79
|
-
*/
|
|
80
|
-
export declare function resolvePdfVersion(headerVersion: string | null, catalogVersion: string | null): string | null;
|
|
81
|
-
//# sourceMappingURL=pdflib-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdflib-service.d.ts","sourceRoot":"","sources":["../../src/services/pdflib-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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
|
5
|
-
* Runs alongside pdfjs-service.ts (which handles text/image extraction).
|
|
6
|
-
*/
|
|
7
|
-
import { open } from 'node:fs/promises';
|
|
8
|
-
import { PDFArray, PDFDict, PDFDocument, PDFHexString, PDFName, PDFNumber, PDFRef, PDFStream, PDFString, } from 'pdf-lib';
|
|
9
|
-
import { readPdfFile } from '../utils/pdf-helpers.js';
|
|
10
|
-
/**
|
|
11
|
-
* pdf-lib emits parser diagnostics via `console.log` (not `console.warn`),
|
|
12
|
-
* which on stdio MCP servers pollutes the JSON-RPC stream. Wrap any pdf-lib
|
|
13
|
-
* call site with this to silence those warnings without losing real errors.
|
|
14
|
-
*/
|
|
15
|
-
async function withSuppressedPdfLibLogs(fn) {
|
|
16
|
-
const originalLog = console.log;
|
|
17
|
-
console.log = () => { };
|
|
18
|
-
try {
|
|
19
|
-
return await fn();
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
console.log = originalLog;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Load a PDF document with pdf-lib.
|
|
27
|
-
*
|
|
28
|
-
* Uses `throwOnInvalidObject: false` so that Linearized PDFs (whose hint
|
|
29
|
-
* streams cannot be resolved by pdf-lib) still load instead of throwing.
|
|
30
|
-
* The actual page-tree access may still throw — see `trySilently` below.
|
|
31
|
-
*/
|
|
32
|
-
export async function loadWithPdfLib(filePath) {
|
|
33
|
-
return loadWithPdfLibFromData(await readPdfFile(filePath));
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* The same, for bytes already in memory — `read_url` has the PDF but no path.
|
|
37
|
-
*/
|
|
38
|
-
export async function loadWithPdfLibFromData(data) {
|
|
39
|
-
return withSuppressedPdfLibLogs(() => PDFDocument.load(data, {
|
|
40
|
-
ignoreEncryption: true,
|
|
41
|
-
updateMetadata: false,
|
|
42
|
-
throwOnInvalidObject: false,
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Try `fn()`, swallowing pdf-lib parse errors and pdf-lib's own
|
|
47
|
-
* `console.log` chatter. Returns `undefined` on failure.
|
|
48
|
-
*
|
|
49
|
-
* Used to make best-effort calls against documents whose cross-reference
|
|
50
|
-
* tables are partially unresolvable (Linearized PDFs are the typical case —
|
|
51
|
-
* pdf-lib cannot follow `/Linearized` hint streams, so `getPages()` and
|
|
52
|
-
* similar accessors throw `Expected instance of PDFDict, but got undefined`).
|
|
53
|
-
*/
|
|
54
|
-
function trySilently(fn) {
|
|
55
|
-
const originalLog = console.log;
|
|
56
|
-
console.log = () => { };
|
|
57
|
-
try {
|
|
58
|
-
return fn();
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
console.log = originalLog;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Check if a PDF is encrypted.
|
|
69
|
-
*/
|
|
70
|
-
export async function detectEncryption(filePath) {
|
|
71
|
-
try {
|
|
72
|
-
const data = await readPdfFile(filePath);
|
|
73
|
-
const doc = await withSuppressedPdfLibLogs(() => PDFDocument.load(data, {
|
|
74
|
-
ignoreEncryption: true,
|
|
75
|
-
updateMetadata: false,
|
|
76
|
-
}));
|
|
77
|
-
return doc.isEncrypted;
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Analyze PDF internal structure (catalog, page tree, objects).
|
|
85
|
-
*
|
|
86
|
-
* Linearized PDFs (typical of public-sector publishers) confuse pdf-lib's
|
|
87
|
-
* cross-reference resolver, so `getPages()` and `getPageCount()` throw
|
|
88
|
-
* `Expected instance of PDFDict, but got instance of undefined`. We catch
|
|
89
|
-
* those failures, fall back to pdfjs-dist for the page count, and attach
|
|
90
|
-
* a `note` describing the partial result. The catalog walk and object
|
|
91
|
-
* enumeration still work in this state, so the user gets meaningful output
|
|
92
|
-
* instead of a hard error.
|
|
93
|
-
*/
|
|
94
|
-
export async function analyzeStructure(filePath) {
|
|
95
|
-
return withSuppressedPdfLibLogs(() => analyzeStructureImpl(filePath));
|
|
96
|
-
}
|
|
97
|
-
async function analyzeStructureImpl(filePath) {
|
|
98
|
-
const doc = await loadWithPdfLib(filePath);
|
|
99
|
-
const catalog = doc.catalog;
|
|
100
|
-
const context = doc.context;
|
|
101
|
-
// Extract catalog entries (best-effort: tolerate per-entry failures)
|
|
102
|
-
const catalogEntries = [];
|
|
103
|
-
try {
|
|
104
|
-
for (const [key, value] of catalog.entries()) {
|
|
105
|
-
catalogEntries.push({
|
|
106
|
-
key: key.decodeText(),
|
|
107
|
-
type: value.constructor.name,
|
|
108
|
-
value: summarizeObject(value),
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
// catalog.entries() should rarely throw, but keep the partial list
|
|
114
|
-
}
|
|
115
|
-
// Page tree info (best-effort — fall back to pdfjs-dist for Linearized PDFs)
|
|
116
|
-
let totalPages = trySilently(() => doc.getPageCount()) ?? 0;
|
|
117
|
-
const pages = trySilently(() => doc.getPages()) ?? [];
|
|
118
|
-
const maxSamples = Math.min(pages.length, 5);
|
|
119
|
-
const mediaBoxSamples = [];
|
|
120
|
-
for (let i = 0; i < maxSamples; i++) {
|
|
121
|
-
const box = trySilently(() => pages[i].getMediaBox());
|
|
122
|
-
if (!box)
|
|
123
|
-
continue;
|
|
124
|
-
mediaBoxSamples.push({
|
|
125
|
-
page: i + 1,
|
|
126
|
-
width: Math.round(box.width * 100) / 100,
|
|
127
|
-
height: Math.round(box.height * 100) / 100,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
let note;
|
|
131
|
-
if (totalPages === 0 && pages.length === 0) {
|
|
132
|
-
// pdf-lib couldn't traverse the page tree — try pdfjs-dist as fallback.
|
|
133
|
-
try {
|
|
134
|
-
const { loadDocument } = await import('./pdfjs-service.js');
|
|
135
|
-
const pdfjsDoc = await loadDocument(filePath);
|
|
136
|
-
try {
|
|
137
|
-
totalPages = pdfjsDoc.numPages;
|
|
138
|
-
note =
|
|
139
|
-
'pdf-lib could not fully resolve the page tree (typical of Linearized PDFs); ' +
|
|
140
|
-
'totalPages was obtained via pdfjs-dist. mediaBox samples are unavailable.';
|
|
141
|
-
}
|
|
142
|
-
finally {
|
|
143
|
-
await pdfjsDoc.destroy();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
// Even pdfjs failed — keep totalPages = 0
|
|
148
|
-
note = 'Page tree could not be resolved by either pdf-lib or pdfjs-dist.';
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const pageTree = {
|
|
152
|
-
totalPages,
|
|
153
|
-
mediaBoxSamples,
|
|
154
|
-
};
|
|
155
|
-
// Object statistics (best-effort)
|
|
156
|
-
const byType = {};
|
|
157
|
-
let streamCount = 0;
|
|
158
|
-
let totalObjects = 0;
|
|
159
|
-
const allObjects = trySilently(() => context.enumerateIndirectObjects()) ?? [];
|
|
160
|
-
for (const [_ref, obj] of allObjects) {
|
|
161
|
-
const typeName = obj.constructor.name;
|
|
162
|
-
byType[typeName] = (byType[typeName] ?? 0) + 1;
|
|
163
|
-
if (obj instanceof PDFStream) {
|
|
164
|
-
streamCount++;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
totalObjects = allObjects.length;
|
|
168
|
-
const objectStats = {
|
|
169
|
-
totalObjects,
|
|
170
|
-
streamCount,
|
|
171
|
-
byType,
|
|
172
|
-
};
|
|
173
|
-
// PDF version: the LATER of the file header and the catalog's /Version.
|
|
174
|
-
// Table 29 does not let the catalog simply win — see resolvePdfVersion.
|
|
175
|
-
// The catalog entry "shall be a name object, not a number", hence PDFName.
|
|
176
|
-
const headerVersion = await readHeaderVersion(filePath);
|
|
177
|
-
const catalogVersion = trySilently(() => catalog.lookupMaybe(PDFName.of('Version'), PDFName))?.decodeText() ?? null;
|
|
178
|
-
const pdfVersion = resolvePdfVersion(headerVersion, catalogVersion);
|
|
179
|
-
const result = {
|
|
180
|
-
catalog: catalogEntries,
|
|
181
|
-
pageTree,
|
|
182
|
-
objectStats,
|
|
183
|
-
isEncrypted: doc.isEncrypted,
|
|
184
|
-
pdfVersion,
|
|
185
|
-
};
|
|
186
|
-
if (note)
|
|
187
|
-
result.note = note;
|
|
188
|
-
return result;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Analyze fonts across all pages using pdf-lib's low-level access.
|
|
192
|
-
* Returns font map and total pages scanned.
|
|
193
|
-
*
|
|
194
|
-
* Linearized PDFs cannot have their page tree enumerated by pdf-lib — instead
|
|
195
|
-
* of throwing, we return an empty font map with `note` describing the limitation,
|
|
196
|
-
* so that the caller can still produce a useful response.
|
|
197
|
-
*/
|
|
198
|
-
export async function analyzeFontsWithPdfLib(filePath) {
|
|
199
|
-
return withSuppressedPdfLibLogs(() => analyzeFontsWithPdfLibImpl(filePath));
|
|
200
|
-
}
|
|
201
|
-
async function analyzeFontsWithPdfLibImpl(filePath) {
|
|
202
|
-
const doc = await loadWithPdfLib(filePath);
|
|
203
|
-
const fontMap = new Map();
|
|
204
|
-
const pages = trySilently(() => doc.getPages()) ?? [];
|
|
205
|
-
if (pages.length === 0) {
|
|
206
|
-
return {
|
|
207
|
-
fontMap,
|
|
208
|
-
pagesScanned: 0,
|
|
209
|
-
note: 'pdf-lib could not enumerate the page tree (typical of Linearized PDFs); ' +
|
|
210
|
-
'fonts could not be analyzed. Consider regenerating the PDF without linearization.',
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
for (let pageIdx = 0; pageIdx < pages.length; pageIdx++) {
|
|
214
|
-
const pageNum = pageIdx + 1;
|
|
215
|
-
const pageNode = pages[pageIdx].node;
|
|
216
|
-
const resources = trySilently(() => pageNode.Resources());
|
|
217
|
-
if (!resources)
|
|
218
|
-
continue;
|
|
219
|
-
const fontDict = trySilently(() => resources.lookupMaybe(PDFName.of('Font'), PDFDict));
|
|
220
|
-
if (!fontDict)
|
|
221
|
-
continue;
|
|
222
|
-
for (const [fontNameObj, fontRefOrDict] of fontDict.entries()) {
|
|
223
|
-
const fontKey = fontNameObj.decodeText();
|
|
224
|
-
// Resolve to actual font dictionary
|
|
225
|
-
let actualFont;
|
|
226
|
-
if (fontRefOrDict instanceof PDFRef) {
|
|
227
|
-
const resolved = doc.context.lookup(fontRefOrDict);
|
|
228
|
-
if (resolved instanceof PDFDict) {
|
|
229
|
-
actualFont = resolved;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else if (fontRefOrDict instanceof PDFDict) {
|
|
233
|
-
actualFont = fontRefOrDict;
|
|
234
|
-
}
|
|
235
|
-
if (!actualFont)
|
|
236
|
-
continue;
|
|
237
|
-
// Extract font properties
|
|
238
|
-
const subtypeObj = actualFont.lookupMaybe(PDFName.of('Subtype'), PDFName);
|
|
239
|
-
const baseFontObj = actualFont.lookupMaybe(PDFName.of('BaseFont'), PDFName);
|
|
240
|
-
const encodingObj = actualFont.get(PDFName.of('Encoding'));
|
|
241
|
-
const baseFontName = baseFontObj?.decodeText() ?? fontKey;
|
|
242
|
-
const subtype = subtypeObj?.decodeText() ?? 'Unknown';
|
|
243
|
-
const encoding = encodingObj instanceof PDFName ? encodingObj.decodeText() : null;
|
|
244
|
-
// Check if font is embedded (has FontDescriptor with FontFile/FontFile2/FontFile3).
|
|
245
|
-
//
|
|
246
|
-
// For Type 0 (composite) fonts the FontDescriptor is NOT on the font
|
|
247
|
-
// dictionary itself — ISO 32000-2 Table 119 has no such entry. It lives on
|
|
248
|
-
// the CIDFont dictionary in DescendantFonts, where Table 115 marks it
|
|
249
|
-
// "(Required; shall be an indirect reference)". §9.7.6.2 fixes the font
|
|
250
|
-
// number at 0 ("In PDF, the font number shall be 0"), and Table 119
|
|
251
|
-
// describes DescendantFonts as "a one-element array", so element 0 is the
|
|
252
|
-
// only descendant to inspect.
|
|
253
|
-
const descriptorHost = subtype === 'Type0' ? resolveDescendantFont(doc, actualFont) : actualFont;
|
|
254
|
-
const isEmbedded = descriptorHost ? hasEmbeddedFontFile(doc, descriptorHost) : false;
|
|
255
|
-
// Check if subset (name starts with 6 uppercase + '+')
|
|
256
|
-
const isSubset = /^[A-Z]{6}\+/.test(baseFontName);
|
|
257
|
-
const existing = fontMap.get(baseFontName);
|
|
258
|
-
if (existing) {
|
|
259
|
-
if (!existing.pagesUsed.includes(pageNum)) {
|
|
260
|
-
existing.pagesUsed.push(pageNum);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
fontMap.set(baseFontName, {
|
|
265
|
-
name: baseFontName,
|
|
266
|
-
type: subtype,
|
|
267
|
-
encoding,
|
|
268
|
-
isEmbedded,
|
|
269
|
-
isSubset,
|
|
270
|
-
pagesUsed: [pageNum],
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return { fontMap, pagesScanned: pages.length };
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Analyze digital signature fields.
|
|
279
|
-
*/
|
|
280
|
-
export async function analyzeSignatures(filePath) {
|
|
281
|
-
return withSuppressedPdfLibLogs(() => analyzeSignaturesImpl(filePath));
|
|
282
|
-
}
|
|
283
|
-
async function analyzeSignaturesImpl(filePath) {
|
|
284
|
-
const doc = await loadWithPdfLib(filePath);
|
|
285
|
-
const fields = [];
|
|
286
|
-
try {
|
|
287
|
-
const acroForm = doc.catalog.getAcroForm();
|
|
288
|
-
if (!acroForm) {
|
|
289
|
-
return {
|
|
290
|
-
totalFields: 0,
|
|
291
|
-
signedCount: 0,
|
|
292
|
-
unsignedCount: 0,
|
|
293
|
-
fields: [],
|
|
294
|
-
note: 'No AcroForm found in the document.',
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
const allFields = acroForm.getAllFields();
|
|
298
|
-
for (const [field, _ref] of allFields) {
|
|
299
|
-
// Signature fields only (ISO 32000-2 §12.7.5.5: FT shall be Sig).
|
|
300
|
-
// A field with no FT is inherited or malformed — either way, not ours.
|
|
301
|
-
const ftName = field.dict.lookupMaybe(PDFName.of('FT'), PDFName);
|
|
302
|
-
if (ftName?.decodeText() !== 'Sig')
|
|
303
|
-
continue;
|
|
304
|
-
const fieldName = field.getFullyQualifiedName() ?? field.getPartialName() ?? '(unnamed)';
|
|
305
|
-
const vObj = field.dict.get(PDFName.of('V'));
|
|
306
|
-
let isSigned = false;
|
|
307
|
-
let signerName = null;
|
|
308
|
-
let reason = null;
|
|
309
|
-
let location = null;
|
|
310
|
-
let contactInfo = null;
|
|
311
|
-
let signingTime = null;
|
|
312
|
-
let filter = null;
|
|
313
|
-
let subFilter = null;
|
|
314
|
-
// If V exists, the field has been signed
|
|
315
|
-
if (vObj) {
|
|
316
|
-
isSigned = true;
|
|
317
|
-
let sigDict;
|
|
318
|
-
if (vObj instanceof PDFRef) {
|
|
319
|
-
const resolved = doc.context.lookup(vObj);
|
|
320
|
-
if (resolved instanceof PDFDict)
|
|
321
|
-
sigDict = resolved;
|
|
322
|
-
}
|
|
323
|
-
else if (vObj instanceof PDFDict) {
|
|
324
|
-
sigDict = vObj;
|
|
325
|
-
}
|
|
326
|
-
if (sigDict) {
|
|
327
|
-
signerName = extractStringFromDict(sigDict, 'Name');
|
|
328
|
-
reason = extractStringFromDict(sigDict, 'Reason');
|
|
329
|
-
location = extractStringFromDict(sigDict, 'Location');
|
|
330
|
-
contactInfo = extractStringFromDict(sigDict, 'ContactInfo');
|
|
331
|
-
signingTime = extractStringFromDict(sigDict, 'M');
|
|
332
|
-
const filterObj = sigDict.lookupMaybe(PDFName.of('Filter'), PDFName);
|
|
333
|
-
filter = filterObj?.decodeText() ?? null;
|
|
334
|
-
const subFilterObj = sigDict.lookupMaybe(PDFName.of('SubFilter'), PDFName);
|
|
335
|
-
subFilter = subFilterObj?.decodeText() ?? null;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
fields.push({
|
|
339
|
-
fieldName,
|
|
340
|
-
isSigned,
|
|
341
|
-
signerName,
|
|
342
|
-
reason,
|
|
343
|
-
location,
|
|
344
|
-
contactInfo,
|
|
345
|
-
signingTime,
|
|
346
|
-
filter,
|
|
347
|
-
subFilter,
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
catch {
|
|
352
|
-
// Some PDFs may have malformed AcroForm
|
|
353
|
-
}
|
|
354
|
-
const signedCount = fields.filter((f) => f.isSigned).length;
|
|
355
|
-
return {
|
|
356
|
-
totalFields: fields.length,
|
|
357
|
-
signedCount,
|
|
358
|
-
unsignedCount: fields.length - signedCount,
|
|
359
|
-
fields,
|
|
360
|
-
note: 'Cryptographic signature verification is not performed. Only field structure is inspected.',
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
// ─── Internal helpers ────────────────────────────────────
|
|
364
|
-
/** A PDF version as written in a header or catalog: `major.minor`. */
|
|
365
|
-
const PDF_VERSION_PATTERN = /^(\d+)\.(\d+)$/;
|
|
366
|
-
/**
|
|
367
|
-
* Read the version from the file header (`%PDF-x.y`, ISO 32000-2 §7.5.2).
|
|
368
|
-
*
|
|
369
|
-
* Only the first 20 bytes are read — the header is at the very start, and the
|
|
370
|
-
* file may be large.
|
|
371
|
-
*/
|
|
372
|
-
async function readHeaderVersion(filePath) {
|
|
373
|
-
try {
|
|
374
|
-
const fh = await open(filePath, 'r');
|
|
375
|
-
try {
|
|
376
|
-
const buf = Buffer.alloc(20);
|
|
377
|
-
await fh.read(buf, 0, 20, 0);
|
|
378
|
-
return buf.toString('ascii').match(/%PDF-(\d+\.\d+)/)?.[1] ?? null;
|
|
379
|
-
}
|
|
380
|
-
finally {
|
|
381
|
-
await fh.close();
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
catch {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
/** Compare `major.minor` versions. Returns > 0 if `a` is later than `b`. */
|
|
389
|
-
function compareVersions(a, b) {
|
|
390
|
-
const ma = a.match(PDF_VERSION_PATTERN);
|
|
391
|
-
const mb = b.match(PDF_VERSION_PATTERN);
|
|
392
|
-
if (!ma || !mb)
|
|
393
|
-
return 0;
|
|
394
|
-
return Number(ma[1]) - Number(mb[1]) || Number(ma[2]) - Number(mb[2]);
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Resolve the PDF version the document conforms to.
|
|
398
|
-
*
|
|
399
|
-
* ISO 32000-2 Table 29 (Version) makes the catalog entry conditional, not
|
|
400
|
-
* authoritative: it is the version "to which the document conforms … **if later
|
|
401
|
-
* than the version specified in the file's header**. If the header specifies a
|
|
402
|
-
* later version, or if this entry is absent, the document shall conform to the
|
|
403
|
-
* version specified in the header."
|
|
404
|
-
*
|
|
405
|
-
* So the answer is the later of the two. The previous code returned the catalog
|
|
406
|
-
* entry unconditionally whenever it existed, which reports the wrong version for
|
|
407
|
-
* a file whose header is newer — the exact case Table 29 calls out. (The entry
|
|
408
|
-
* exists so a version can be *raised* by an incremental update; see §7.5.6.)
|
|
409
|
-
*
|
|
410
|
-
* A malformed catalog entry cannot be shown to specify a later version, so the
|
|
411
|
-
* header wins by default.
|
|
412
|
-
*
|
|
413
|
-
* Exported for unit testing — the interesting cases (header newer, versions
|
|
414
|
-
* equal, catalog malformed) would each need a hand-built PDF otherwise.
|
|
415
|
-
*/
|
|
416
|
-
export function resolvePdfVersion(headerVersion, catalogVersion) {
|
|
417
|
-
if (!catalogVersion)
|
|
418
|
-
return headerVersion;
|
|
419
|
-
if (!headerVersion)
|
|
420
|
-
return PDF_VERSION_PATTERN.test(catalogVersion) ? catalogVersion : null;
|
|
421
|
-
return compareVersions(catalogVersion, headerVersion) > 0 ? catalogVersion : headerVersion;
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Resolve a value that may be a direct object or an indirect reference to a PDFDict.
|
|
425
|
-
*/
|
|
426
|
-
function resolveDict(doc, obj) {
|
|
427
|
-
if (obj instanceof PDFDict)
|
|
428
|
-
return obj;
|
|
429
|
-
if (obj instanceof PDFRef) {
|
|
430
|
-
const resolved = trySilently(() => doc.context.lookup(obj));
|
|
431
|
-
if (resolved instanceof PDFDict)
|
|
432
|
-
return resolved;
|
|
433
|
-
}
|
|
434
|
-
return undefined;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Resolve the CIDFont dictionary of a Type 0 (composite) font.
|
|
438
|
-
*
|
|
439
|
-
* ISO 32000-2 Table 119 defines DescendantFonts as "(Required) A one-element
|
|
440
|
-
* array specifying the CIDFont dictionary that is the descendant of this Type 0
|
|
441
|
-
* font", and §9.7.6.2 states "In PDF, the font number shall be 0" — so index 0
|
|
442
|
-
* is the only descendant. The array itself may also be an indirect reference.
|
|
443
|
-
*
|
|
444
|
-
* Returns `undefined` for malformed fonts (missing / empty DescendantFonts),
|
|
445
|
-
* which the caller reports as not embedded — the descriptor is unreachable, so
|
|
446
|
-
* embedding cannot be asserted.
|
|
447
|
-
*/
|
|
448
|
-
function resolveDescendantFont(doc, type0Font) {
|
|
449
|
-
const descendants = trySilently(() => type0Font.lookupMaybe(PDFName.of('DescendantFonts'), PDFArray));
|
|
450
|
-
if (!descendants || descendants.size() === 0)
|
|
451
|
-
return undefined;
|
|
452
|
-
return resolveDict(doc, descendants.get(0));
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Report whether a font dictionary's FontDescriptor carries an embedded font
|
|
456
|
-
* program. ISO 32000-2 §9.8.2 Table 121: FontFile (Type 1), FontFile2
|
|
457
|
-
* (TrueType), FontFile3 (Type 1C / CIDFontType0C / OpenType).
|
|
458
|
-
*/
|
|
459
|
-
function hasEmbeddedFontFile(doc, fontDict) {
|
|
460
|
-
const descriptor = resolveDict(doc, fontDict.get(PDFName.of('FontDescriptor')));
|
|
461
|
-
if (!descriptor)
|
|
462
|
-
return false;
|
|
463
|
-
return (descriptor.has(PDFName.of('FontFile')) ||
|
|
464
|
-
descriptor.has(PDFName.of('FontFile2')) ||
|
|
465
|
-
descriptor.has(PDFName.of('FontFile3')));
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Summarize a PDF object for display (truncated).
|
|
469
|
-
*/
|
|
470
|
-
function summarizeObject(obj) {
|
|
471
|
-
if (obj instanceof PDFRef)
|
|
472
|
-
return `ref(${obj.objectNumber})`;
|
|
473
|
-
if (obj instanceof PDFName)
|
|
474
|
-
return obj.decodeText();
|
|
475
|
-
if (obj instanceof PDFArray)
|
|
476
|
-
return `Array[${obj.size()}]`;
|
|
477
|
-
if (obj instanceof PDFDict)
|
|
478
|
-
return `Dict{${obj.entries().length} entries}`;
|
|
479
|
-
if (obj instanceof PDFStream)
|
|
480
|
-
return `Stream{${obj.getContentsSize()} bytes}`;
|
|
481
|
-
if (obj instanceof PDFNumber)
|
|
482
|
-
return String(obj.asNumber());
|
|
483
|
-
if (obj instanceof PDFString)
|
|
484
|
-
return obj.decodeText();
|
|
485
|
-
if (obj instanceof PDFHexString)
|
|
486
|
-
return obj.decodeText();
|
|
487
|
-
if (obj === undefined || obj === null)
|
|
488
|
-
return 'null';
|
|
489
|
-
return String(obj);
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Extract a string value from a PDFDict by key name.
|
|
493
|
-
*/
|
|
494
|
-
function extractStringFromDict(dict, key) {
|
|
495
|
-
const obj = dict.get(PDFName.of(key));
|
|
496
|
-
if (obj instanceof PDFString)
|
|
497
|
-
return obj.decodeText();
|
|
498
|
-
if (obj instanceof PDFHexString)
|
|
499
|
-
return obj.decodeText();
|
|
500
|
-
if (obj instanceof PDFName)
|
|
501
|
-
return obj.decodeText();
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
//# sourceMappingURL=pdflib-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdflib-service.js","sourceRoot":"","sources":["../../src/services/pdflib-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,M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