pdf-oxide 0.3.24
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/README.md +218 -0
- package/binding.gyp +35 -0
- package/package.json +78 -0
- package/src/builders/annotation-builder.ts +367 -0
- package/src/builders/conversion-options-builder.ts +257 -0
- package/src/builders/index.ts +12 -0
- package/src/builders/metadata-builder.ts +317 -0
- package/src/builders/pdf-builder.ts +386 -0
- package/src/builders/search-options-builder.ts +151 -0
- package/src/document-editor-manager.ts +318 -0
- package/src/errors.ts +1629 -0
- package/src/form-field-manager.ts +666 -0
- package/src/hybrid-ml-manager.ts +283 -0
- package/src/index.ts +453 -0
- package/src/managers/accessibility-manager.ts +338 -0
- package/src/managers/annotation-manager.ts +439 -0
- package/src/managers/barcode-manager.ts +235 -0
- package/src/managers/batch-manager.ts +533 -0
- package/src/managers/cache-manager.ts +486 -0
- package/src/managers/compliance-manager.ts +375 -0
- package/src/managers/content-manager.ts +339 -0
- package/src/managers/document-utility-manager.ts +922 -0
- package/src/managers/dom-pdf-creator.ts +365 -0
- package/src/managers/editing-manager.ts +514 -0
- package/src/managers/enterprise-manager.ts +478 -0
- package/src/managers/extended-managers.ts +437 -0
- package/src/managers/extraction-manager.ts +583 -0
- package/src/managers/final-utilities.ts +429 -0
- package/src/managers/hybrid-ml-advanced.ts +479 -0
- package/src/managers/index.ts +239 -0
- package/src/managers/layer-manager.ts +500 -0
- package/src/managers/metadata-manager.ts +303 -0
- package/src/managers/ocr-manager.ts +756 -0
- package/src/managers/optimization-manager.ts +262 -0
- package/src/managers/outline-manager.ts +196 -0
- package/src/managers/page-manager.ts +289 -0
- package/src/managers/pattern-detection.ts +440 -0
- package/src/managers/rendering-manager.ts +863 -0
- package/src/managers/search-manager.ts +385 -0
- package/src/managers/security-manager.ts +345 -0
- package/src/managers/signature-manager.ts +1664 -0
- package/src/managers/streams.ts +618 -0
- package/src/managers/xfa-manager.ts +500 -0
- package/src/pdf-creator-manager.ts +494 -0
- package/src/properties.ts +522 -0
- package/src/result-accessors-manager.ts +867 -0
- package/src/tests/advanced-features.test.ts +414 -0
- package/src/tests/advanced.test.ts +266 -0
- package/src/tests/extended-managers.test.ts +316 -0
- package/src/tests/final-utilities.test.ts +455 -0
- package/src/tests/foundation.test.ts +315 -0
- package/src/tests/high-demand.test.ts +257 -0
- package/src/tests/specialized.test.ts +97 -0
- package/src/thumbnail-manager.ts +272 -0
- package/src/types/common.ts +142 -0
- package/src/types/document-types.ts +457 -0
- package/src/types/index.ts +6 -0
- package/src/types/manager-types.ts +284 -0
- package/src/types/native-bindings.ts +517 -0
- package/src/workers/index.ts +7 -0
- package/src/workers/pool.ts +274 -0
- package/src/workers/worker.ts +131 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PdfDocument - TypeScript type definitions for pdf_oxide
|
|
3
|
+
*
|
|
4
|
+
* Provides complete type definitions for the PdfDocument class and related types.
|
|
5
|
+
* These types ensure type safety when using the pdf_oxide library in TypeScript.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { PdfDocument } from 'pdf_oxide';
|
|
10
|
+
*
|
|
11
|
+
* const doc = await PdfDocument.open('document.pdf');
|
|
12
|
+
* const pageCount = await doc.pageCount();
|
|
13
|
+
* const text = await doc.extractText(0);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Core Types
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents a rectangle in PDF coordinate space (origin at bottom-left)
|
|
23
|
+
*/
|
|
24
|
+
export interface Rect {
|
|
25
|
+
readonly x: number;
|
|
26
|
+
readonly y: number;
|
|
27
|
+
readonly width: number;
|
|
28
|
+
readonly height: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represents a point in PDF coordinate space
|
|
33
|
+
*/
|
|
34
|
+
export interface Point {
|
|
35
|
+
readonly x: number;
|
|
36
|
+
readonly y: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Represents a color (RGBA)
|
|
41
|
+
*/
|
|
42
|
+
export interface Color {
|
|
43
|
+
readonly r: number;
|
|
44
|
+
readonly g: number;
|
|
45
|
+
readonly b: number;
|
|
46
|
+
readonly a?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Standard page sizes
|
|
51
|
+
*/
|
|
52
|
+
export enum PageSizeType {
|
|
53
|
+
LETTER = 'letter',
|
|
54
|
+
LEGAL = 'legal',
|
|
55
|
+
A4 = 'a4',
|
|
56
|
+
A3 = 'a3',
|
|
57
|
+
A5 = 'a5',
|
|
58
|
+
B4 = 'b4',
|
|
59
|
+
TABLOID = 'tabloid',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Page size dimensions
|
|
64
|
+
*/
|
|
65
|
+
export interface PageSize {
|
|
66
|
+
readonly type?: PageSizeType;
|
|
67
|
+
readonly width: number;
|
|
68
|
+
readonly height: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// Document Metadata
|
|
73
|
+
// ============================================================================
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* PDF document metadata
|
|
77
|
+
*/
|
|
78
|
+
export interface DocumentMetadata {
|
|
79
|
+
readonly title?: string;
|
|
80
|
+
readonly author?: string;
|
|
81
|
+
readonly subject?: string;
|
|
82
|
+
readonly keywords?: string;
|
|
83
|
+
readonly creator?: string;
|
|
84
|
+
readonly producer?: string;
|
|
85
|
+
readonly creationDate?: Date;
|
|
86
|
+
readonly modificationDate?: Date;
|
|
87
|
+
readonly pageCount: number;
|
|
88
|
+
readonly format?: string;
|
|
89
|
+
readonly version?: string;
|
|
90
|
+
readonly isEncrypted?: boolean;
|
|
91
|
+
readonly hasXfa?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ============================================================================
|
|
95
|
+
// Form Fields
|
|
96
|
+
// ============================================================================
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Form field type enumeration
|
|
100
|
+
*/
|
|
101
|
+
export enum FormFieldType {
|
|
102
|
+
TEXT = 'text',
|
|
103
|
+
CHECKBOX = 'checkbox',
|
|
104
|
+
RADIO = 'radio',
|
|
105
|
+
COMBOBOX = 'combobox',
|
|
106
|
+
LISTBOX = 'listbox',
|
|
107
|
+
SIGNATURE = 'signature',
|
|
108
|
+
DATE = 'date',
|
|
109
|
+
BUTTON = 'button',
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Form field information
|
|
114
|
+
*/
|
|
115
|
+
export interface FormField {
|
|
116
|
+
readonly name: string;
|
|
117
|
+
readonly type: FormFieldType;
|
|
118
|
+
readonly value: string;
|
|
119
|
+
readonly pageIndex: number;
|
|
120
|
+
readonly x: number;
|
|
121
|
+
readonly y: number;
|
|
122
|
+
readonly width: number;
|
|
123
|
+
readonly height: number;
|
|
124
|
+
readonly required?: boolean;
|
|
125
|
+
readonly readonly?: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ============================================================================
|
|
129
|
+
// Page Content
|
|
130
|
+
// ============================================================================
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Text content on a page
|
|
134
|
+
*/
|
|
135
|
+
export interface TextContent {
|
|
136
|
+
readonly text: string;
|
|
137
|
+
readonly x: number;
|
|
138
|
+
readonly y: number;
|
|
139
|
+
readonly width: number;
|
|
140
|
+
readonly height: number;
|
|
141
|
+
readonly fontName?: string;
|
|
142
|
+
readonly fontSize?: number;
|
|
143
|
+
readonly confidence?: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Image content on a page
|
|
148
|
+
*/
|
|
149
|
+
export interface ImageContent {
|
|
150
|
+
readonly x: number;
|
|
151
|
+
readonly y: number;
|
|
152
|
+
readonly width: number;
|
|
153
|
+
readonly height: number;
|
|
154
|
+
readonly imageType?: string;
|
|
155
|
+
readonly bitsPerComponent?: number;
|
|
156
|
+
readonly colorSpace?: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// Annotations
|
|
161
|
+
// ============================================================================
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Annotation type enumeration
|
|
165
|
+
*/
|
|
166
|
+
export enum AnnotationType {
|
|
167
|
+
TEXT = 'text',
|
|
168
|
+
LINK = 'link',
|
|
169
|
+
HIGHLIGHT = 'highlight',
|
|
170
|
+
UNDERLINE = 'underline',
|
|
171
|
+
STRIKEOUT = 'strikeout',
|
|
172
|
+
SQUIGGLY = 'squiggly',
|
|
173
|
+
STAMP = 'stamp',
|
|
174
|
+
CARET = 'caret',
|
|
175
|
+
INK = 'ink',
|
|
176
|
+
POPUP = 'popup',
|
|
177
|
+
FILE_ATTACHMENT = 'file_attachment',
|
|
178
|
+
SOUND = 'sound',
|
|
179
|
+
MOVIE = 'movie',
|
|
180
|
+
WIDGET = 'widget',
|
|
181
|
+
SCREEN = 'screen',
|
|
182
|
+
PRINTER_MARK = 'printer_mark',
|
|
183
|
+
TRAP_NET = 'trap_net',
|
|
184
|
+
WATERMARK = 'watermark',
|
|
185
|
+
REDACT = 'redact',
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Annotation information
|
|
190
|
+
*/
|
|
191
|
+
export interface Annotation {
|
|
192
|
+
readonly type: AnnotationType;
|
|
193
|
+
readonly x: number;
|
|
194
|
+
readonly y: number;
|
|
195
|
+
readonly width: number;
|
|
196
|
+
readonly height: number;
|
|
197
|
+
readonly contents?: string;
|
|
198
|
+
readonly author?: string;
|
|
199
|
+
readonly creationDate?: Date;
|
|
200
|
+
readonly modificationDate?: Date;
|
|
201
|
+
readonly color?: Color;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// Search
|
|
206
|
+
// ============================================================================
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Search options
|
|
210
|
+
*/
|
|
211
|
+
export interface SearchOptions {
|
|
212
|
+
readonly caseSensitive?: boolean;
|
|
213
|
+
readonly wholeWord?: boolean;
|
|
214
|
+
readonly regex?: boolean;
|
|
215
|
+
readonly maxResults?: number;
|
|
216
|
+
readonly pageRange?: { start: number; end: number };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Search result
|
|
221
|
+
*/
|
|
222
|
+
export interface SearchResult {
|
|
223
|
+
readonly pageIndex: number;
|
|
224
|
+
readonly text: string;
|
|
225
|
+
readonly x: number;
|
|
226
|
+
readonly y: number;
|
|
227
|
+
readonly width: number;
|
|
228
|
+
readonly height: number;
|
|
229
|
+
readonly context?: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ============================================================================
|
|
233
|
+
// Conversion Options
|
|
234
|
+
// ============================================================================
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Markdown conversion options
|
|
238
|
+
*/
|
|
239
|
+
export interface MarkdownOptions {
|
|
240
|
+
readonly includeImages?: boolean;
|
|
241
|
+
readonly includeLinks?: boolean;
|
|
242
|
+
readonly preserveLayout?: boolean;
|
|
243
|
+
readonly pageRange?: { start: number; end: number };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* HTML conversion options
|
|
248
|
+
*/
|
|
249
|
+
export interface HtmlOptions {
|
|
250
|
+
readonly includeStyles?: boolean;
|
|
251
|
+
readonly includeImages?: boolean;
|
|
252
|
+
readonly embedImages?: boolean;
|
|
253
|
+
readonly pageRange?: { start: number; end: number };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ============================================================================
|
|
257
|
+
// Page Interface
|
|
258
|
+
// ============================================================================
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Represents a single page in a PDF document
|
|
262
|
+
*/
|
|
263
|
+
export interface PdfPage {
|
|
264
|
+
readonly index: number;
|
|
265
|
+
readonly width: number;
|
|
266
|
+
readonly height: number;
|
|
267
|
+
readonly rotation: number;
|
|
268
|
+
readonly mediaBox: Rect;
|
|
269
|
+
readonly cropBox?: Rect;
|
|
270
|
+
readonly bleedBox?: Rect;
|
|
271
|
+
readonly trimBox?: Rect;
|
|
272
|
+
readonly artBox?: Rect;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ============================================================================
|
|
276
|
+
// PdfDocument Class
|
|
277
|
+
// ============================================================================
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Main PDF document class
|
|
281
|
+
*
|
|
282
|
+
* Provides access to PDF document content, metadata, and structure.
|
|
283
|
+
* All operations are async to support non-blocking I/O.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* // Open a document
|
|
288
|
+
* const doc = await PdfDocument.open('file.pdf');
|
|
289
|
+
*
|
|
290
|
+
* // Get page count
|
|
291
|
+
* const pages = await doc.pageCount();
|
|
292
|
+
*
|
|
293
|
+
* // Extract text from first page
|
|
294
|
+
* const text = await doc.extractText(0);
|
|
295
|
+
*
|
|
296
|
+
* // Get metadata
|
|
297
|
+
* const metadata = await doc.getMetadata();
|
|
298
|
+
*
|
|
299
|
+
* // Convert to markdown
|
|
300
|
+
* const markdown = await doc.toMarkdown();
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export interface PdfDocument {
|
|
304
|
+
// ==========================================================================
|
|
305
|
+
// Static Methods
|
|
306
|
+
// ==========================================================================
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Open a PDF document from a file path
|
|
310
|
+
*/
|
|
311
|
+
// open(path: string, password?: string): Promise<PdfDocument>;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Open a PDF document from a buffer
|
|
315
|
+
*/
|
|
316
|
+
// openBuffer(buffer: Buffer, password?: string): Promise<PdfDocument>;
|
|
317
|
+
|
|
318
|
+
// ==========================================================================
|
|
319
|
+
// Document Properties
|
|
320
|
+
// ==========================================================================
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Get the number of pages in the document
|
|
324
|
+
*/
|
|
325
|
+
pageCount(): Promise<number>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Get document metadata
|
|
329
|
+
*/
|
|
330
|
+
getMetadata(): Promise<DocumentMetadata>;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Get page information
|
|
334
|
+
*/
|
|
335
|
+
getPage(pageIndex: number): Promise<PdfPage>;
|
|
336
|
+
|
|
337
|
+
// ==========================================================================
|
|
338
|
+
// Text Extraction
|
|
339
|
+
// ==========================================================================
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Extract text from a specific page
|
|
343
|
+
*/
|
|
344
|
+
extractText(pageIndex: number): Promise<string>;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Extract text from a range of pages
|
|
348
|
+
*/
|
|
349
|
+
extractTextRange(startPage: number, endPage: number): Promise<string[]>;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Extract all text from the document
|
|
353
|
+
*/
|
|
354
|
+
extractAllText(): Promise<string>;
|
|
355
|
+
|
|
356
|
+
// ==========================================================================
|
|
357
|
+
// Form Fields
|
|
358
|
+
// ==========================================================================
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Get all form fields in the document
|
|
362
|
+
*/
|
|
363
|
+
extractFormFields(): Promise<FormField[]>;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Get form field by name
|
|
367
|
+
*/
|
|
368
|
+
getFormField(fieldName: string): Promise<FormField | undefined>;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Set form field value
|
|
372
|
+
*/
|
|
373
|
+
setFormFieldValue(fieldName: string, value: string): Promise<boolean>;
|
|
374
|
+
|
|
375
|
+
// ==========================================================================
|
|
376
|
+
// Annotations
|
|
377
|
+
// ==========================================================================
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Get annotations on a specific page
|
|
381
|
+
*/
|
|
382
|
+
getAnnotations(pageIndex: number): Promise<Annotation[]>;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Get all annotations in the document
|
|
386
|
+
*/
|
|
387
|
+
getAllAnnotations(): Promise<Annotation[]>;
|
|
388
|
+
|
|
389
|
+
// ==========================================================================
|
|
390
|
+
// Search
|
|
391
|
+
// ==========================================================================
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Search for text in the document
|
|
395
|
+
*/
|
|
396
|
+
search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
397
|
+
|
|
398
|
+
// ==========================================================================
|
|
399
|
+
// Conversion
|
|
400
|
+
// ==========================================================================
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Convert document to markdown
|
|
404
|
+
*/
|
|
405
|
+
toMarkdown(options?: MarkdownOptions): Promise<string>;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Convert document to HTML
|
|
409
|
+
*/
|
|
410
|
+
toHtml(options?: HtmlOptions): Promise<string>;
|
|
411
|
+
|
|
412
|
+
// ==========================================================================
|
|
413
|
+
// Resource Management
|
|
414
|
+
// ==========================================================================
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Close the document and release resources
|
|
418
|
+
*/
|
|
419
|
+
close(): Promise<void>;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Check if document is open
|
|
423
|
+
*/
|
|
424
|
+
isOpen(): boolean;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* PdfDocument static methods (factory pattern)
|
|
429
|
+
*/
|
|
430
|
+
export interface PdfDocumentStatic {
|
|
431
|
+
/**
|
|
432
|
+
* Open a PDF document from a file path
|
|
433
|
+
*/
|
|
434
|
+
open(path: string, password?: string): Promise<PdfDocument>;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Open a PDF document from a buffer
|
|
438
|
+
*/
|
|
439
|
+
openBuffer(buffer: Buffer, password?: string): Promise<PdfDocument>;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Create a new empty PDF document
|
|
443
|
+
*/
|
|
444
|
+
create(): Promise<PdfDocument>;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// ============================================================================
|
|
448
|
+
// Export PdfDocument (dynamically loaded from native module)
|
|
449
|
+
// ============================================================================
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Re-export PdfDocument from the main nodejs module
|
|
453
|
+
* This provides the actual implementation with full type safety
|
|
454
|
+
*/
|
|
455
|
+
export { PdfDocument } from '../index.js';
|
|
456
|
+
|
|
457
|
+
export default PdfDocument;
|