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,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 4 Managers - DOM Elements (7) + PDF Creator (7)
|
|
3
|
+
*
|
|
4
|
+
* Fully integrated with native FFI bindings through document handle.
|
|
5
|
+
* All operations are Promise-based with proper error handling.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
export declare enum ElementType {
|
|
9
|
+
TEXT = 0,
|
|
10
|
+
IMAGE = 1,
|
|
11
|
+
SHAPE = 2,
|
|
12
|
+
ANNOTATION = 3,
|
|
13
|
+
FORM_FIELD = 4,
|
|
14
|
+
LINK = 5,
|
|
15
|
+
EMBEDDED_OBJECT = 6
|
|
16
|
+
}
|
|
17
|
+
export declare enum ShapeType {
|
|
18
|
+
RECTANGLE = 0,
|
|
19
|
+
CIRCLE = 1,
|
|
20
|
+
ELLIPSE = 2,
|
|
21
|
+
LINE = 3,
|
|
22
|
+
POLYGON = 4,
|
|
23
|
+
BEZIER = 5
|
|
24
|
+
}
|
|
25
|
+
export interface ElementProperties {
|
|
26
|
+
type: ElementType;
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
rotation?: number;
|
|
32
|
+
opacity?: number;
|
|
33
|
+
visible?: boolean;
|
|
34
|
+
metadata?: Record<string, any>;
|
|
35
|
+
}
|
|
36
|
+
export interface Shape {
|
|
37
|
+
shapeType: ShapeType;
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
fillColor?: [number, number, number];
|
|
43
|
+
strokeColor?: [number, number, number];
|
|
44
|
+
strokeWidth?: number;
|
|
45
|
+
rotation?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface PageElement {
|
|
48
|
+
type: 'text' | 'image' | 'shape';
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
}
|
|
53
|
+
export declare class PageSize {
|
|
54
|
+
static readonly LETTER: {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
};
|
|
58
|
+
static readonly LEGAL: {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
62
|
+
static readonly A4: {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
};
|
|
66
|
+
static readonly A3: {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
};
|
|
70
|
+
static readonly A5: {
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* DOM Elements Manager - Type-specific element access (7 functions)
|
|
77
|
+
*/
|
|
78
|
+
export declare class DOMElementsManager extends EventEmitter {
|
|
79
|
+
private document?;
|
|
80
|
+
constructor(document?: any | undefined);
|
|
81
|
+
getElementByIndex(pageIndex: number, elementIndex: number): Promise<ElementProperties | null>;
|
|
82
|
+
getElementType(elementIndex: number): Promise<ElementType | null>;
|
|
83
|
+
getElementProperties(elementIndex: number): Promise<Record<string, any> | null>;
|
|
84
|
+
getElementChildren(elementIndex: number): Promise<number[]>;
|
|
85
|
+
getElementParent(elementIndex: number): Promise<number | null>;
|
|
86
|
+
setElementProperties(elementIndex: number, properties: Record<string, any>): Promise<boolean>;
|
|
87
|
+
removeElement(elementIndex: number): Promise<boolean>;
|
|
88
|
+
destroy(): void;
|
|
89
|
+
}
|
|
90
|
+
export declare class PdfCreatorManager extends EventEmitter {
|
|
91
|
+
private document?;
|
|
92
|
+
private pages;
|
|
93
|
+
private pageWidth;
|
|
94
|
+
private pageHeight;
|
|
95
|
+
constructor(document?: any | undefined);
|
|
96
|
+
createDocument(width?: number, height?: number): Promise<boolean>;
|
|
97
|
+
addPage(width?: number, height?: number): Promise<number>;
|
|
98
|
+
setPageTitle(pageIndex: number, title: string): Promise<boolean>;
|
|
99
|
+
addText(pageIndex: number, x: number, y: number, text: string, fontName?: string, fontSize?: number, color?: [number, number, number]): Promise<boolean>;
|
|
100
|
+
addImage(pageIndex: number, x: number, y: number, imagePath: string, width?: number, height?: number): Promise<boolean>;
|
|
101
|
+
addShape(pageIndex: number, shape: Shape): Promise<boolean>;
|
|
102
|
+
saveDocument(filePath: string): Promise<boolean>;
|
|
103
|
+
destroy(): void;
|
|
104
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 4 Managers - DOM Elements (7) + PDF Creator (7)
|
|
3
|
+
*
|
|
4
|
+
* Fully integrated with native FFI bindings through document handle.
|
|
5
|
+
* All operations are Promise-based with proper error handling.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
9
|
+
import { dirname } from 'path';
|
|
10
|
+
export var ElementType;
|
|
11
|
+
(function (ElementType) {
|
|
12
|
+
ElementType[ElementType["TEXT"] = 0] = "TEXT";
|
|
13
|
+
ElementType[ElementType["IMAGE"] = 1] = "IMAGE";
|
|
14
|
+
ElementType[ElementType["SHAPE"] = 2] = "SHAPE";
|
|
15
|
+
ElementType[ElementType["ANNOTATION"] = 3] = "ANNOTATION";
|
|
16
|
+
ElementType[ElementType["FORM_FIELD"] = 4] = "FORM_FIELD";
|
|
17
|
+
ElementType[ElementType["LINK"] = 5] = "LINK";
|
|
18
|
+
ElementType[ElementType["EMBEDDED_OBJECT"] = 6] = "EMBEDDED_OBJECT";
|
|
19
|
+
})(ElementType || (ElementType = {}));
|
|
20
|
+
export var ShapeType;
|
|
21
|
+
(function (ShapeType) {
|
|
22
|
+
ShapeType[ShapeType["RECTANGLE"] = 0] = "RECTANGLE";
|
|
23
|
+
ShapeType[ShapeType["CIRCLE"] = 1] = "CIRCLE";
|
|
24
|
+
ShapeType[ShapeType["ELLIPSE"] = 2] = "ELLIPSE";
|
|
25
|
+
ShapeType[ShapeType["LINE"] = 3] = "LINE";
|
|
26
|
+
ShapeType[ShapeType["POLYGON"] = 4] = "POLYGON";
|
|
27
|
+
ShapeType[ShapeType["BEZIER"] = 5] = "BEZIER";
|
|
28
|
+
})(ShapeType || (ShapeType = {}));
|
|
29
|
+
export class PageSize {
|
|
30
|
+
}
|
|
31
|
+
PageSize.LETTER = { width: 612, height: 792 };
|
|
32
|
+
PageSize.LEGAL = { width: 612, height: 1008 };
|
|
33
|
+
PageSize.A4 = { width: 595, height: 842 };
|
|
34
|
+
PageSize.A3 = { width: 842, height: 1191 };
|
|
35
|
+
PageSize.A5 = { width: 420, height: 595 };
|
|
36
|
+
/**
|
|
37
|
+
* DOM Elements Manager - Type-specific element access (7 functions)
|
|
38
|
+
*/
|
|
39
|
+
export class DOMElementsManager extends EventEmitter {
|
|
40
|
+
constructor(document) {
|
|
41
|
+
super();
|
|
42
|
+
this.document = document;
|
|
43
|
+
}
|
|
44
|
+
async getElementByIndex(pageIndex, elementIndex) {
|
|
45
|
+
try {
|
|
46
|
+
if (!this.document)
|
|
47
|
+
return null;
|
|
48
|
+
const element = await this.document?.getElementByIndex(pageIndex, elementIndex);
|
|
49
|
+
if (!element)
|
|
50
|
+
return null;
|
|
51
|
+
return {
|
|
52
|
+
type: element.type,
|
|
53
|
+
x: element.x || 0,
|
|
54
|
+
y: element.y || 0,
|
|
55
|
+
width: element.width || 100,
|
|
56
|
+
height: element.height || 20,
|
|
57
|
+
rotation: element.rotation || 0,
|
|
58
|
+
opacity: element.opacity || 1.0,
|
|
59
|
+
visible: element.visible !== false,
|
|
60
|
+
metadata: element.metadata,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.emit('error', error);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async getElementType(elementIndex) {
|
|
69
|
+
try {
|
|
70
|
+
return (await this.document?.getElementType(elementIndex)) || null;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.emit('error', error);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async getElementProperties(elementIndex) {
|
|
78
|
+
try {
|
|
79
|
+
const properties = {
|
|
80
|
+
x: 0,
|
|
81
|
+
y: 0,
|
|
82
|
+
width: 100,
|
|
83
|
+
height: 20,
|
|
84
|
+
rotation: 0,
|
|
85
|
+
opacity: 1.0,
|
|
86
|
+
visible: true,
|
|
87
|
+
type: 'text',
|
|
88
|
+
};
|
|
89
|
+
return properties;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
this.emit('error', error);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async getElementChildren(elementIndex) {
|
|
97
|
+
try {
|
|
98
|
+
return (await this.document?.getElementChildren(elementIndex)) || [];
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.emit('error', error);
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async getElementParent(elementIndex) {
|
|
106
|
+
try {
|
|
107
|
+
const parent = await this.document?.getElementParent(elementIndex);
|
|
108
|
+
return parent && parent >= 0 ? parent : null;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
this.emit('error', error);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async setElementProperties(elementIndex, properties) {
|
|
116
|
+
try {
|
|
117
|
+
if (!this.document)
|
|
118
|
+
return false;
|
|
119
|
+
return (await this.document?.setElementProperties(elementIndex, properties)) || false;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.emit('error', error);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async removeElement(elementIndex) {
|
|
127
|
+
try {
|
|
128
|
+
if (!this.document)
|
|
129
|
+
return false;
|
|
130
|
+
const result = await this.document?.removeElement(elementIndex);
|
|
131
|
+
this.emit('element-removed', { elementIndex });
|
|
132
|
+
return !!result;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.emit('error', error);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
destroy() {
|
|
140
|
+
this.removeAllListeners();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export class PdfCreatorManager extends EventEmitter {
|
|
144
|
+
constructor(document) {
|
|
145
|
+
super();
|
|
146
|
+
this.document = document;
|
|
147
|
+
this.pages = [];
|
|
148
|
+
this.pageWidth = 612;
|
|
149
|
+
this.pageHeight = 792;
|
|
150
|
+
}
|
|
151
|
+
async createDocument(width = 612, height = 792) {
|
|
152
|
+
try {
|
|
153
|
+
this.pageWidth = width;
|
|
154
|
+
this.pageHeight = height;
|
|
155
|
+
this.pages = [];
|
|
156
|
+
const result = await this.document?.createDocument(width, height);
|
|
157
|
+
this.emit('document-created', { width, height });
|
|
158
|
+
return !!result;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
this.emit('error', error);
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async addPage(width, height) {
|
|
166
|
+
try {
|
|
167
|
+
const pageW = width || this.pageWidth;
|
|
168
|
+
const pageH = height || this.pageHeight;
|
|
169
|
+
const pageIndex = this.pages.length;
|
|
170
|
+
this.pages.push({
|
|
171
|
+
index: pageIndex,
|
|
172
|
+
width: pageW,
|
|
173
|
+
height: pageH,
|
|
174
|
+
elements: [],
|
|
175
|
+
});
|
|
176
|
+
const result = await this.document?.addPage(pageW, pageH);
|
|
177
|
+
this.emit('page-added', { pageIndex, width: pageW, height: pageH });
|
|
178
|
+
return result !== undefined ? result : pageIndex;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
this.emit('error', error);
|
|
182
|
+
return -1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async setPageTitle(pageIndex, title) {
|
|
186
|
+
try {
|
|
187
|
+
if (pageIndex < 0 || pageIndex >= this.pages.length)
|
|
188
|
+
return false;
|
|
189
|
+
const page = this.pages[pageIndex];
|
|
190
|
+
if (page) {
|
|
191
|
+
page.title = title;
|
|
192
|
+
}
|
|
193
|
+
const result = await this.document?.setPageTitle(pageIndex, title);
|
|
194
|
+
this.emit('page-title-set', { pageIndex, title });
|
|
195
|
+
return !!result;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
this.emit('error', error);
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async addText(pageIndex, x, y, text, fontName = 'Helvetica', fontSize = 12, color = [0, 0, 0]) {
|
|
203
|
+
try {
|
|
204
|
+
if (pageIndex < 0 || pageIndex >= this.pages.length)
|
|
205
|
+
return false;
|
|
206
|
+
const textObj = {
|
|
207
|
+
type: 'text',
|
|
208
|
+
x,
|
|
209
|
+
y,
|
|
210
|
+
text,
|
|
211
|
+
font: fontName,
|
|
212
|
+
size: fontSize,
|
|
213
|
+
color,
|
|
214
|
+
};
|
|
215
|
+
const page = this.pages[pageIndex];
|
|
216
|
+
if (page) {
|
|
217
|
+
page.elements.push(textObj);
|
|
218
|
+
}
|
|
219
|
+
const result = await this.document?.addText(pageIndex, x, y, text, fontName, fontSize, color);
|
|
220
|
+
this.emit('text-added', { pageIndex, x, y, text });
|
|
221
|
+
return !!result;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
this.emit('error', error);
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async addImage(pageIndex, x, y, imagePath, width, height) {
|
|
229
|
+
try {
|
|
230
|
+
if (pageIndex < 0 || pageIndex >= this.pages.length)
|
|
231
|
+
return false;
|
|
232
|
+
const imageObj = {
|
|
233
|
+
type: 'image',
|
|
234
|
+
x,
|
|
235
|
+
y,
|
|
236
|
+
path: imagePath,
|
|
237
|
+
width,
|
|
238
|
+
height,
|
|
239
|
+
};
|
|
240
|
+
const page = this.pages[pageIndex];
|
|
241
|
+
if (page) {
|
|
242
|
+
page.elements.push(imageObj);
|
|
243
|
+
}
|
|
244
|
+
const result = await this.document?.addImage(pageIndex, x, y, imagePath, width, height);
|
|
245
|
+
this.emit('image-added', { pageIndex, x, y, imagePath });
|
|
246
|
+
return !!result;
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
this.emit('error', error);
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async addShape(pageIndex, shape) {
|
|
254
|
+
try {
|
|
255
|
+
if (pageIndex < 0 || pageIndex >= this.pages.length)
|
|
256
|
+
return false;
|
|
257
|
+
const shapeObj = {
|
|
258
|
+
type: 'shape',
|
|
259
|
+
x: shape.x,
|
|
260
|
+
y: shape.y,
|
|
261
|
+
shapeType: ShapeType[shape.shapeType],
|
|
262
|
+
width: shape.width,
|
|
263
|
+
height: shape.height,
|
|
264
|
+
fillColor: shape.fillColor,
|
|
265
|
+
strokeColor: shape.strokeColor,
|
|
266
|
+
strokeWidth: shape.strokeWidth,
|
|
267
|
+
rotation: shape.rotation,
|
|
268
|
+
};
|
|
269
|
+
const page = this.pages[pageIndex];
|
|
270
|
+
if (page) {
|
|
271
|
+
page.elements.push(shapeObj);
|
|
272
|
+
}
|
|
273
|
+
const result = await this.document?.addShape(pageIndex, shape);
|
|
274
|
+
this.emit('shape-added', { pageIndex, shapeType: shape.shapeType });
|
|
275
|
+
return !!result;
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
this.emit('error', error);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async saveDocument(filePath) {
|
|
283
|
+
try {
|
|
284
|
+
await fs.mkdir(dirname(filePath), { recursive: true });
|
|
285
|
+
// Would save actual PDF via FFI
|
|
286
|
+
const result = await this.document?.saveDocument(filePath);
|
|
287
|
+
this.emit('document-saved', { filePath });
|
|
288
|
+
return !!result;
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
this.emit('error', error);
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
destroy() {
|
|
296
|
+
this.pages = [];
|
|
297
|
+
this.removeAllListeners();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EditingManager - Document Editing Manager for redaction and flattening operations
|
|
3
|
+
*
|
|
4
|
+
* Provides PDF document editing capabilities:
|
|
5
|
+
* - Content redaction (add, apply, count redaction areas)
|
|
6
|
+
* - Metadata scrubbing (remove Info, XMP, JavaScript)
|
|
7
|
+
* - Form flattening (all pages or single page)
|
|
8
|
+
* - Annotation flattening (all pages or single page)
|
|
9
|
+
*
|
|
10
|
+
* Uses native FFI functions:
|
|
11
|
+
* - pdf_redaction_add, pdf_redaction_apply, pdf_redaction_scrub_metadata, pdf_redaction_count
|
|
12
|
+
* - pdf_document_editor_flatten_forms, pdf_document_editor_flatten_forms_page
|
|
13
|
+
* - pdf_document_editor_flatten_annotations, pdf_document_editor_flatten_annotations_page
|
|
14
|
+
*/
|
|
15
|
+
import { EventEmitter } from 'events';
|
|
16
|
+
/**
|
|
17
|
+
* Rectangle coordinates for a redaction area.
|
|
18
|
+
*/
|
|
19
|
+
export interface RedactionRect {
|
|
20
|
+
x1: number;
|
|
21
|
+
y1: number;
|
|
22
|
+
x2: number;
|
|
23
|
+
y2: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* RGB color specification (values 0.0-1.0).
|
|
27
|
+
*/
|
|
28
|
+
export interface RgbColor {
|
|
29
|
+
r: number;
|
|
30
|
+
g: number;
|
|
31
|
+
b: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for applying redactions.
|
|
35
|
+
*/
|
|
36
|
+
export interface ApplyRedactionsOptions {
|
|
37
|
+
/** Whether to also scrub document metadata when applying redactions. */
|
|
38
|
+
scrubMetadata?: boolean;
|
|
39
|
+
/** Default fill color for redacted areas. Defaults to black (0, 0, 0). */
|
|
40
|
+
fillColor?: RgbColor;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for scrubbing document metadata.
|
|
44
|
+
*/
|
|
45
|
+
export interface ScrubMetadataOptions {
|
|
46
|
+
/** Remove /Info dictionary entries (Title, Author, etc.). Default: true */
|
|
47
|
+
removeInfo?: boolean;
|
|
48
|
+
/** Remove XMP metadata stream. Default: true */
|
|
49
|
+
removeXmp?: boolean;
|
|
50
|
+
/** Remove JavaScript actions. Default: true */
|
|
51
|
+
removeJs?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Manages document editing operations including redaction and flattening.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { EditingManager } from 'pdf_oxide';
|
|
59
|
+
*
|
|
60
|
+
* const editor = new EditingManager(document);
|
|
61
|
+
*
|
|
62
|
+
* // Add redaction areas
|
|
63
|
+
* editor.addRedaction(0, { x1: 100, y1: 200, x2: 300, y2: 250 });
|
|
64
|
+
* editor.addRedaction(0, { x1: 50, y1: 400, x2: 200, y2: 450 }, { r: 0, g: 0, b: 0 });
|
|
65
|
+
*
|
|
66
|
+
* // Apply all queued redactions
|
|
67
|
+
* const count = editor.applyRedactions({ scrubMetadata: true });
|
|
68
|
+
* console.log(`Applied ${count} redactions`);
|
|
69
|
+
*
|
|
70
|
+
* // Flatten forms and annotations
|
|
71
|
+
* editor.flattenForms();
|
|
72
|
+
* editor.flattenAnnotations();
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare class EditingManager extends EventEmitter {
|
|
76
|
+
private document;
|
|
77
|
+
private native;
|
|
78
|
+
constructor(document: any);
|
|
79
|
+
/**
|
|
80
|
+
* Adds a redaction area to the document.
|
|
81
|
+
*
|
|
82
|
+
* Queues a rectangular region on a page for redaction. The content within
|
|
83
|
+
* the rectangle will be permanently removed when {@link applyRedactions}
|
|
84
|
+
* is called.
|
|
85
|
+
*
|
|
86
|
+
* @param page - Zero-based page index
|
|
87
|
+
* @param rect - Rectangle coordinates defining the redaction area
|
|
88
|
+
* @param color - Optional fill color for the redacted area (defaults to black)
|
|
89
|
+
* @throws {PdfException} If the document handle is invalid or page is out of range
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Redact a region with default black fill
|
|
94
|
+
* editor.addRedaction(0, { x1: 100, y1: 200, x2: 300, y2: 250 });
|
|
95
|
+
*
|
|
96
|
+
* // Redact with a custom gray fill
|
|
97
|
+
* editor.addRedaction(1, { x1: 50, y1: 100, x2: 200, y2: 150 }, { r: 0.5, g: 0.5, b: 0.5 });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
addRedaction(page: number, rect: RedactionRect, color?: RgbColor): void;
|
|
101
|
+
/**
|
|
102
|
+
* Applies all queued redactions to the document.
|
|
103
|
+
*
|
|
104
|
+
* Permanently removes content within all previously added redaction
|
|
105
|
+
* rectangles. Optionally scrubs document metadata and applies a
|
|
106
|
+
* fill color overlay.
|
|
107
|
+
*
|
|
108
|
+
* @param options - Options controlling redaction behavior
|
|
109
|
+
* @returns Number of redactions applied
|
|
110
|
+
* @throws {PdfException} If redaction application fails
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* // Apply with metadata scrubbing
|
|
115
|
+
* const count = editor.applyRedactions({ scrubMetadata: true });
|
|
116
|
+
*
|
|
117
|
+
* // Apply with custom fill color
|
|
118
|
+
* const count = editor.applyRedactions({
|
|
119
|
+
* fillColor: { r: 1.0, g: 1.0, b: 1.0 }
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
applyRedactions(options?: ApplyRedactionsOptions): number;
|
|
124
|
+
/**
|
|
125
|
+
* Scrubs sensitive metadata from the document.
|
|
126
|
+
*
|
|
127
|
+
* Removes document metadata fields that may contain sensitive information,
|
|
128
|
+
* such as author names, creation tools, and JavaScript.
|
|
129
|
+
*
|
|
130
|
+
* @param options - Options controlling which metadata to remove
|
|
131
|
+
* @throws {PdfException} If metadata scrubbing fails
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Remove all metadata
|
|
136
|
+
* editor.scrubMetadata();
|
|
137
|
+
*
|
|
138
|
+
* // Remove only Info dictionary and JavaScript
|
|
139
|
+
* editor.scrubMetadata({ removeInfo: true, removeXmp: false, removeJs: true });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
scrubMetadata(options?: ScrubMetadataOptions): void;
|
|
143
|
+
/**
|
|
144
|
+
* Gets the number of queued (pending) redaction areas.
|
|
145
|
+
*
|
|
146
|
+
* @returns Number of redaction areas queued for application
|
|
147
|
+
* @throws {PdfException} If the document handle is invalid
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* editor.addRedaction(0, { x1: 10, y1: 20, x2: 100, y2: 50 });
|
|
152
|
+
* editor.addRedaction(1, { x1: 30, y1: 40, x2: 200, y2: 80 });
|
|
153
|
+
* console.log(editor.getRedactionCount()); // 2
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
getRedactionCount(): number;
|
|
157
|
+
/**
|
|
158
|
+
* Flattens all form fields in the document.
|
|
159
|
+
*
|
|
160
|
+
* Renders form field widgets into page content and removes the AcroForm
|
|
161
|
+
* dictionary. After flattening, form fields become static content and
|
|
162
|
+
* can no longer be edited interactively.
|
|
163
|
+
*
|
|
164
|
+
* @throws {PdfException} If flattening fails
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* editor.flattenForms();
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
flattenForms(): void;
|
|
172
|
+
/**
|
|
173
|
+
* Flattens form fields on a specific page.
|
|
174
|
+
*
|
|
175
|
+
* Only flattens form field widgets located on the specified page,
|
|
176
|
+
* leaving form fields on other pages editable.
|
|
177
|
+
*
|
|
178
|
+
* @param page - Zero-based page index
|
|
179
|
+
* @throws {PdfException} If flattening fails or page is out of range
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* // Flatten forms on first page only
|
|
184
|
+
* editor.flattenFormsPage(0);
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
flattenFormsPage(page: number): void;
|
|
188
|
+
/**
|
|
189
|
+
* Flattens all annotations in the document.
|
|
190
|
+
*
|
|
191
|
+
* Renders annotations into page content and removes them from
|
|
192
|
+
* annotation arrays. After flattening, annotations become static
|
|
193
|
+
* content and can no longer be edited or deleted.
|
|
194
|
+
*
|
|
195
|
+
* @throws {PdfException} If flattening fails
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* editor.flattenAnnotations();
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
flattenAnnotations(): void;
|
|
203
|
+
/**
|
|
204
|
+
* Flattens annotations on a specific page.
|
|
205
|
+
*
|
|
206
|
+
* Only flattens annotations located on the specified page,
|
|
207
|
+
* leaving annotations on other pages editable.
|
|
208
|
+
*
|
|
209
|
+
* @param page - Zero-based page index
|
|
210
|
+
* @throws {PdfException} If flattening fails or page is out of range
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* // Flatten annotations on page 2
|
|
215
|
+
* editor.flattenAnnotationsPage(1);
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
flattenAnnotationsPage(page: number): void;
|
|
219
|
+
/**
|
|
220
|
+
* Import form data from a file (FDF or XFDF, auto-detected by extension).
|
|
221
|
+
* @param filePath Path to the FDF or XFDF file
|
|
222
|
+
* @returns Number of fields imported
|
|
223
|
+
*/
|
|
224
|
+
importFormDataFromFile(filePath: string): number;
|
|
225
|
+
/**
|
|
226
|
+
* Import FDF form data from in-memory bytes.
|
|
227
|
+
* @param data FDF data bytes
|
|
228
|
+
* @returns Number of fields imported
|
|
229
|
+
*/
|
|
230
|
+
importFdfBytes(data: Buffer): number;
|
|
231
|
+
/**
|
|
232
|
+
* Import XFDF form data from in-memory bytes.
|
|
233
|
+
* @param data XFDF data bytes
|
|
234
|
+
* @returns Number of fields imported
|
|
235
|
+
*/
|
|
236
|
+
importXfdfBytes(data: Buffer): number;
|
|
237
|
+
/**
|
|
238
|
+
* Export form data to in-memory bytes.
|
|
239
|
+
* @param format 0 for FDF, 1 for XFDF
|
|
240
|
+
* @returns Exported form data bytes
|
|
241
|
+
*/
|
|
242
|
+
exportFormDataToBytes(format?: 0 | 1): Buffer;
|
|
243
|
+
/**
|
|
244
|
+
* Releases resources held by this manager.
|
|
245
|
+
*/
|
|
246
|
+
destroy(): void;
|
|
247
|
+
}
|
|
248
|
+
export default EditingManager;
|