pdf-oxide-fips 0.3.47

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.
Files changed (127) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +25 -0
  3. package/README.md +218 -0
  4. package/lib/builders/annotation-builder.d.ts +198 -0
  5. package/lib/builders/annotation-builder.js +317 -0
  6. package/lib/builders/conversion-options-builder.d.ts +106 -0
  7. package/lib/builders/conversion-options-builder.js +214 -0
  8. package/lib/builders/document-builder.d.ts +381 -0
  9. package/lib/builders/document-builder.js +770 -0
  10. package/lib/builders/index.d.ts +13 -0
  11. package/lib/builders/index.js +13 -0
  12. package/lib/builders/metadata-builder.d.ts +201 -0
  13. package/lib/builders/metadata-builder.js +285 -0
  14. package/lib/builders/pdf-builder.d.ts +216 -0
  15. package/lib/builders/pdf-builder.js +350 -0
  16. package/lib/builders/search-options-builder.d.ts +73 -0
  17. package/lib/builders/search-options-builder.js +129 -0
  18. package/lib/builders/streaming-table.d.ts +64 -0
  19. package/lib/builders/streaming-table.js +140 -0
  20. package/lib/document-editor-manager.d.ts +139 -0
  21. package/lib/document-editor-manager.js +256 -0
  22. package/lib/document-editor.d.ts +124 -0
  23. package/lib/document-editor.js +318 -0
  24. package/lib/errors.d.ts +382 -0
  25. package/lib/errors.js +1115 -0
  26. package/lib/form-field-manager.d.ts +299 -0
  27. package/lib/form-field-manager.js +568 -0
  28. package/lib/hybrid-ml-manager.d.ts +142 -0
  29. package/lib/hybrid-ml-manager.js +208 -0
  30. package/lib/index.d.ts +205 -0
  31. package/lib/index.js +693 -0
  32. package/lib/managers/accessibility-manager.d.ts +148 -0
  33. package/lib/managers/accessibility-manager.js +234 -0
  34. package/lib/managers/annotation-manager.d.ts +219 -0
  35. package/lib/managers/annotation-manager.js +359 -0
  36. package/lib/managers/barcode-manager.d.ts +82 -0
  37. package/lib/managers/barcode-manager.js +263 -0
  38. package/lib/managers/batch-manager.d.ts +185 -0
  39. package/lib/managers/batch-manager.js +385 -0
  40. package/lib/managers/cache-manager.d.ts +181 -0
  41. package/lib/managers/cache-manager.js +384 -0
  42. package/lib/managers/compliance-manager.d.ts +103 -0
  43. package/lib/managers/compliance-manager.js +453 -0
  44. package/lib/managers/content-manager.d.ts +120 -0
  45. package/lib/managers/content-manager.js +294 -0
  46. package/lib/managers/document-utility-manager.d.ts +369 -0
  47. package/lib/managers/document-utility-manager.js +730 -0
  48. package/lib/managers/dom-pdf-creator.d.ts +104 -0
  49. package/lib/managers/dom-pdf-creator.js +299 -0
  50. package/lib/managers/editing-manager.d.ts +248 -0
  51. package/lib/managers/editing-manager.js +387 -0
  52. package/lib/managers/enterprise-manager.d.ts +192 -0
  53. package/lib/managers/enterprise-manager.js +307 -0
  54. package/lib/managers/extended-managers.d.ts +122 -0
  55. package/lib/managers/extended-managers.js +664 -0
  56. package/lib/managers/extraction-manager.d.ts +246 -0
  57. package/lib/managers/extraction-manager.js +482 -0
  58. package/lib/managers/final-utilities.d.ts +127 -0
  59. package/lib/managers/final-utilities.js +657 -0
  60. package/lib/managers/hybrid-ml-advanced.d.ts +136 -0
  61. package/lib/managers/hybrid-ml-advanced.js +722 -0
  62. package/lib/managers/index.d.ts +64 -0
  63. package/lib/managers/index.js +69 -0
  64. package/lib/managers/layer-manager.d.ts +203 -0
  65. package/lib/managers/layer-manager.js +401 -0
  66. package/lib/managers/metadata-manager.d.ts +148 -0
  67. package/lib/managers/metadata-manager.js +280 -0
  68. package/lib/managers/ocr-manager.d.ts +194 -0
  69. package/lib/managers/ocr-manager.js +582 -0
  70. package/lib/managers/optimization-manager.d.ts +102 -0
  71. package/lib/managers/optimization-manager.js +213 -0
  72. package/lib/managers/outline-manager.d.ts +101 -0
  73. package/lib/managers/outline-manager.js +169 -0
  74. package/lib/managers/page-manager.d.ts +142 -0
  75. package/lib/managers/page-manager.js +235 -0
  76. package/lib/managers/pattern-detection.d.ts +169 -0
  77. package/lib/managers/pattern-detection.js +322 -0
  78. package/lib/managers/rendering-manager.d.ts +353 -0
  79. package/lib/managers/rendering-manager.js +679 -0
  80. package/lib/managers/search-manager.d.ts +235 -0
  81. package/lib/managers/search-manager.js +329 -0
  82. package/lib/managers/security-manager.d.ts +161 -0
  83. package/lib/managers/security-manager.js +292 -0
  84. package/lib/managers/signature-manager.d.ts +738 -0
  85. package/lib/managers/signature-manager.js +1509 -0
  86. package/lib/managers/streams.d.ts +262 -0
  87. package/lib/managers/streams.js +477 -0
  88. package/lib/managers/xfa-manager.d.ts +227 -0
  89. package/lib/managers/xfa-manager.js +539 -0
  90. package/lib/native-loader.d.ts +7 -0
  91. package/lib/native-loader.js +62 -0
  92. package/lib/native.d.ts +16 -0
  93. package/lib/native.js +69 -0
  94. package/lib/pdf-creator-manager.d.ts +200 -0
  95. package/lib/pdf-creator-manager.js +381 -0
  96. package/lib/properties.d.ts +79 -0
  97. package/lib/properties.js +454 -0
  98. package/lib/result-accessors-manager.d.ts +346 -0
  99. package/lib/result-accessors-manager.js +706 -0
  100. package/lib/thumbnail-manager.d.ts +121 -0
  101. package/lib/thumbnail-manager.js +205 -0
  102. package/lib/timestamp.d.ts +54 -0
  103. package/lib/timestamp.js +115 -0
  104. package/lib/tsa-client.d.ts +44 -0
  105. package/lib/tsa-client.js +67 -0
  106. package/lib/types/common.d.ts +189 -0
  107. package/lib/types/common.js +17 -0
  108. package/lib/types/document-types.d.ts +352 -0
  109. package/lib/types/document-types.js +82 -0
  110. package/lib/types/index.d.ts +5 -0
  111. package/lib/types/index.js +5 -0
  112. package/lib/types/manager-types.d.ts +179 -0
  113. package/lib/types/manager-types.js +100 -0
  114. package/lib/types/native-bindings.d.ts +439 -0
  115. package/lib/types/native-bindings.js +7 -0
  116. package/lib/workers/index.d.ts +6 -0
  117. package/lib/workers/index.js +5 -0
  118. package/lib/workers/pool.d.ts +64 -0
  119. package/lib/workers/pool.js +192 -0
  120. package/lib/workers/worker.d.ts +5 -0
  121. package/lib/workers/worker.js +99 -0
  122. package/package.json +79 -0
  123. package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
  124. package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
  125. package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
  126. package/prebuilds/linux-x64/pdf_oxide.node +0 -0
  127. package/prebuilds/win32-x64/pdf_oxide.node +0 -0
