@pdfluent/sdk-wasm 1.0.0-beta.10

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/xfa_wasm.d.ts ADDED
@@ -0,0 +1,526 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Chroma subsampling format
6
+ */
7
+ export enum ChromaSampling {
8
+ /**
9
+ * Both vertically and horizontally subsampled.
10
+ */
11
+ Cs420 = 0,
12
+ /**
13
+ * Horizontally subsampled.
14
+ */
15
+ Cs422 = 1,
16
+ /**
17
+ * Not subsampled.
18
+ */
19
+ Cs444 = 2,
20
+ /**
21
+ * Monochrome.
22
+ */
23
+ Cs400 = 3,
24
+ }
25
+
26
+ /**
27
+ * Status of the currently-active license.
28
+ */
29
+ export class LicenseStatus {
30
+ private constructor();
31
+ free(): void;
32
+ [Symbol.dispose](): void;
33
+ /**
34
+ * Whether output is marked via `/Producer` metadata (Trial tier).
35
+ */
36
+ readonly outputIsMarked: boolean;
37
+ /**
38
+ * Source: `"Default" | "EnvVar" | "Explicit"`.
39
+ */
40
+ readonly source: string;
41
+ /**
42
+ * Tier name: `"Trial" | "Developer" | "Team" | "Business" | "Enterprise"`.
43
+ */
44
+ readonly tier: string;
45
+ }
46
+
47
+ /**
48
+ * PDF document handle for analysis and text extraction.
49
+ *
50
+ * Uses `pdf-syntax` for metadata/geometry/signatures/compliance and
51
+ * `pdf-engine` for text extraction so the WASM path matches native decoding.
52
+ */
53
+ export class PdfDoc {
54
+ private constructor();
55
+ free(): void;
56
+ [Symbol.dispose](): void;
57
+ /**
58
+ * Add a free-text (callout-style) annotation at the given page rectangle.
59
+ */
60
+ addFreeText(page_index: number, x: number, y: number, w: number, h: number, contents: string): Uint8Array;
61
+ /**
62
+ * Add a highlight annotation over the given page rectangle.
63
+ * Rectangle in PDF user-space coordinates (origin bottom-left).
64
+ * Optional `color_hex` like `"#ffeb3b"`; default yellow if `None`.
65
+ */
66
+ addHighlight(page_index: number, x: number, y: number, w: number, h: number, color_hex?: string | null): Uint8Array;
67
+ /**
68
+ * Add a sticky-note (text) annotation at the given page position.
69
+ */
70
+ addStickyNote(page_index: number, x: number, y: number, contents: string): Uint8Array;
71
+ /**
72
+ * Apply a diagonal text watermark to every page.
73
+ * `opacity` in 0.0..=1.0. Default rotation 45 deg, default colour gray.
74
+ */
75
+ addTextWatermark(text: string, opacity: number): Uint8Array;
76
+ /**
77
+ * Re-encode all content streams with deflate compression. Removes
78
+ * no-op overhead. Returns the optimised PDF as a `Uint8Array`.
79
+ */
80
+ compress(): Uint8Array;
81
+ /**
82
+ * Convert this PDF to PDF/A-1b, PDF/A-2b, or PDF/A-3b.
83
+ *
84
+ * `level` must be "1b", "2b", or "3b".
85
+ * Returns the converted PDF as a `Uint8Array`.
86
+ */
87
+ convertToPdfa(level: string): Uint8Array;
88
+ /**
89
+ * Delete the listed pages (0-based) from the document.
90
+ */
91
+ deletePages(pages: Uint32Array): Uint8Array;
92
+ /**
93
+ * DSS (Document Security Store) info as JSON, or null if absent.
94
+ */
95
+ dssInfo(): string | undefined;
96
+ /**
97
+ * Extract the listed pages (0-based) into a new document.
98
+ * Used to implement "split" workflows in the browser.
99
+ */
100
+ extractPages(pages: Uint32Array): Uint8Array;
101
+ /**
102
+ * Flatten XFA form fields into static PDF content.
103
+ *
104
+ * Returns the flattened PDF as a `Uint8Array`.
105
+ * Throws if the document has no XFA stream or flattening fails.
106
+ */
107
+ flattenXfa(): Uint8Array;
108
+ /**
109
+ * Parse existing annotations on a page as JSON.
110
+ *
111
+ * Returns a JSON array of annotation objects.
112
+ */
113
+ getAnnotations(page_index: number): string;
114
+ /**
115
+ * Text-run positions for a page.
116
+ *
117
+ * Returns a JSON array of `{text, x, y, width, height, fontSize}`
118
+ * objects in page space with origin at the top-left. Each entry is a
119
+ * contiguous text run emitted by the same PDF interpreter that drives the
120
+ * renderer, which keeps the selection overlay aligned with the canvas.
121
+ *
122
+ * ```js
123
+ * const runs = JSON.parse(doc.getTextPositions(0));
124
+ * // runs[i] = { text: "Hello world", x: 72.0, y: 100.0, width: 96.0, height: 12.0, fontSize: 12.0 }
125
+ * ```
126
+ */
127
+ getTextPositions(page_index: number): string;
128
+ /**
129
+ * Check if the document has any signatures.
130
+ */
131
+ hasSignatures(): boolean;
132
+ /**
133
+ * Merge another PDF document into this one.
134
+ *
135
+ * Returns the merged PDF as a `Uint8Array`.
136
+ */
137
+ merge(other: Uint8Array): Uint8Array;
138
+ /**
139
+ * Document metadata as JSON.
140
+ */
141
+ metadata(): string;
142
+ /**
143
+ * Open a PDF from raw bytes.
144
+ */
145
+ static open(data: Uint8Array): PdfDoc;
146
+ /**
147
+ * Number of pages.
148
+ */
149
+ pageCount(): number;
150
+ /**
151
+ * Get page height in PDF points.
152
+ */
153
+ pageHeight(page_index: number): number;
154
+ /**
155
+ * Get page width in PDF points.
156
+ */
157
+ pageWidth(page_index: number): number;
158
+ /**
159
+ * Permanently remove content within the given page rectangle.
160
+ * Coordinates in PDF user-space (origin bottom-left).
161
+ */
162
+ redactRegion(page_index: number, x: number, y: number, w: number, h: number): Uint8Array;
163
+ /**
164
+ * Search-and-redact: every match of `query` (literal text, case-sensitive)
165
+ * is permanently removed from every page.
166
+ */
167
+ redactSearch(query: string): Uint8Array;
168
+ /**
169
+ * Render a page to RGBA pixels.
170
+ *
171
+ * Returns a Uint8Array with layout: `[width:4LE][height:4LE][RGBA pixels...]`.
172
+ * Use with Canvas ImageData:
173
+ * ```js
174
+ * const raw = doc.renderPage(0, 1.5);
175
+ * const view = new DataView(raw.buffer);
176
+ * const w = view.getUint32(0, true);
177
+ * const h = view.getUint32(4, true);
178
+ * const pixels = raw.slice(8);
179
+ * const imageData = new ImageData(new Uint8ClampedArray(pixels), w, h);
180
+ * ctx.putImageData(imageData, 0, 0);
181
+ * ```
182
+ */
183
+ renderPage(page_index: number, scale: number): Uint8Array;
184
+ /**
185
+ * Render a page directly to an HTML canvas element (wasm32 only).
186
+ *
187
+ * Calls `canvas.getContext("2d")`, sets the canvas dimensions to the
188
+ * rendered pixel size, and calls `putImageData` — no round-trip through
189
+ * a JS Uint8Array. XFA documents are auto-flattened before rendering.
190
+ *
191
+ * ```js
192
+ * const canvas = document.getElementById('viewer');
193
+ * await doc.renderPageToCanvas(canvas, 0, 1.5); // page 0, 108 DPI
194
+ * ```
195
+ */
196
+ renderPageToCanvas(canvas: HTMLCanvasElement, page_index: number, scale: number): void;
197
+ /**
198
+ * Render a page using Canvas2D vector draw calls.
199
+ *
200
+ * Falls back to the raster renderer if the vector device hits an
201
+ * unsupported PDF feature.
202
+ */
203
+ renderPageToCanvasVector(canvas: HTMLCanvasElement, page_index: number, scale: number): void;
204
+ /**
205
+ * Render a thumbnail constrained to a maximum dimension.
206
+ *
207
+ * Same return format as `renderPage`.
208
+ */
209
+ renderThumbnail(page_index: number, max_dimension: number): Uint8Array;
210
+ /**
211
+ * Re-order pages. `new_order` is a permutation of 0..pageCount.
212
+ */
213
+ reorderPages(new_order: Uint32Array): Uint8Array;
214
+ /**
215
+ * Rotate a single page by 90, 180, or 270 degrees (clockwise).
216
+ * `degrees` may be negative; values are normalised modulo 360.
217
+ */
218
+ rotatePage(page_index: number, degrees: number): Uint8Array;
219
+ /**
220
+ * Set a single AcroForm text-field value. Returns the new PDF bytes.
221
+ */
222
+ setFormField(path: string, value: string): Uint8Array;
223
+ /**
224
+ * Bulk-set multiple AcroForm text fields from a JSON object
225
+ * `{"field.path": "value", ...}`. Returns the new PDF bytes.
226
+ */
227
+ setFormFields(fields_json: string): Uint8Array;
228
+ /**
229
+ * Signature info as JSON array.
230
+ */
231
+ signatures(): string;
232
+ /**
233
+ * Extract plain text from a page (0-based index).
234
+ *
235
+ * Returns an empty string if the page index is out of range or text
236
+ * extraction fails.
237
+ */
238
+ text(page_index: number): string;
239
+ /**
240
+ * Validate against a PDF/A level. Returns compliance report as JSON.
241
+ */
242
+ validatePdfA(level: string): string;
243
+ /**
244
+ * Verify all digital signatures in the document.
245
+ *
246
+ * Returns JSON array with verification results per signature.
247
+ */
248
+ verifySignatures(): string;
249
+ }
250
+
251
+ /**
252
+ * Stateful editing handle.
253
+ *
254
+ * Construct with [`PdfDocMut::open`], apply any sequence of mutations
255
+ * (all `&mut self`), and finally call [`PdfDocMut::save`] to get the
256
+ * modified PDF bytes. `save` is non-consuming; you can continue
257
+ * editing after taking a snapshot.
258
+ */
259
+ export class PdfDocMut {
260
+ private constructor();
261
+ free(): void;
262
+ [Symbol.dispose](): void;
263
+ /**
264
+ * Add a free-text annotation at the given page rectangle.
265
+ */
266
+ addFreeText(page_index: number, x: number, y: number, w: number, h: number, contents: string): void;
267
+ /**
268
+ * Add a highlight annotation over the given page rectangle.
269
+ * `color_hex` like `"#ffeb3b"` — defaults to yellow when `None`.
270
+ */
271
+ addHighlight(page_index: number, x: number, y: number, w: number, h: number, color_hex?: string | null): void;
272
+ /**
273
+ * Add a sticky-note annotation at the given page position.
274
+ */
275
+ addStickyNote(page_index: number, x: number, y: number, contents: string): void;
276
+ /**
277
+ * Apply a diagonal text watermark to every page.
278
+ */
279
+ addTextWatermark(text: string, opacity: number): void;
280
+ /**
281
+ * Re-encode content streams with deflate compression.
282
+ */
283
+ compress(): void;
284
+ /**
285
+ * Delete the listed pages (0-based) from the document.
286
+ */
287
+ deletePages(pages: Uint32Array): void;
288
+ /**
289
+ * Extract the listed pages (0-based) into a **new** document and
290
+ * return its bytes. Leaves the current editing session untouched.
291
+ *
292
+ * Use for split-style workflows where the original keeps the full
293
+ * set of pages and a subset is exported.
294
+ */
295
+ extractPages(pages: Uint32Array): Uint8Array;
296
+ /**
297
+ * Open a PDF for editing.
298
+ */
299
+ static open(bytes: Uint8Array): PdfDocMut;
300
+ /**
301
+ * Number of pages in the current document state.
302
+ */
303
+ pageCount(): number;
304
+ /**
305
+ * Permanently remove content within the given page rectangle.
306
+ */
307
+ redactRegion(page_index: number, x: number, y: number, w: number, h: number): void;
308
+ /**
309
+ * Search-and-redact: every literal match of `query` is permanently
310
+ * removed from every page.
311
+ */
312
+ redactSearch(query: string): void;
313
+ /**
314
+ * Re-order pages. `new_order` is a permutation of `0..page_count`.
315
+ */
316
+ reorderPages(new_order: Uint32Array): void;
317
+ /**
318
+ * Rotate a single page by 90/180/270 (or negative). Multiples of 90 only.
319
+ */
320
+ rotatePage(page_index: number, degrees: number): void;
321
+ /**
322
+ * Serialise the current document state to a `Uint8Array`.
323
+ *
324
+ * Non-consuming: subsequent mutations are still possible on the
325
+ * same handle.
326
+ */
327
+ save(): Uint8Array;
328
+ /**
329
+ * Set a single AcroForm text-field value.
330
+ *
331
+ * Note: pdfluent's high-level `PdfFormMut` requires a
332
+ * `pdfluent::PdfDocument`. To stay in-place on this handle, we use
333
+ * the lower-level lopdf walk via the `pdf-forms` engine. For 1.0,
334
+ * this supports flat top-level field hierarchies (no `/Kids`
335
+ * recursion) — same constraint as the Rust core.
336
+ */
337
+ setFormField(path: string, value: string): void;
338
+ /**
339
+ * Bulk-set multiple AcroForm text fields from a JSON object
340
+ * `{"field.path": "value", ...}`.
341
+ */
342
+ setFormFields(fields_json: string): void;
343
+ }
344
+
345
+ /**
346
+ * The main XFA processing engine for WASM.
347
+ *
348
+ * Holds a parsed FormTree and provides methods to extract/import data.
349
+ */
350
+ export class XfaEngine {
351
+ private constructor();
352
+ free(): void;
353
+ [Symbol.dispose](): void;
354
+ /**
355
+ * Export all field values as a JSON string.
356
+ *
357
+ * Returns `{"form1.FieldName": "value", ...}`.
358
+ */
359
+ exportJson(): string;
360
+ /**
361
+ * Export the form schema as a JSON string.
362
+ *
363
+ * Returns metadata about each field (name, type, constraints).
364
+ */
365
+ exportSchema(): string;
366
+ /**
367
+ * Create an XfaEngine from a JSON array of field definitions.
368
+ *
369
+ * Expected format:
370
+ * ```json
371
+ * [
372
+ * {"name": "FieldName", "value": "initial value", "calculate": "optional script"},
373
+ * ...
374
+ * ]
375
+ * ```
376
+ */
377
+ static fromFields(fields_json: string): XfaEngine;
378
+ /**
379
+ * Create an XfaEngine from exported JSON data (e.g. from `exportJson`).
380
+ *
381
+ * Rebuilds the form tree from a flat field map.
382
+ */
383
+ static fromJson(json_str: string): XfaEngine;
384
+ /**
385
+ * Get a single field value by SOM path (e.g., "form1.Name").
386
+ */
387
+ getFieldValue(path: string): string | undefined;
388
+ /**
389
+ * Import field values from a JSON string.
390
+ *
391
+ * Accepts either:
392
+ * - `{"fields": {"form1.Name": "value"}}` (FormData format)
393
+ * - `{"form1.Name": "value"}` (flat format)
394
+ */
395
+ importJson(json_str: string): void;
396
+ /**
397
+ * Get the number of form nodes.
398
+ */
399
+ nodeCount(): number;
400
+ /**
401
+ * Run FormCalc calculate scripts to compute derived field values.
402
+ */
403
+ runCalculations(): void;
404
+ /**
405
+ * Set a single field value by SOM path.
406
+ */
407
+ setFieldValue(path: string, value: string): boolean;
408
+ /**
409
+ * Get engine version string.
410
+ */
411
+ static version(): string;
412
+ }
413
+
414
+ /**
415
+ * Activate the process-global license from a key string.
416
+ *
417
+ * Throws on invalid key or if the process has already been activated to a
418
+ * different tier this session.
419
+ */
420
+ export function activateLicenseKey(key: string): void;
421
+
422
+ /**
423
+ * Return the current license status. Always succeeds; defaults to Trial.
424
+ */
425
+ export function licenseStatus(): LicenseStatus;
426
+
427
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
428
+
429
+ export interface InitOutput {
430
+ readonly memory: WebAssembly.Memory;
431
+ readonly __wbg_licensestatus_free: (a: number, b: number) => void;
432
+ readonly __wbg_pdfdoc_free: (a: number, b: number) => void;
433
+ readonly __wbg_pdfdocmut_free: (a: number, b: number) => void;
434
+ readonly __wbg_xfaengine_free: (a: number, b: number) => void;
435
+ readonly activateLicenseKey: (a: number, b: number, c: number) => void;
436
+ readonly licenseStatus: () => number;
437
+ readonly licensestatus_outputIsMarked: (a: number) => number;
438
+ readonly licensestatus_source: (a: number, b: number) => void;
439
+ readonly licensestatus_tier: (a: number, b: number) => void;
440
+ readonly pdfdoc_addFreeText: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
441
+ readonly pdfdoc_addHighlight: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
442
+ readonly pdfdoc_addStickyNote: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
443
+ readonly pdfdoc_addTextWatermark: (a: number, b: number, c: number, d: number, e: number) => void;
444
+ readonly pdfdoc_compress: (a: number, b: number) => void;
445
+ readonly pdfdoc_convertToPdfa: (a: number, b: number, c: number, d: number) => void;
446
+ readonly pdfdoc_deletePages: (a: number, b: number, c: number, d: number) => void;
447
+ readonly pdfdoc_dssInfo: (a: number, b: number) => void;
448
+ readonly pdfdoc_extractPages: (a: number, b: number, c: number, d: number) => void;
449
+ readonly pdfdoc_flattenXfa: (a: number, b: number) => void;
450
+ readonly pdfdoc_getAnnotations: (a: number, b: number, c: number) => void;
451
+ readonly pdfdoc_getTextPositions: (a: number, b: number, c: number) => void;
452
+ readonly pdfdoc_hasSignatures: (a: number) => number;
453
+ readonly pdfdoc_merge: (a: number, b: number, c: number, d: number) => void;
454
+ readonly pdfdoc_metadata: (a: number, b: number) => void;
455
+ readonly pdfdoc_open: (a: number, b: number, c: number) => void;
456
+ readonly pdfdoc_pageCount: (a: number) => number;
457
+ readonly pdfdoc_pageHeight: (a: number, b: number) => number;
458
+ readonly pdfdoc_pageWidth: (a: number, b: number) => number;
459
+ readonly pdfdoc_redactRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
460
+ readonly pdfdoc_redactSearch: (a: number, b: number, c: number, d: number) => void;
461
+ readonly pdfdoc_renderPage: (a: number, b: number, c: number, d: number) => void;
462
+ readonly pdfdoc_renderPageToCanvas: (a: number, b: number, c: number, d: number, e: number) => void;
463
+ readonly pdfdoc_renderPageToCanvasVector: (a: number, b: number, c: number, d: number, e: number) => void;
464
+ readonly pdfdoc_renderThumbnail: (a: number, b: number, c: number, d: number) => void;
465
+ readonly pdfdoc_reorderPages: (a: number, b: number, c: number, d: number) => void;
466
+ readonly pdfdoc_rotatePage: (a: number, b: number, c: number, d: number) => void;
467
+ readonly pdfdoc_setFormField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
468
+ readonly pdfdoc_setFormFields: (a: number, b: number, c: number, d: number) => void;
469
+ readonly pdfdoc_signatures: (a: number, b: number) => void;
470
+ readonly pdfdoc_text: (a: number, b: number, c: number) => void;
471
+ readonly pdfdoc_validatePdfA: (a: number, b: number, c: number, d: number) => void;
472
+ readonly pdfdoc_verifySignatures: (a: number, b: number) => void;
473
+ readonly pdfdocmut_addFreeText: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
474
+ readonly pdfdocmut_addHighlight: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
475
+ readonly pdfdocmut_addStickyNote: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
476
+ readonly pdfdocmut_addTextWatermark: (a: number, b: number, c: number, d: number, e: number) => void;
477
+ readonly pdfdocmut_compress: (a: number, b: number) => void;
478
+ readonly pdfdocmut_deletePages: (a: number, b: number, c: number, d: number) => void;
479
+ readonly pdfdocmut_extractPages: (a: number, b: number, c: number, d: number) => void;
480
+ readonly pdfdocmut_open: (a: number, b: number, c: number) => void;
481
+ readonly pdfdocmut_pageCount: (a: number) => number;
482
+ readonly pdfdocmut_redactRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
483
+ readonly pdfdocmut_redactSearch: (a: number, b: number, c: number, d: number) => void;
484
+ readonly pdfdocmut_reorderPages: (a: number, b: number, c: number, d: number) => void;
485
+ readonly pdfdocmut_rotatePage: (a: number, b: number, c: number, d: number) => void;
486
+ readonly pdfdocmut_save: (a: number, b: number) => void;
487
+ readonly pdfdocmut_setFormField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
488
+ readonly pdfdocmut_setFormFields: (a: number, b: number, c: number, d: number) => void;
489
+ readonly xfaengine_exportJson: (a: number, b: number) => void;
490
+ readonly xfaengine_exportSchema: (a: number, b: number) => void;
491
+ readonly xfaengine_fromFields: (a: number, b: number, c: number) => void;
492
+ readonly xfaengine_fromJson: (a: number, b: number, c: number) => void;
493
+ readonly xfaengine_getFieldValue: (a: number, b: number, c: number, d: number) => void;
494
+ readonly xfaengine_importJson: (a: number, b: number, c: number, d: number) => void;
495
+ readonly xfaengine_nodeCount: (a: number) => number;
496
+ readonly xfaengine_runCalculations: (a: number, b: number) => void;
497
+ readonly xfaengine_setFieldValue: (a: number, b: number, c: number, d: number, e: number) => number;
498
+ readonly xfaengine_version: (a: number) => void;
499
+ readonly __wbindgen_export: (a: number, b: number) => number;
500
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
501
+ readonly __wbindgen_export3: (a: number) => void;
502
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
503
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
504
+ }
505
+
506
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
507
+
508
+ /**
509
+ * Instantiates the given `module`, which can either be bytes or
510
+ * a precompiled `WebAssembly.Module`.
511
+ *
512
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
513
+ *
514
+ * @returns {InitOutput}
515
+ */
516
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
517
+
518
+ /**
519
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
520
+ * for everything else, calls `WebAssembly.instantiate` directly.
521
+ *
522
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
523
+ *
524
+ * @returns {Promise<InitOutput>}
525
+ */
526
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;