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.
- package/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +25 -0
- package/README.md +218 -0
- package/lib/builders/annotation-builder.d.ts +198 -0
- package/lib/builders/annotation-builder.js +317 -0
- package/lib/builders/conversion-options-builder.d.ts +106 -0
- package/lib/builders/conversion-options-builder.js +214 -0
- package/lib/builders/document-builder.d.ts +381 -0
- package/lib/builders/document-builder.js +770 -0
- package/lib/builders/index.d.ts +13 -0
- package/lib/builders/index.js +13 -0
- package/lib/builders/metadata-builder.d.ts +201 -0
- package/lib/builders/metadata-builder.js +285 -0
- package/lib/builders/pdf-builder.d.ts +216 -0
- package/lib/builders/pdf-builder.js +350 -0
- package/lib/builders/search-options-builder.d.ts +73 -0
- package/lib/builders/search-options-builder.js +129 -0
- package/lib/builders/streaming-table.d.ts +64 -0
- package/lib/builders/streaming-table.js +140 -0
- package/lib/document-editor-manager.d.ts +139 -0
- package/lib/document-editor-manager.js +256 -0
- package/lib/document-editor.d.ts +124 -0
- package/lib/document-editor.js +318 -0
- package/lib/errors.d.ts +382 -0
- package/lib/errors.js +1115 -0
- package/lib/form-field-manager.d.ts +299 -0
- package/lib/form-field-manager.js +568 -0
- package/lib/hybrid-ml-manager.d.ts +142 -0
- package/lib/hybrid-ml-manager.js +208 -0
- package/lib/index.d.ts +205 -0
- package/lib/index.js +693 -0
- package/lib/managers/accessibility-manager.d.ts +148 -0
- package/lib/managers/accessibility-manager.js +234 -0
- package/lib/managers/annotation-manager.d.ts +219 -0
- package/lib/managers/annotation-manager.js +359 -0
- package/lib/managers/barcode-manager.d.ts +82 -0
- package/lib/managers/barcode-manager.js +263 -0
- package/lib/managers/batch-manager.d.ts +185 -0
- package/lib/managers/batch-manager.js +385 -0
- package/lib/managers/cache-manager.d.ts +181 -0
- package/lib/managers/cache-manager.js +384 -0
- package/lib/managers/compliance-manager.d.ts +103 -0
- package/lib/managers/compliance-manager.js +453 -0
- package/lib/managers/content-manager.d.ts +120 -0
- package/lib/managers/content-manager.js +294 -0
- package/lib/managers/document-utility-manager.d.ts +369 -0
- package/lib/managers/document-utility-manager.js +730 -0
- package/lib/managers/dom-pdf-creator.d.ts +104 -0
- package/lib/managers/dom-pdf-creator.js +299 -0
- package/lib/managers/editing-manager.d.ts +248 -0
- package/lib/managers/editing-manager.js +387 -0
- package/lib/managers/enterprise-manager.d.ts +192 -0
- package/lib/managers/enterprise-manager.js +307 -0
- package/lib/managers/extended-managers.d.ts +122 -0
- package/lib/managers/extended-managers.js +664 -0
- package/lib/managers/extraction-manager.d.ts +246 -0
- package/lib/managers/extraction-manager.js +482 -0
- package/lib/managers/final-utilities.d.ts +127 -0
- package/lib/managers/final-utilities.js +657 -0
- package/lib/managers/hybrid-ml-advanced.d.ts +136 -0
- package/lib/managers/hybrid-ml-advanced.js +722 -0
- package/lib/managers/index.d.ts +64 -0
- package/lib/managers/index.js +69 -0
- package/lib/managers/layer-manager.d.ts +203 -0
- package/lib/managers/layer-manager.js +401 -0
- package/lib/managers/metadata-manager.d.ts +148 -0
- package/lib/managers/metadata-manager.js +280 -0
- package/lib/managers/ocr-manager.d.ts +194 -0
- package/lib/managers/ocr-manager.js +582 -0
- package/lib/managers/optimization-manager.d.ts +102 -0
- package/lib/managers/optimization-manager.js +213 -0
- package/lib/managers/outline-manager.d.ts +101 -0
- package/lib/managers/outline-manager.js +169 -0
- package/lib/managers/page-manager.d.ts +142 -0
- package/lib/managers/page-manager.js +235 -0
- package/lib/managers/pattern-detection.d.ts +169 -0
- package/lib/managers/pattern-detection.js +322 -0
- package/lib/managers/rendering-manager.d.ts +353 -0
- package/lib/managers/rendering-manager.js +679 -0
- package/lib/managers/search-manager.d.ts +235 -0
- package/lib/managers/search-manager.js +329 -0
- package/lib/managers/security-manager.d.ts +161 -0
- package/lib/managers/security-manager.js +292 -0
- package/lib/managers/signature-manager.d.ts +738 -0
- package/lib/managers/signature-manager.js +1509 -0
- package/lib/managers/streams.d.ts +262 -0
- package/lib/managers/streams.js +477 -0
- package/lib/managers/xfa-manager.d.ts +227 -0
- package/lib/managers/xfa-manager.js +539 -0
- package/lib/native-loader.d.ts +7 -0
- package/lib/native-loader.js +62 -0
- package/lib/native.d.ts +16 -0
- package/lib/native.js +69 -0
- package/lib/pdf-creator-manager.d.ts +200 -0
- package/lib/pdf-creator-manager.js +381 -0
- package/lib/properties.d.ts +79 -0
- package/lib/properties.js +454 -0
- package/lib/result-accessors-manager.d.ts +346 -0
- package/lib/result-accessors-manager.js +706 -0
- package/lib/thumbnail-manager.d.ts +121 -0
- package/lib/thumbnail-manager.js +205 -0
- package/lib/timestamp.d.ts +54 -0
- package/lib/timestamp.js +115 -0
- package/lib/tsa-client.d.ts +44 -0
- package/lib/tsa-client.js +67 -0
- package/lib/types/common.d.ts +189 -0
- package/lib/types/common.js +17 -0
- package/lib/types/document-types.d.ts +352 -0
- package/lib/types/document-types.js +82 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.js +5 -0
- package/lib/types/manager-types.d.ts +179 -0
- package/lib/types/manager-types.js +100 -0
- package/lib/types/native-bindings.d.ts +439 -0
- package/lib/types/native-bindings.js +7 -0
- package/lib/workers/index.d.ts +6 -0
- package/lib/workers/index.js +5 -0
- package/lib/workers/pool.d.ts +64 -0
- package/lib/workers/pool.js +192 -0
- package/lib/workers/worker.d.ts +5 -0
- package/lib/workers/worker.js +99 -0
- package/package.json +79 -0
- package/prebuilds/darwin-arm64/pdf_oxide.node +0 -0
- package/prebuilds/darwin-x64/pdf_oxide.node +0 -0
- package/prebuilds/linux-arm64/pdf_oxide.node +0 -0
- package/prebuilds/linux-x64/pdf_oxide.node +0 -0
- package/prebuilds/win32-x64/pdf_oxide.node +0 -0
|
@@ -0,0 +1,294 @@
|
|
|
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 class ContentManager {
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new ContentManager for a specific page
|
|
22
|
+
* @param document - The PDF document
|
|
23
|
+
* @param pageIndex - Page index to analyze (0-based)
|
|
24
|
+
* @throws Error if document is null or undefined
|
|
25
|
+
*/
|
|
26
|
+
constructor(document, pageIndex) {
|
|
27
|
+
if (!document) {
|
|
28
|
+
throw new Error('Document is required');
|
|
29
|
+
}
|
|
30
|
+
if (typeof pageIndex !== 'number' || pageIndex < 0) {
|
|
31
|
+
throw new Error('Page index must be a non-negative number');
|
|
32
|
+
}
|
|
33
|
+
this._document = document;
|
|
34
|
+
this._pageIndex = pageIndex;
|
|
35
|
+
this._cache = new Map();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets the page index this manager operates on
|
|
39
|
+
* @returns Page index
|
|
40
|
+
*/
|
|
41
|
+
get pageIndex() {
|
|
42
|
+
return this._pageIndex;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Clears the content cache
|
|
46
|
+
*/
|
|
47
|
+
clearCache() {
|
|
48
|
+
this._cache.clear();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the page has any content
|
|
52
|
+
* @returns True if the page has content
|
|
53
|
+
*/
|
|
54
|
+
hasContent() {
|
|
55
|
+
const cacheKey = `content:has:${this._pageIndex}`;
|
|
56
|
+
if (this._cache.has(cacheKey)) {
|
|
57
|
+
return this._cache.get(cacheKey);
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
// Placeholder - would check via FFI
|
|
61
|
+
const has = true;
|
|
62
|
+
this._cache.set(cacheKey, has);
|
|
63
|
+
return has;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the approximate size of the content stream in bytes
|
|
71
|
+
* @returns Content size in bytes
|
|
72
|
+
*/
|
|
73
|
+
getContentSize() {
|
|
74
|
+
const cacheKey = `content:size:${this._pageIndex}`;
|
|
75
|
+
if (this._cache.has(cacheKey)) {
|
|
76
|
+
return this._cache.get(cacheKey);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
// Placeholder - would call FFI
|
|
80
|
+
const size = 0;
|
|
81
|
+
this._cache.set(cacheKey, size);
|
|
82
|
+
return size;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the page appears to be blank (no visible content)
|
|
90
|
+
* @returns True if the page is blank
|
|
91
|
+
*/
|
|
92
|
+
isBlank() {
|
|
93
|
+
const cacheKey = `content:blank:${this._pageIndex}`;
|
|
94
|
+
if (this._cache.has(cacheKey)) {
|
|
95
|
+
return this._cache.get(cacheKey);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
// Placeholder - would call FFI
|
|
99
|
+
const blank = false;
|
|
100
|
+
this._cache.set(cacheKey, blank);
|
|
101
|
+
return blank;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Gets a complexity score for the page (0-100)
|
|
109
|
+
* Higher scores indicate more complex content.
|
|
110
|
+
* @returns Complexity score from 0 to 100
|
|
111
|
+
*/
|
|
112
|
+
getComplexityScore() {
|
|
113
|
+
const cacheKey = `content:complexity:${this._pageIndex}`;
|
|
114
|
+
if (this._cache.has(cacheKey)) {
|
|
115
|
+
return this._cache.get(cacheKey);
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
// Placeholder - would call FFI
|
|
119
|
+
const score = 0;
|
|
120
|
+
this._cache.set(cacheKey, score);
|
|
121
|
+
return score;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Gets a human-readable summary of page dimensions
|
|
129
|
+
* @returns Formatted dimensions string
|
|
130
|
+
*/
|
|
131
|
+
getDimensionsSummary() {
|
|
132
|
+
const cacheKey = `content:dimensions:${this._pageIndex}`;
|
|
133
|
+
if (this._cache.has(cacheKey)) {
|
|
134
|
+
return this._cache.get(cacheKey);
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const page = this._document.getPage(this._pageIndex);
|
|
138
|
+
const width = page?.width || 612;
|
|
139
|
+
const height = page?.height || 792;
|
|
140
|
+
// Convert points to inches and mm
|
|
141
|
+
const widthInches = width / 72;
|
|
142
|
+
const heightInches = height / 72;
|
|
143
|
+
const widthMm = width * 0.352778;
|
|
144
|
+
const heightMm = height * 0.352778;
|
|
145
|
+
const summary = `${width.toFixed(0)} x ${height.toFixed(0)} pt ` +
|
|
146
|
+
`(${widthInches.toFixed(2)} x ${heightInches.toFixed(2)} in, ` +
|
|
147
|
+
`${widthMm.toFixed(0)} x ${heightMm.toFixed(0)} mm)`;
|
|
148
|
+
this._cache.set(cacheKey, summary);
|
|
149
|
+
return summary;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return '0 x 0 pt';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Checks if the page likely contains form fields
|
|
157
|
+
* @returns True if the page likely has forms
|
|
158
|
+
*/
|
|
159
|
+
likelyHasForms() {
|
|
160
|
+
const cacheKey = `content:likely_forms:${this._pageIndex}`;
|
|
161
|
+
if (this._cache.has(cacheKey)) {
|
|
162
|
+
return this._cache.get(cacheKey);
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
// Placeholder - would call FFI
|
|
166
|
+
const has = false;
|
|
167
|
+
this._cache.set(cacheKey, has);
|
|
168
|
+
return has;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Checks if the page likely contains tables
|
|
176
|
+
* @returns True if the page likely has tables
|
|
177
|
+
*/
|
|
178
|
+
likelyHasTables() {
|
|
179
|
+
const cacheKey = `content:likely_tables:${this._pageIndex}`;
|
|
180
|
+
if (this._cache.has(cacheKey)) {
|
|
181
|
+
return this._cache.get(cacheKey);
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
// Placeholder - would call FFI
|
|
185
|
+
const has = false;
|
|
186
|
+
this._cache.set(cacheKey, has);
|
|
187
|
+
return has;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Checks if the page likely contains images
|
|
195
|
+
* @returns True if the page likely has images
|
|
196
|
+
*/
|
|
197
|
+
likelyHasImages() {
|
|
198
|
+
const cacheKey = `content:likely_images:${this._pageIndex}`;
|
|
199
|
+
if (this._cache.has(cacheKey)) {
|
|
200
|
+
return this._cache.get(cacheKey);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
// Placeholder - would call FFI
|
|
204
|
+
const has = false;
|
|
205
|
+
this._cache.set(cacheKey, has);
|
|
206
|
+
return has;
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Gets a list of content types detected on the page
|
|
214
|
+
* @returns Array of content type strings
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const types = manager.getContentTypes();
|
|
219
|
+
* console.log(`Content types: ${types.join(', ')}`);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
getContentTypes() {
|
|
223
|
+
const cacheKey = `content:types:${this._pageIndex}`;
|
|
224
|
+
if (this._cache.has(cacheKey)) {
|
|
225
|
+
return this._cache.get(cacheKey);
|
|
226
|
+
}
|
|
227
|
+
const types = [];
|
|
228
|
+
if (!this.hasContent()) {
|
|
229
|
+
types.push('empty');
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
types.push('text'); // Most pages have text
|
|
233
|
+
if (this.likelyHasImages()) {
|
|
234
|
+
types.push('images');
|
|
235
|
+
}
|
|
236
|
+
if (this.likelyHasTables()) {
|
|
237
|
+
types.push('tables');
|
|
238
|
+
}
|
|
239
|
+
if (this.likelyHasForms()) {
|
|
240
|
+
types.push('forms');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
this._cache.set(cacheKey, types);
|
|
244
|
+
return types;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Gets a human-readable summary of the page content
|
|
248
|
+
* @returns Formatted content summary string
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* const summary = manager.getContentSummary();
|
|
253
|
+
* console.log(summary);
|
|
254
|
+
* // Output: "Dimensions: 612 x 792 pt; Content: text, images; Complexity: 45/100"
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
getContentSummary() {
|
|
258
|
+
const cacheKey = `content:summary:${this._pageIndex}`;
|
|
259
|
+
if (this._cache.has(cacheKey)) {
|
|
260
|
+
return this._cache.get(cacheKey);
|
|
261
|
+
}
|
|
262
|
+
if (this.isBlank()) {
|
|
263
|
+
return 'Blank page';
|
|
264
|
+
}
|
|
265
|
+
const parts = [];
|
|
266
|
+
const dimensions = this.getDimensionsSummary();
|
|
267
|
+
parts.push(`Dimensions: ${dimensions}`);
|
|
268
|
+
const contentTypes = this.getContentTypes();
|
|
269
|
+
parts.push(`Content: ${contentTypes.join(', ')}`);
|
|
270
|
+
const complexity = this.getComplexityScore();
|
|
271
|
+
parts.push(`Complexity: ${complexity}/100`);
|
|
272
|
+
const summary = parts.join('; ');
|
|
273
|
+
this._cache.set(cacheKey, summary);
|
|
274
|
+
return summary;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Analyzes page content thoroughly
|
|
278
|
+
* @returns Detailed content analysis
|
|
279
|
+
*/
|
|
280
|
+
analyze() {
|
|
281
|
+
return {
|
|
282
|
+
pageIndex: this._pageIndex,
|
|
283
|
+
hasContent: this.hasContent(),
|
|
284
|
+
isBlank: this.isBlank(),
|
|
285
|
+
contentSize: this.getContentSize(),
|
|
286
|
+
complexityScore: this.getComplexityScore(),
|
|
287
|
+
dimensions: this.getDimensionsSummary(),
|
|
288
|
+
contentTypes: this.getContentTypes(),
|
|
289
|
+
likelyHasForms: this.likelyHasForms(),
|
|
290
|
+
likelyHasTables: this.likelyHasTables(),
|
|
291
|
+
likelyHasImages: this.likelyHasImages(),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document Utility Manager - Document optimization and manipulation utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides comprehensive document utilities:
|
|
5
|
+
* - Document optimization and compression
|
|
6
|
+
* - PDF linearization (fast web view)
|
|
7
|
+
* - Font optimization and subsetting
|
|
8
|
+
* - Image optimization and recompression
|
|
9
|
+
* - Page manipulation utilities
|
|
10
|
+
* - Document repair
|
|
11
|
+
* - Resource cleanup
|
|
12
|
+
*
|
|
13
|
+
* This completes the document utility coverage for 100% FFI parity.
|
|
14
|
+
*/
|
|
15
|
+
import { EventEmitter } from 'events';
|
|
16
|
+
/**
|
|
17
|
+
* Optimization level enumeration
|
|
18
|
+
*/
|
|
19
|
+
export declare enum OptimizationLevel {
|
|
20
|
+
/** No optimization */
|
|
21
|
+
NONE = "none",
|
|
22
|
+
/** Light optimization - fast, minimal size reduction */
|
|
23
|
+
LIGHT = "light",
|
|
24
|
+
/** Balanced optimization - good balance of speed and size */
|
|
25
|
+
BALANCED = "balanced",
|
|
26
|
+
/** Aggressive optimization - maximum size reduction, slower */
|
|
27
|
+
AGGRESSIVE = "aggressive",
|
|
28
|
+
/** Maximum optimization - smallest possible size */
|
|
29
|
+
MAXIMUM = "maximum"
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Image compression type
|
|
33
|
+
*/
|
|
34
|
+
export declare enum ImageCompressionType {
|
|
35
|
+
NONE = "none",
|
|
36
|
+
JPEG = "jpeg",
|
|
37
|
+
JPEG2000 = "jpeg2000",
|
|
38
|
+
JBIG2 = "jbig2",
|
|
39
|
+
FLATE = "flate",
|
|
40
|
+
LZW = "lzw",
|
|
41
|
+
RUN_LENGTH = "run_length",
|
|
42
|
+
CCITT_FAX = "ccitt_fax"
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Color space type
|
|
46
|
+
*/
|
|
47
|
+
export declare enum ColorSpaceType {
|
|
48
|
+
RGB = "rgb",
|
|
49
|
+
CMYK = "cmyk",
|
|
50
|
+
GRAYSCALE = "grayscale",
|
|
51
|
+
INDEXED = "indexed"
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Font embedding mode
|
|
55
|
+
*/
|
|
56
|
+
export declare enum FontEmbeddingMode {
|
|
57
|
+
/** Embed full fonts */
|
|
58
|
+
FULL = "full",
|
|
59
|
+
/** Embed subset of used glyphs only */
|
|
60
|
+
SUBSET = "subset",
|
|
61
|
+
/** Remove all font embedding */
|
|
62
|
+
REMOVE = "remove"
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Page range specification
|
|
66
|
+
*/
|
|
67
|
+
export interface PageRange {
|
|
68
|
+
readonly start: number;
|
|
69
|
+
readonly end: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Optimization options
|
|
73
|
+
*/
|
|
74
|
+
export interface OptimizationOptions {
|
|
75
|
+
readonly level?: OptimizationLevel;
|
|
76
|
+
readonly compressImages?: boolean;
|
|
77
|
+
readonly imageQuality?: number;
|
|
78
|
+
readonly imageCompression?: ImageCompressionType;
|
|
79
|
+
readonly downsampleImages?: boolean;
|
|
80
|
+
readonly maxImageDpi?: number;
|
|
81
|
+
readonly removeUnusedObjects?: boolean;
|
|
82
|
+
readonly removeMetadata?: boolean;
|
|
83
|
+
readonly removeThumbnails?: boolean;
|
|
84
|
+
readonly removeBookmarks?: boolean;
|
|
85
|
+
readonly removeAnnotations?: boolean;
|
|
86
|
+
readonly removeJavaScript?: boolean;
|
|
87
|
+
readonly removeFormFields?: boolean;
|
|
88
|
+
readonly removeEmbeddedFiles?: boolean;
|
|
89
|
+
readonly linearize?: boolean;
|
|
90
|
+
readonly fontEmbedding?: FontEmbeddingMode;
|
|
91
|
+
readonly convertColorSpace?: ColorSpaceType;
|
|
92
|
+
readonly flattenTransparency?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Compression options
|
|
96
|
+
*/
|
|
97
|
+
export interface CompressionOptions {
|
|
98
|
+
readonly compressStreams?: boolean;
|
|
99
|
+
readonly compressObjects?: boolean;
|
|
100
|
+
readonly algorithm?: 'flate' | 'lzw' | 'none';
|
|
101
|
+
readonly level?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Image optimization options
|
|
105
|
+
*/
|
|
106
|
+
export interface ImageOptimizationOptions {
|
|
107
|
+
readonly maxDpi?: number;
|
|
108
|
+
readonly minDpi?: number;
|
|
109
|
+
readonly targetQuality?: number;
|
|
110
|
+
readonly targetFormat?: ImageCompressionType;
|
|
111
|
+
readonly convertColor?: ColorSpaceType;
|
|
112
|
+
readonly removeIccProfiles?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Font optimization options
|
|
116
|
+
*/
|
|
117
|
+
export interface FontOptimizationOptions {
|
|
118
|
+
readonly mode?: FontEmbeddingMode;
|
|
119
|
+
readonly removeUnusedFonts?: boolean;
|
|
120
|
+
readonly mergeSubsets?: boolean;
|
|
121
|
+
readonly convertToType1?: boolean;
|
|
122
|
+
readonly convertToOpenType?: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Linearization options
|
|
126
|
+
*/
|
|
127
|
+
export interface LinearizationOptions {
|
|
128
|
+
readonly firstPageEnd?: number;
|
|
129
|
+
readonly primaryHint?: boolean;
|
|
130
|
+
readonly overflowHint?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Optimization result
|
|
134
|
+
*/
|
|
135
|
+
export interface OptimizationResult {
|
|
136
|
+
readonly success: boolean;
|
|
137
|
+
readonly originalSize: number;
|
|
138
|
+
readonly optimizedSize: number;
|
|
139
|
+
readonly reductionPercent: number;
|
|
140
|
+
readonly reductionBytes: number;
|
|
141
|
+
readonly duration: number;
|
|
142
|
+
readonly details?: {
|
|
143
|
+
readonly imagesOptimized?: number;
|
|
144
|
+
readonly fontsOptimized?: number;
|
|
145
|
+
readonly objectsRemoved?: number;
|
|
146
|
+
readonly streamsCompressed?: number;
|
|
147
|
+
};
|
|
148
|
+
readonly error?: string;
|
|
149
|
+
readonly warnings?: readonly string[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Document repair result
|
|
153
|
+
*/
|
|
154
|
+
export interface RepairResult {
|
|
155
|
+
readonly success: boolean;
|
|
156
|
+
readonly issuesFound: number;
|
|
157
|
+
readonly issuesFixed: number;
|
|
158
|
+
readonly issues: readonly string[];
|
|
159
|
+
readonly error?: string;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Document statistics
|
|
163
|
+
*/
|
|
164
|
+
export interface DocumentStatistics {
|
|
165
|
+
readonly pageCount: number;
|
|
166
|
+
readonly fileSize: number;
|
|
167
|
+
readonly objectCount: number;
|
|
168
|
+
readonly streamCount: number;
|
|
169
|
+
readonly imageCount: number;
|
|
170
|
+
readonly fontCount: number;
|
|
171
|
+
readonly annotationCount: number;
|
|
172
|
+
readonly bookmarkCount: number;
|
|
173
|
+
readonly embeddedFileCount: number;
|
|
174
|
+
readonly formFieldCount: number;
|
|
175
|
+
readonly signatureCount: number;
|
|
176
|
+
readonly hasJavaScript: boolean;
|
|
177
|
+
readonly hasXfa: boolean;
|
|
178
|
+
readonly isLinearized: boolean;
|
|
179
|
+
readonly isEncrypted: boolean;
|
|
180
|
+
readonly pdfVersion: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Page information
|
|
184
|
+
*/
|
|
185
|
+
export interface PageInfo {
|
|
186
|
+
readonly index: number;
|
|
187
|
+
readonly width: number;
|
|
188
|
+
readonly height: number;
|
|
189
|
+
readonly rotation: number;
|
|
190
|
+
readonly hasAnnotations: boolean;
|
|
191
|
+
readonly hasText: boolean;
|
|
192
|
+
readonly hasImages: boolean;
|
|
193
|
+
readonly mediaBox: readonly [number, number, number, number];
|
|
194
|
+
readonly cropBox?: readonly [number, number, number, number];
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Document Utility Manager - Complete document optimization and manipulation
|
|
198
|
+
*
|
|
199
|
+
* Provides 35 functions for document utilities.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const doc = await PdfDocument.open('large-document.pdf');
|
|
204
|
+
* const utilityManager = new DocumentUtilityManager(doc);
|
|
205
|
+
*
|
|
206
|
+
* // Optimize document
|
|
207
|
+
* const result = await utilityManager.optimizeDocument({
|
|
208
|
+
* level: OptimizationLevel.AGGRESSIVE,
|
|
209
|
+
* compressImages: true,
|
|
210
|
+
* imageQuality: 75,
|
|
211
|
+
* linearize: true,
|
|
212
|
+
* });
|
|
213
|
+
*
|
|
214
|
+
* console.log(`Reduced by ${result.reductionPercent}%`);
|
|
215
|
+
*
|
|
216
|
+
* // Save optimized document
|
|
217
|
+
* await utilityManager.saveOptimized('optimized.pdf');
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare class DocumentUtilityManager extends EventEmitter {
|
|
221
|
+
private readonly document;
|
|
222
|
+
private lastOptimizationResult;
|
|
223
|
+
constructor(document: any);
|
|
224
|
+
/**
|
|
225
|
+
* Optimizes the document with specified options
|
|
226
|
+
*/
|
|
227
|
+
optimizeDocument(options?: OptimizationOptions): Promise<OptimizationResult>;
|
|
228
|
+
/**
|
|
229
|
+
* Compresses document streams
|
|
230
|
+
*/
|
|
231
|
+
compressStreams(options?: CompressionOptions): Promise<boolean>;
|
|
232
|
+
/**
|
|
233
|
+
* Optimizes images in the document
|
|
234
|
+
*/
|
|
235
|
+
optimizeImages(options?: ImageOptimizationOptions): Promise<number>;
|
|
236
|
+
/**
|
|
237
|
+
* Optimizes fonts in the document
|
|
238
|
+
*/
|
|
239
|
+
optimizeFonts(options?: FontOptimizationOptions): Promise<number>;
|
|
240
|
+
/**
|
|
241
|
+
* Linearizes the document for fast web view
|
|
242
|
+
*/
|
|
243
|
+
linearize(options?: LinearizationOptions): Promise<boolean>;
|
|
244
|
+
/**
|
|
245
|
+
* Removes unused objects from the document
|
|
246
|
+
*/
|
|
247
|
+
removeUnusedObjects(): Promise<number>;
|
|
248
|
+
/**
|
|
249
|
+
* Flattens transparency in the document
|
|
250
|
+
*/
|
|
251
|
+
flattenTransparency(): Promise<boolean>;
|
|
252
|
+
/**
|
|
253
|
+
* Converts color space
|
|
254
|
+
*/
|
|
255
|
+
convertColorSpace(targetColorSpace: ColorSpaceType): Promise<boolean>;
|
|
256
|
+
/**
|
|
257
|
+
* Rotates pages
|
|
258
|
+
*/
|
|
259
|
+
rotatePages(pageRange: PageRange | 'all', degrees: 90 | 180 | 270): Promise<number>;
|
|
260
|
+
/**
|
|
261
|
+
* Scales pages
|
|
262
|
+
*/
|
|
263
|
+
scalePages(pageRange: PageRange | 'all', scaleX: number, scaleY: number): Promise<number>;
|
|
264
|
+
/**
|
|
265
|
+
* Crops pages
|
|
266
|
+
*/
|
|
267
|
+
cropPages(pageRange: PageRange | 'all', cropBox: readonly [number, number, number, number]): Promise<number>;
|
|
268
|
+
/**
|
|
269
|
+
* Removes pages
|
|
270
|
+
*/
|
|
271
|
+
removePages(pageIndices: readonly number[]): Promise<boolean>;
|
|
272
|
+
/**
|
|
273
|
+
* Reorders pages
|
|
274
|
+
*/
|
|
275
|
+
reorderPages(newOrder: readonly number[]): Promise<boolean>;
|
|
276
|
+
/**
|
|
277
|
+
* Duplicates pages
|
|
278
|
+
*/
|
|
279
|
+
duplicatePages(pageIndices: readonly number[], times?: number): Promise<boolean>;
|
|
280
|
+
/**
|
|
281
|
+
* Extracts pages to a new document
|
|
282
|
+
*/
|
|
283
|
+
extractPages(pageIndices: readonly number[]): Promise<Buffer | null>;
|
|
284
|
+
/**
|
|
285
|
+
* Inserts blank pages
|
|
286
|
+
*/
|
|
287
|
+
insertBlankPages(afterPageIndex: number, count: number, width?: number, height?: number): Promise<boolean>;
|
|
288
|
+
/**
|
|
289
|
+
* Gets document statistics
|
|
290
|
+
*/
|
|
291
|
+
getDocumentStatistics(): Promise<DocumentStatistics | null>;
|
|
292
|
+
/**
|
|
293
|
+
* Gets page information
|
|
294
|
+
*/
|
|
295
|
+
getPageInfo(pageIndex: number): Promise<PageInfo | null>;
|
|
296
|
+
/**
|
|
297
|
+
* Gets page count
|
|
298
|
+
*/
|
|
299
|
+
getPageCount(): Promise<number>;
|
|
300
|
+
/**
|
|
301
|
+
* Gets file size in bytes
|
|
302
|
+
*/
|
|
303
|
+
getFileSize(): Promise<number>;
|
|
304
|
+
/**
|
|
305
|
+
* Checks if document is linearized
|
|
306
|
+
*/
|
|
307
|
+
isLinearized(): Promise<boolean>;
|
|
308
|
+
/**
|
|
309
|
+
* Gets last optimization result
|
|
310
|
+
*/
|
|
311
|
+
getLastOptimizationResult(): OptimizationResult | null;
|
|
312
|
+
/**
|
|
313
|
+
* Repairs the document
|
|
314
|
+
*/
|
|
315
|
+
repairDocument(): Promise<RepairResult>;
|
|
316
|
+
/**
|
|
317
|
+
* Removes all metadata
|
|
318
|
+
*/
|
|
319
|
+
removeAllMetadata(): Promise<boolean>;
|
|
320
|
+
/**
|
|
321
|
+
* Removes all JavaScript
|
|
322
|
+
*/
|
|
323
|
+
removeAllJavaScript(): Promise<boolean>;
|
|
324
|
+
/**
|
|
325
|
+
* Removes all annotations
|
|
326
|
+
*/
|
|
327
|
+
removeAllAnnotations(): Promise<number>;
|
|
328
|
+
/**
|
|
329
|
+
* Removes all embedded files
|
|
330
|
+
*/
|
|
331
|
+
removeAllEmbeddedFiles(): Promise<number>;
|
|
332
|
+
/**
|
|
333
|
+
* Saves the optimized document to a file
|
|
334
|
+
*/
|
|
335
|
+
saveOptimized(filePath: string): Promise<boolean>;
|
|
336
|
+
/**
|
|
337
|
+
* Saves the document to bytes
|
|
338
|
+
*/
|
|
339
|
+
saveToBytes(): Promise<Buffer | null>;
|
|
340
|
+
/**
|
|
341
|
+
* Saves with incremental update
|
|
342
|
+
*/
|
|
343
|
+
saveIncremental(filePath: string): Promise<boolean>;
|
|
344
|
+
/**
|
|
345
|
+
* Saves with specific PDF version
|
|
346
|
+
*/
|
|
347
|
+
saveWithVersion(filePath: string, version: string): Promise<boolean>;
|
|
348
|
+
/**
|
|
349
|
+
* Exports pages as separate PDFs
|
|
350
|
+
*/
|
|
351
|
+
exportPagesAsSeparateFiles(outputDir: string, prefix?: string): Promise<number>;
|
|
352
|
+
/**
|
|
353
|
+
* Merges another PDF into this document
|
|
354
|
+
*/
|
|
355
|
+
mergePdf(otherPdfBuffer: Buffer, atPageIndex?: number): Promise<boolean>;
|
|
356
|
+
/**
|
|
357
|
+
* Merges multiple PDFs
|
|
358
|
+
*/
|
|
359
|
+
mergeMultiplePdfs(pdfBuffers: readonly Buffer[]): Promise<boolean>;
|
|
360
|
+
/**
|
|
361
|
+
* Appends pages from another PDF
|
|
362
|
+
*/
|
|
363
|
+
appendPagesFromPdf(otherPdfBuffer: Buffer, pageIndices?: readonly number[]): Promise<boolean>;
|
|
364
|
+
/**
|
|
365
|
+
* Cleanup resources
|
|
366
|
+
*/
|
|
367
|
+
destroy(): void;
|
|
368
|
+
}
|
|
369
|
+
export default DocumentUtilityManager;
|