@@ -0,0 +1,453 @@
1
+ /**
2
+ * ComplianceManager - Canonical Compliance Manager (merged from 2 implementations)
3
+ *
4
+ * Consolidates:
5
+ * - src/compliance-manager.ts ComplianceManager (validation + issue analysis + native FFI)
6
+ * - src/managers/ocr-compliance-cache.ts ComplianceManager (validation + conversion + fixing)
7
+ *
8
+ * Provides complete PDF/A, PDF/X, PDF/UA compliance operations.
9
+ */
10
+ import { EventEmitter } from 'events';
11
+ import { promises as fs } from 'fs';
12
+ import { dirname } from 'path';
13
+ // =============================================================================
14
+ // Type Definitions (from root-level compliance-manager.ts)
15
+ // =============================================================================
16
+ export var PdfALevel;
17
+ (function (PdfALevel) {
18
+ PdfALevel["A1a"] = "PDF/A-1a";
19
+ PdfALevel["A1b"] = "PDF/A-1b";
20
+ PdfALevel["A2a"] = "PDF/A-2a";
21
+ PdfALevel["A2b"] = "PDF/A-2b";
22
+ PdfALevel["A3a"] = "PDF/A-3a";
23
+ PdfALevel["A3b"] = "PDF/A-3b";
24
+ })(PdfALevel || (PdfALevel = {}));
25
+ export var PdfXLevel;
26
+ (function (PdfXLevel) {
27
+ PdfXLevel["X1a"] = "PDF/X-1a";
28
+ PdfXLevel["X1a2001"] = "PDF/X-1a:2001";
29
+ PdfXLevel["X1a2003"] = "PDF/X-1a:2003";
30
+ PdfXLevel["X3"] = "PDF/X-3";
31
+ PdfXLevel["X3_2002"] = "PDF/X-3:2002";
32
+ PdfXLevel["X3_2003"] = "PDF/X-3:2003";
33
+ PdfXLevel["X4"] = "PDF/X-4";
34
+ })(PdfXLevel || (PdfXLevel = {}));
35
+ export var PdfUALevel;
36
+ (function (PdfUALevel) {
37
+ PdfUALevel["UA1"] = "PDF/UA-1";
38
+ PdfUALevel["UA2"] = "PDF/UA-2";
39
+ })(PdfUALevel || (PdfUALevel = {}));
40
+ export var ComplianceIssueType;
41
+ (function (ComplianceIssueType) {
42
+ ComplianceIssueType["FontNotEmbedded"] = "font_not_embedded";
43
+ ComplianceIssueType["InvalidColorSpace"] = "invalid_color_space";
44
+ ComplianceIssueType["MissingAltText"] = "missing_alt_text";
45
+ ComplianceIssueType["MissingLanguage"] = "missing_language";
46
+ ComplianceIssueType["MissingTitle"] = "missing_title";
47
+ ComplianceIssueType["InvalidAnnotation"] = "invalid_annotation";
48
+ ComplianceIssueType["MissingStructure"] = "missing_structure";
49
+ ComplianceIssueType["InvalidLink"] = "invalid_link";
50
+ ComplianceIssueType["Other"] = "other";
51
+ })(ComplianceIssueType || (ComplianceIssueType = {}));
52
+ export var IssueSeverity;
53
+ (function (IssueSeverity) {
54
+ IssueSeverity["Error"] = "error";
55
+ IssueSeverity["Warning"] = "warning";
56
+ IssueSeverity["Info"] = "info";
57
+ })(IssueSeverity || (IssueSeverity = {}));
58
+ // =============================================================================
59
+ // Canonical ComplianceManager
60
+ // =============================================================================
61
+ export class ComplianceManager extends EventEmitter {
62
+ constructor(document) {
63
+ super();
64
+ this.resultCache = new Map();
65
+ this.maxCacheSize = 100;
66
+ this.document = document;
67
+ try {
68
+ this.native = require('../../index.node');
69
+ }
70
+ catch {
71
+ this.native = null;
72
+ }
73
+ }
74
+ // ===========================================================================
75
+ // Validation (from root-level with native FFI)
76
+ // ===========================================================================
77
+ async validatePdfA(level = PdfALevel.A1b) {
78
+ const cacheKey = `compliance:pdfa:${level}`;
79
+ if (this.resultCache.has(cacheKey))
80
+ return this.resultCache.get(cacheKey);
81
+ let isCompliant = true;
82
+ let issues = [];
83
+ let validationTime = 0;
84
+ if (this.native?.validate_pdf_a) {
85
+ try {
86
+ const nativeResult = this.native.validate_pdf_a(level);
87
+ isCompliant = nativeResult.is_compliant ?? true;
88
+ validationTime = nativeResult.validation_time ?? 0;
89
+ if (nativeResult.issues_json) {
90
+ try {
91
+ issues = JSON.parse(nativeResult.issues_json);
92
+ }
93
+ catch {
94
+ issues = [];
95
+ }
96
+ }
97
+ }
98
+ catch {
99
+ isCompliant = true;
100
+ issues = [];
101
+ }
102
+ }
103
+ else if (this.document?.validatePdfA) {
104
+ try {
105
+ const valid = await this.document.validatePdfA(typeof level === 'string' ? level : '1b');
106
+ isCompliant = !!valid;
107
+ }
108
+ catch {
109
+ isCompliant = true;
110
+ }
111
+ }
112
+ const result = {
113
+ isCompliant,
114
+ level: typeof level === 'string' ? level : level,
115
+ issues,
116
+ validationTime,
117
+ };
118
+ this.setCached(cacheKey, result);
119
+ this.emit('pdfAValidated', { level, isCompliant, issueCount: issues.length });
120
+ return result;
121
+ }
122
+ async validatePdfX(level = PdfXLevel.X1a) {
123
+ const cacheKey = `compliance:pdfx:${level}`;
124
+ if (this.resultCache.has(cacheKey))
125
+ return this.resultCache.get(cacheKey);
126
+ let isCompliant = true;
127
+ let issues = [];
128
+ let validationTime = 0;
129
+ if (this.native?.validate_pdf_x) {
130
+ try {
131
+ const nativeResult = this.native.validate_pdf_x(level);
132
+ isCompliant = nativeResult.is_compliant ?? true;
133
+ validationTime = nativeResult.validation_time ?? 0;
134
+ if (nativeResult.issues_json) {
135
+ try {
136
+ issues = JSON.parse(nativeResult.issues_json);
137
+ }
138
+ catch {
139
+ issues = [];
140
+ }
141
+ }
142
+ }
143
+ catch {
144
+ isCompliant = true;
145
+ issues = [];
146
+ }
147
+ }
148
+ else if (this.document?.validatePdfX) {
149
+ try {
150
+ const valid = await this.document.validatePdfX(typeof level === 'string' ? level : '1a');
151
+ isCompliant = !!valid;
152
+ }
153
+ catch {
154
+ isCompliant = true;
155
+ }
156
+ }
157
+ const result = {
158
+ isCompliant,
159
+ level: typeof level === 'string' ? level : level,
160
+ issues,
161
+ validationTime,
162
+ };
163
+ this.setCached(cacheKey, result);
164
+ this.emit('pdfXValidated', { level, isCompliant, issueCount: issues.length });
165
+ return result;
166
+ }
167
+ async validatePdfUA(level = PdfUALevel.UA1) {
168
+ const cacheKey = `compliance:pdfua:${level}`;
169
+ if (this.resultCache.has(cacheKey))
170
+ return this.resultCache.get(cacheKey);
171
+ let isCompliant = true;
172
+ let issues = [];
173
+ let validationTime = 0;
174
+ if (this.native?.validate_pdf_ua) {
175
+ try {
176
+ const nativeResult = this.native.validate_pdf_ua(level);
177
+ isCompliant = nativeResult.is_compliant ?? true;
178
+ validationTime = nativeResult.validation_time ?? 0;
179
+ if (nativeResult.issues_json) {
180
+ try {
181
+ issues = JSON.parse(nativeResult.issues_json);
182
+ }
183
+ catch {
184
+ issues = [];
185
+ }
186
+ }
187
+ }
188
+ catch {
189
+ isCompliant = true;
190
+ issues = [];
191
+ }
192
+ }
193
+ else if (this.document?.validatePdfUA) {
194
+ try {
195
+ isCompliant = !!(await this.document.validatePdfUA());
196
+ }
197
+ catch {
198
+ isCompliant = true;
199
+ }
200
+ }
201
+ const result = {
202
+ isCompliant,
203
+ level: typeof level === 'string' ? level : level,
204
+ issues,
205
+ validationTime,
206
+ };
207
+ this.setCached(cacheKey, result);
208
+ this.emit('pdfUAValidated', { level, isCompliant, issueCount: issues.length });
209
+ return result;
210
+ }
211
+ // ===========================================================================
212
+ // Issue Analysis (from root-level)
213
+ // ===========================================================================
214
+ async getAllIssues() {
215
+ const cacheKey = 'compliance:all_issues';
216
+ if (this.resultCache.has(cacheKey))
217
+ return this.resultCache.get(cacheKey);
218
+ let issues = [];
219
+ if (this.native?.compliance_get_all_issues) {
220
+ try {
221
+ issues = JSON.parse(this.native.compliance_get_all_issues()) || [];
222
+ }
223
+ catch {
224
+ issues = [];
225
+ }
226
+ }
227
+ this.setCached(cacheKey, issues);
228
+ this.emit('issuesRetrieved', { count: issues.length });
229
+ return issues;
230
+ }
231
+ async getIssuesOfType(type) {
232
+ const allIssues = await this.getAllIssues();
233
+ return allIssues.filter((issue) => issue.type === type);
234
+ }
235
+ async getIssueCount() {
236
+ return (await this.getAllIssues()).length;
237
+ }
238
+ async getErrorCount() {
239
+ return (await this.getAllIssues()).filter((i) => i.severity === IssueSeverity.Error).length;
240
+ }
241
+ async getWarningCount() {
242
+ return (await this.getAllIssues()).filter((i) => i.severity === IssueSeverity.Warning).length;
243
+ }
244
+ // ===========================================================================
245
+ // Conversion & Fixing (from managers version)
246
+ // ===========================================================================
247
+ async convertToPdfA(level = '1b') {
248
+ try {
249
+ const result = await this.document?.convertToPdfA?.(level);
250
+ this.resultCache.delete(`compliance:pdfa:${level}`);
251
+ this.emit('conversion-complete', { type: 'PDF/A', level, success: result });
252
+ return !!result;
253
+ }
254
+ catch (error) {
255
+ this.emit('error', error);
256
+ return false;
257
+ }
258
+ }
259
+ async convertToPdfUA() {
260
+ try {
261
+ const result = await this.document?.convertToPdfUA?.();
262
+ this.resultCache.delete('compliance:pdfua:');
263
+ this.emit('conversion-complete', { type: 'PDF/UA', success: result });
264
+ return !!result;
265
+ }
266
+ catch (error) {
267
+ this.emit('error', error);
268
+ return false;
269
+ }
270
+ }
271
+ async getComplianceReport(complianceType = 'all') {
272
+ try {
273
+ return (await this.document?.getComplianceReport?.(complianceType)) ?? '';
274
+ }
275
+ catch (error) {
276
+ this.emit('error', error);
277
+ return '';
278
+ }
279
+ }
280
+ async checkFontEmbedding() {
281
+ const cacheKey = 'compliance:fonts_embedded';
282
+ if (this.resultCache.has(cacheKey))
283
+ return this.resultCache.get(cacheKey);
284
+ const result = this.document?.checkFontEmbedding?.() ??
285
+ this.native?.compliance_has_embedded_fonts?.() ??
286
+ true;
287
+ this.setCached(cacheKey, result);
288
+ return result;
289
+ }
290
+ /** @deprecated Use checkFontEmbedding() instead */
291
+ async hasFontsEmbedded() {
292
+ return this.checkFontEmbedding();
293
+ }
294
+ async checkColorSpace() {
295
+ const cacheKey = 'compliance:valid_color_space';
296
+ if (this.resultCache.has(cacheKey))
297
+ return this.resultCache.get(cacheKey);
298
+ const result = this.document?.checkColorSpace?.() ??
299
+ this.native?.compliance_has_valid_color_space?.() ??
300
+ true;
301
+ this.setCached(cacheKey, result);
302
+ return result;
303
+ }
304
+ /** @deprecated Use checkColorSpace() instead */
305
+ async hasValidColorSpace() {
306
+ return this.checkColorSpace();
307
+ }
308
+ async checkTaggedContent() {
309
+ try {
310
+ return (await this.document?.checkTaggedContent?.()) ?? false;
311
+ }
312
+ catch (error) {
313
+ this.emit('error', error);
314
+ return false;
315
+ }
316
+ }
317
+ async addMissingTags() {
318
+ try {
319
+ const result = await this.document?.addMissingTags?.();
320
+ this.emit('tags-added');
321
+ return !!result;
322
+ }
323
+ catch (error) {
324
+ this.emit('error', error);
325
+ return false;
326
+ }
327
+ }
328
+ async fixFontIssues() {
329
+ try {
330
+ const count = (await this.document?.fixFontIssues?.()) ?? 0;
331
+ this.emit('fonts-fixed', { count });
332
+ return count;
333
+ }
334
+ catch (error) {
335
+ this.emit('error', error);
336
+ return 0;
337
+ }
338
+ }
339
+ async fixColorIssues() {
340
+ try {
341
+ const count = (await this.document?.fixColorIssues?.()) ?? 0;
342
+ this.emit('colors-fixed', { count });
343
+ return count;
344
+ }
345
+ catch (error) {
346
+ this.emit('error', error);
347
+ return 0;
348
+ }
349
+ }
350
+ async removeUnsupportedFeatures() {
351
+ try {
352
+ const count = (await this.document?.removeUnsupportedFeatures?.()) ?? 0;
353
+ this.emit('features-removed', { count });
354
+ return count;
355
+ }
356
+ catch (error) {
357
+ this.emit('error', error);
358
+ return 0;
359
+ }
360
+ }
361
+ async getComplianceIssues() {
362
+ try {
363
+ const issues = [];
364
+ const pdfA = await this.validatePdfA(PdfALevel.A1b);
365
+ if (!pdfA.isCompliant)
366
+ issues.push('PDF/A non-compliant');
367
+ const pdfX = await this.validatePdfX(PdfXLevel.X1a);
368
+ if (!pdfX.isCompliant)
369
+ issues.push('PDF/X non-compliant');
370
+ const pdfUA = await this.validatePdfUA(PdfUALevel.UA1);
371
+ if (!pdfUA.isCompliant)
372
+ issues.push('PDF/UA non-accessible');
373
+ const fontEmbedded = await this.checkFontEmbedding();
374
+ if (!fontEmbedded)
375
+ issues.push('Fonts not properly embedded');
376
+ const taggedContent = await this.checkTaggedContent();
377
+ if (!taggedContent)
378
+ issues.push('Missing proper tagging');
379
+ this.emit('issues-analyzed', { count: issues.length });
380
+ return issues;
381
+ }
382
+ catch (error) {
383
+ this.emit('error', error);
384
+ return [];
385
+ }
386
+ }
387
+ getIssueSeverity(issue) {
388
+ if (issue.includes('Font') || issue.includes('PDF/UA'))
389
+ return 'critical';
390
+ if (issue.includes('PDF/A') || issue.includes('PDF/X'))
391
+ return 'high';
392
+ if (issue.includes('tagging'))
393
+ return 'medium';
394
+ return 'low';
395
+ }
396
+ async createComplianceReportFile(filePath) {
397
+ try {
398
+ const report = await this.getComplianceReport('all');
399
+ await fs.mkdir(dirname(filePath), { recursive: true });
400
+ await fs.writeFile(filePath, report, 'utf8');
401
+ this.emit('report-created', { filePath });
402
+ return true;
403
+ }
404
+ catch (error) {
405
+ this.emit('error', error);
406
+ return false;
407
+ }
408
+ }
409
+ async getComplianceSummary() {
410
+ try {
411
+ return {
412
+ pdfA: await this.validatePdfA(PdfALevel.A1b),
413
+ pdfX: await this.validatePdfX(PdfXLevel.X1a),
414
+ pdfUA: await this.validatePdfUA(PdfUALevel.UA1),
415
+ fontEmbedded: await this.checkFontEmbedding(),
416
+ colorSpace: await this.checkColorSpace(),
417
+ taggedContent: await this.checkTaggedContent(),
418
+ issues: await this.getComplianceIssues(),
419
+ };
420
+ }
421
+ catch (error) {
422
+ this.emit('error', error);
423
+ return {};
424
+ }
425
+ }
426
+ // ===========================================================================
427
+ // Cache
428
+ // ===========================================================================
429
+ clearCache() {
430
+ this.resultCache.clear();
431
+ this.emit('cacheCleared');
432
+ }
433
+ getCacheStats() {
434
+ return {
435
+ cacheSize: this.resultCache.size,
436
+ maxCacheSize: this.maxCacheSize,
437
+ entries: Array.from(this.resultCache.keys()),
438
+ };
439
+ }
440
+ destroy() {
441
+ this.resultCache.clear();
442
+ this.removeAllListeners();
443
+ }
444
+ setCached(key, value) {
445
+ this.resultCache.set(key, value);
446
+ if (this.resultCache.size > this.maxCacheSize) {
447
+ const firstKey = this.resultCache.keys().next().value;
448
+ if (firstKey !== undefined)
449
+ this.resultCache.delete(firstKey);
450
+ }
451
+ }
452
+ }
453
+ export default ComplianceManager;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Manager for page-level content analysis
3
+ *
4
+ * Provides methods to analyze content type, complexity, and characteristics of PDF pages.
5
+ * This manager operates on a specific page, unlike document-level managers.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { ContentManager } from 'pdf_oxide';
10
+ *
11
+ * const doc = PdfDocument.open('document.pdf');
12
+ * const contentManager = new ContentManager(doc, 0);
13
+ *
14
+ * if (!contentManager.isBlank()) {
15
+ * console.log(contentManager.getContentSummary());
16
+ * }
17
+ * ```
18
+ */
19
+ export interface ContentAnalysis {
20
+ pageIndex: number;
21
+ hasContent: boolean;
22
+ isBlank: boolean;
23
+ contentSize: number;
24
+ complexityScore: number;
25
+ dimensions: string;
26
+ contentTypes: string[];
27
+ likelyHasForms: boolean;
28
+ likelyHasTables: boolean;
29
+ likelyHasImages: boolean;
30
+ }
31
+ export declare class ContentManager {
32
+ private _document;
33
+ private _pageIndex;
34
+ private _cache;
35
+ /**
36
+ * Creates a new ContentManager for a specific page
37
+ * @param document - The PDF document
38
+ * @param pageIndex - Page index to analyze (0-based)
39
+ * @throws Error if document is null or undefined
40
+ */
41
+ constructor(document: any, pageIndex: number);
42
+ /**
43
+ * Gets the page index this manager operates on
44
+ * @returns Page index
45
+ */
46
+ get pageIndex(): number;
47
+ /**
48
+ * Clears the content cache
49
+ */
50
+ clearCache(): void;
51
+ /**
52
+ * Checks if the page has any content
53
+ * @returns True if the page has content
54
+ */
55
+ hasContent(): boolean;
56
+ /**
57
+ * Gets the approximate size of the content stream in bytes
58
+ * @returns Content size in bytes
59
+ */
60
+ getContentSize(): number;
61
+ /**
62
+ * Checks if the page appears to be blank (no visible content)
63
+ * @returns True if the page is blank
64
+ */
65
+ isBlank(): boolean;
66
+ /**
67
+ * Gets a complexity score for the page (0-100)
68
+ * Higher scores indicate more complex content.
69
+ * @returns Complexity score from 0 to 100
70
+ */
71
+ getComplexityScore(): number;
72
+ /**
73
+ * Gets a human-readable summary of page dimensions
74
+ * @returns Formatted dimensions string
75
+ */
76
+ getDimensionsSummary(): string;
77
+ /**
78
+ * Checks if the page likely contains form fields
79
+ * @returns True if the page likely has forms
80
+ */
81
+ likelyHasForms(): boolean;
82
+ /**
83
+ * Checks if the page likely contains tables
84
+ * @returns True if the page likely has tables
85
+ */
86
+ likelyHasTables(): boolean;
87
+ /**
88
+ * Checks if the page likely contains images
89
+ * @returns True if the page likely has images
90
+ */
91
+ likelyHasImages(): boolean;
92
+ /**
93
+ * Gets a list of content types detected on the page
94
+ * @returns Array of content type strings
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const types = manager.getContentTypes();
99
+ * console.log(`Content types: ${types.join(', ')}`);
100
+ * ```
101
+ */
102
+ getContentTypes(): string[];
103
+ /**
104
+ * Gets a human-readable summary of the page content
105
+ * @returns Formatted content summary string
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const summary = manager.getContentSummary();
110
+ * console.log(summary);
111
+ * // Output: "Dimensions: 612 x 792 pt; Content: text, images; Complexity: 45/100"
112
+ * ```
113
+ */
114
+ getContentSummary(): string;
115
+ /**
116
+ * Analyzes page content thoroughly
117
+ * @returns Detailed content analysis
118
+ */
119
+ analyze(): ContentAnalysis;
120
+ }