@pdfluent/sdk-wasm 1.0.0-beta.10 → 1.0.0-beta.12
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 +10 -9
- package/package.json +1 -1
- package/xfa_wasm.d.ts +182 -1
- package/xfa_wasm.js +418 -55
- package/xfa_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -4,9 +4,10 @@ WebAssembly distribution of the PDFluent PDF engine. Read, edit, annotate,
|
|
|
4
4
|
redact, sign, and validate PDFs (including XFA) entirely in the browser —
|
|
5
5
|
zero bytes go to a server.
|
|
6
6
|
|
|
7
|
-
Published as `@pdfluent/
|
|
8
|
-
|
|
9
|
-
in-browser PDF editor.
|
|
7
|
+
Published as `@pdfluent/sdk-wasm` on npm. (The crate directory is named
|
|
8
|
+
`xfa-wasm` for historical XFA roots — the published npm package covers the
|
|
9
|
+
full SDK surface needed for an in-browser PDF editor. Previously known as
|
|
10
|
+
`@pdfluent/xfa-wasm`; renamed to `@pdfluent/sdk-wasm`.)
|
|
10
11
|
|
|
11
12
|
## Features
|
|
12
13
|
|
|
@@ -31,10 +32,10 @@ in-browser PDF editor.)
|
|
|
31
32
|
cargo install wasm-pack
|
|
32
33
|
|
|
33
34
|
# Build the WASM package
|
|
34
|
-
wasm-pack build crates
|
|
35
|
+
wasm-pack build crates/xfa-wasm --target web
|
|
35
36
|
|
|
36
37
|
# Without rendering (smaller bundle)
|
|
37
|
-
wasm-pack build crates
|
|
38
|
+
wasm-pack build crates/xfa-wasm --target web -- --no-default-features
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
## Quick Start
|
|
@@ -148,7 +149,7 @@ const data = forms.exportJson();
|
|
|
148
149
|
Build without optional features for a smaller WASM binary:
|
|
149
150
|
|
|
150
151
|
```bash
|
|
151
|
-
wasm-pack build crates
|
|
152
|
+
wasm-pack build crates/xfa-wasm --target web -- --no-default-features
|
|
152
153
|
```
|
|
153
154
|
|
|
154
155
|
## API Reference
|
|
@@ -175,7 +176,7 @@ is marked via `/Producer` metadata in Trial. Activate a license to remove
|
|
|
175
176
|
the mark and unlock paid capabilities.
|
|
176
177
|
|
|
177
178
|
```js
|
|
178
|
-
import init, { activateLicenseKey, licenseStatus } from '@pdfluent/
|
|
179
|
+
import init, { activateLicenseKey, licenseStatus } from '@pdfluent/sdk-wasm';
|
|
179
180
|
|
|
180
181
|
await init();
|
|
181
182
|
activateLicenseKey('tier:enterprise');
|
|
@@ -278,7 +279,7 @@ operations to the same document, **`PdfDocMut` is dramatically faster**:
|
|
|
278
279
|
#### Editor flow with PdfDocMut
|
|
279
280
|
|
|
280
281
|
```js
|
|
281
|
-
import init, { PdfDocMut } from '@pdfluent/
|
|
282
|
+
import init, { PdfDocMut } from '@pdfluent/sdk-wasm';
|
|
282
283
|
|
|
283
284
|
await init();
|
|
284
285
|
const bytes = new Uint8Array(await (await fetch('/document.pdf')).arrayBuffer());
|
|
@@ -304,7 +305,7 @@ are equally fine. They are kept for backward compatibility but the
|
|
|
304
305
|
recommended path for any multi-step edit is `PdfDocMut`.
|
|
305
306
|
|
|
306
307
|
```js
|
|
307
|
-
import init, { PdfDoc } from '@pdfluent/
|
|
308
|
+
import init, { PdfDoc } from '@pdfluent/sdk-wasm';
|
|
308
309
|
await init();
|
|
309
310
|
const doc = PdfDoc.open(bytes);
|
|
310
311
|
const merged = doc.merge(otherBytes); // single op, one-shot
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@pdfluent/sdk-wasm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "PDFluent browser SDK — read, edit, annotate, redact, sign, and validate PDFs (including XFA) entirely client-side via WASM.",
|
|
5
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.12",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"files": [
|
|
8
8
|
"xfa_wasm_bg.wasm",
|
package/xfa_wasm.d.ts
CHANGED
|
@@ -49,6 +49,33 @@ export class LicenseStatus {
|
|
|
49
49
|
*
|
|
50
50
|
* Uses `pdf-syntax` for metadata/geometry/signatures/compliance and
|
|
51
51
|
* `pdf-engine` for text extraction so the WASM path matches native decoding.
|
|
52
|
+
*
|
|
53
|
+
* # Memory lifecycle
|
|
54
|
+
*
|
|
55
|
+
* `PdfDoc` holds native WASM memory. Call [`PdfDoc.free()`] when done,
|
|
56
|
+
* or use the `using` keyword (TypeScript 5.2+):
|
|
57
|
+
*
|
|
58
|
+
* ```js
|
|
59
|
+
* using doc = PdfDoc.open(bytes);
|
|
60
|
+
* // doc.free() is called automatically at end of block
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* After `free()`, all method calls throw. Do not hold references across `free()`.
|
|
64
|
+
*
|
|
65
|
+
* # Errors
|
|
66
|
+
*
|
|
67
|
+
* All fallible methods throw a `PdfluentError` — a standard `Error` subclass with
|
|
68
|
+
* these properties:
|
|
69
|
+
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
70
|
+
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
71
|
+
* - `message`: human-readable description (stable for backwards compatibility).
|
|
72
|
+
* - `operation`: short identifier of the API call that failed.
|
|
73
|
+
* - `help`: optional actionable hint (may be empty string).
|
|
74
|
+
* - `docsUrl`: deep-link into `https://pdfluent.com/errors/<code>`.
|
|
75
|
+
* - `legacyCode`: the original SCREAMING_SNAKE_CASE identifier from the
|
|
76
|
+
* pre-1.0 WASM binding, preserved so older user code keeps working.
|
|
77
|
+
*
|
|
78
|
+
* JavaScript callers can use `error instanceof PdfluentError` to discriminate.
|
|
52
79
|
*/
|
|
53
80
|
export class PdfDoc {
|
|
54
81
|
private constructor();
|
|
@@ -121,8 +148,30 @@ export class PdfDoc {
|
|
|
121
148
|
*
|
|
122
149
|
* ```js
|
|
123
150
|
* const runs = JSON.parse(doc.getTextPositions(0));
|
|
124
|
-
* // runs[i] = {
|
|
151
|
+
* // runs[i] = {
|
|
152
|
+
* // text: "Hello world",
|
|
153
|
+
* // x: 72.0, y: 100.0, width: 96.0, height: 12.0, fontSize: 12.0,
|
|
154
|
+
* // fontName: "Helvetica-Bold", // G1: stable presence; null when unknown
|
|
155
|
+
* // isBold: true, isItalic: false,
|
|
156
|
+
* // color: [0, 0, 0, 255], // G1: omitted when unknown
|
|
157
|
+
* // widthSource: "Metric", // G2: "Metric" | "Estimate"
|
|
158
|
+
* // charBounds: [[72,100,80,112], …] // G2: per-glyph bounds (omitted when empty)
|
|
159
|
+
* // }
|
|
125
160
|
* ```
|
|
161
|
+
*
|
|
162
|
+
* `fontName` is always present in the JSON: a known PostScript
|
|
163
|
+
* name (embedded font, or resolved standard-14 fallback for
|
|
164
|
+
* non-embedded Type1) emits a string; an unknown name (Type3
|
|
165
|
+
* glyphs, embedded Type1 without a standard-font fallback)
|
|
166
|
+
* emits `null`. This stable presence matches the editor
|
|
167
|
+
* contract; the editor can call `run.fontName ?? "Unknown"`
|
|
168
|
+
* or do `'fontName' in run` tests without conditional logic.
|
|
169
|
+
*
|
|
170
|
+
* `color` is still omitted from the JSON when the source paint
|
|
171
|
+
* is a pattern/shading or the color space could not be
|
|
172
|
+
* resolved. `isBold`/`isItalic` are always present so editor
|
|
173
|
+
* toolbars can render unconditionally. `widthSource` is always
|
|
174
|
+
* present; `charBounds` is omitted only when the span is empty.
|
|
126
175
|
*/
|
|
127
176
|
getTextPositions(page_index: number): string;
|
|
128
177
|
/**
|
|
@@ -277,6 +326,16 @@ export class PdfDocMut {
|
|
|
277
326
|
* Apply a diagonal text watermark to every page.
|
|
278
327
|
*/
|
|
279
328
|
addTextWatermark(text: string, opacity: number): void;
|
|
329
|
+
/**
|
|
330
|
+
* Convenience: open bytes, format a single run, return new bytes.
|
|
331
|
+
*
|
|
332
|
+
* One-shot equivalent of `open → formatTextSpan → save`.
|
|
333
|
+
*/
|
|
334
|
+
static applyTextFormat(data: Uint8Array, page_num: number, run_index: number, font_size?: number | null, color?: string | null): Uint8Array;
|
|
335
|
+
/**
|
|
336
|
+
* Convenience: open bytes, apply style, return new bytes.
|
|
337
|
+
*/
|
|
338
|
+
static applyTextRunStyle(data: Uint8Array, page_num: number, run_index: number, bold?: boolean | null, italic?: boolean | null): Uint8Array;
|
|
280
339
|
/**
|
|
281
340
|
* Re-encode content streams with deflate compression.
|
|
282
341
|
*/
|
|
@@ -293,6 +352,26 @@ export class PdfDocMut {
|
|
|
293
352
|
* set of pages and a subset is exported.
|
|
294
353
|
*/
|
|
295
354
|
extractPages(pages: Uint32Array): Uint8Array;
|
|
355
|
+
/**
|
|
356
|
+
* Format a single text run on `page_num` (1-based) by changing its font
|
|
357
|
+
* size and/or fill color. The mutation is scoped so other runs on the
|
|
358
|
+
* page are unaffected (q…Q isolation injected as needed).
|
|
359
|
+
*
|
|
360
|
+
* Parameters:
|
|
361
|
+
* - `page_num`: 1-based page index.
|
|
362
|
+
* - `run_index`: 0-based index into `extract_page_text_runs(page_num)`.
|
|
363
|
+
* - `font_size`: optional new font size (points). Pass `None` to keep.
|
|
364
|
+
* - `color`: optional hex color string (e.g. `"#FF0000"`); pass `None`
|
|
365
|
+
* to keep the existing fill color.
|
|
366
|
+
*
|
|
367
|
+
* Returns a JSON string with the canonical `FormatResult` shape:
|
|
368
|
+
* `{ "formatted": bool, "bytesChanged": usize, "isolationStrategy": str,
|
|
369
|
+
* "originalSize": f32?, "originalColor": [f32; 3]?, "code": str? }`.
|
|
370
|
+
*
|
|
371
|
+
* Passing both `font_size = None` and `color = None` is a no-op:
|
|
372
|
+
* `formatted = false`, `bytesChanged = 0`, no error.
|
|
373
|
+
*/
|
|
374
|
+
formatTextSpan(page_num: number, run_index: number, font_size?: number | null, color?: string | null): string;
|
|
296
375
|
/**
|
|
297
376
|
* Open a PDF for editing.
|
|
298
377
|
*/
|
|
@@ -314,6 +393,50 @@ export class PdfDocMut {
|
|
|
314
393
|
* Re-order pages. `new_order` is a permutation of `0..page_count`.
|
|
315
394
|
*/
|
|
316
395
|
reorderPages(new_order: Uint32Array): void;
|
|
396
|
+
/**
|
|
397
|
+
* G3 — Replace a text span on a page.
|
|
398
|
+
*
|
|
399
|
+
* The editor passes the **exact** text it extracted from
|
|
400
|
+
* `getTextPositions()` as `original_text`, and the desired
|
|
401
|
+
* replacement as `replacement_text`. The replacement is
|
|
402
|
+
* re-encoded into the same font used by the matched span
|
|
403
|
+
* (subset-font fallback applies when the original font cannot
|
|
404
|
+
* encode the replacement — see
|
|
405
|
+
* `pdf-manip::text_replace::replace_text`).
|
|
406
|
+
*
|
|
407
|
+
* `page_num` is **1-based** to match the rest of the
|
|
408
|
+
* `pdf-manip` surface (and the existing `formatTextSpan` /
|
|
409
|
+
* `setTextRunStyle` methods on this handle).
|
|
410
|
+
*
|
|
411
|
+
* Returns a JSON string with the following shape:
|
|
412
|
+
*
|
|
413
|
+
* ```jsonc
|
|
414
|
+
* {
|
|
415
|
+
* "replaced": false,
|
|
416
|
+
* "code": "NO_MATCH", // only when replaced=false
|
|
417
|
+
* "reason": "originalText …", // only when replaced=false
|
|
418
|
+
* "byteLengthBefore": 12345, // only when replaced=true
|
|
419
|
+
* "byteLengthAfter": 12378 // only when replaced=true
|
|
420
|
+
* }
|
|
421
|
+
* ```
|
|
422
|
+
*
|
|
423
|
+
* Typed unsupported codes (all set `replaced=false`):
|
|
424
|
+
*
|
|
425
|
+
* - `"NO_MATCH"` — `original_text` not found on the page.
|
|
426
|
+
* - `"ENCODING_UNSUPPORTED"` — replacement contains characters
|
|
427
|
+
* the matched font cannot encode and no fallback font is
|
|
428
|
+
* available.
|
|
429
|
+
* - `"REPLACE_FAILED"` — anything else (lopdf I/O,
|
|
430
|
+
* serialisation, FontMap construction, …). `reason` carries
|
|
431
|
+
* the lower-level error message.
|
|
432
|
+
*
|
|
433
|
+
* Layout is preserved within the existing run: same font,
|
|
434
|
+
* same baseline, same `Tj`/`TJ` operator boundaries. Cross-run
|
|
435
|
+
* matches (where the search text is split across multiple
|
|
436
|
+
* content-stream operators) are handled by the underlying
|
|
437
|
+
* `replace_text` cross-run path.
|
|
438
|
+
*/
|
|
439
|
+
replaceTextSpan(page_num: number, original_text: string, replacement_text: string): string;
|
|
317
440
|
/**
|
|
318
441
|
* Rotate a single page by 90/180/270 (or negative). Multiples of 90 only.
|
|
319
442
|
*/
|
|
@@ -340,12 +463,43 @@ export class PdfDocMut {
|
|
|
340
463
|
* `{"field.path": "value", ...}`.
|
|
341
464
|
*/
|
|
342
465
|
setFormFields(fields_json: string): void;
|
|
466
|
+
/**
|
|
467
|
+
* Apply bold/italic style to a text run on `page_num` (1-based).
|
|
468
|
+
*/
|
|
469
|
+
setTextRunStyle(page_num: number, runs_json: string, run_index: number, bold?: boolean | null, italic?: boolean | null): string;
|
|
343
470
|
}
|
|
344
471
|
|
|
345
472
|
/**
|
|
346
473
|
* The main XFA processing engine for WASM.
|
|
347
474
|
*
|
|
348
475
|
* Holds a parsed FormTree and provides methods to extract/import data.
|
|
476
|
+
*
|
|
477
|
+
* # Memory lifecycle
|
|
478
|
+
*
|
|
479
|
+
* `XfaEngine` holds native WASM memory. Call [`XfaEngine.free()`] when done,
|
|
480
|
+
* or use the `using` keyword (TypeScript 5.2+, TC39 Explicit Resource Management):
|
|
481
|
+
*
|
|
482
|
+
* ```js
|
|
483
|
+
* using engine = XfaEngine.fromFields(fields);
|
|
484
|
+
* // engine.free() is called automatically at end of block
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
487
|
+
* After `free()`, all method calls throw. Do not keep references across blocks.
|
|
488
|
+
*
|
|
489
|
+
* # Errors
|
|
490
|
+
*
|
|
491
|
+
* All fallible methods throw a `PdfluentError` — a standard `Error` subclass with
|
|
492
|
+
* these properties:
|
|
493
|
+
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
494
|
+
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
495
|
+
* - `message`: human-readable description (stable for backwards compatibility).
|
|
496
|
+
* - `operation`: short identifier of the API call that failed.
|
|
497
|
+
* - `help`: optional actionable hint (may be empty string).
|
|
498
|
+
* - `docsUrl`: deep-link into `https://pdfluent.com/errors/<code>`.
|
|
499
|
+
* - `legacyCode`: the original SCREAMING_SNAKE_CASE identifier from the
|
|
500
|
+
* pre-1.0 WASM binding, preserved so older user code keeps working.
|
|
501
|
+
*
|
|
502
|
+
* JavaScript callers can use `error instanceof PdfluentError` to discriminate.
|
|
349
503
|
*/
|
|
350
504
|
export class XfaEngine {
|
|
351
505
|
private constructor();
|
|
@@ -419,6 +573,27 @@ export class XfaEngine {
|
|
|
419
573
|
*/
|
|
420
574
|
export function activateLicenseKey(key: string): void;
|
|
421
575
|
|
|
576
|
+
/**
|
|
577
|
+
* Flatten an XFA (XML Forms Architecture) PDF into a static, viewer-agnostic
|
|
578
|
+
* PDF, entirely in the browser.
|
|
579
|
+
*
|
|
580
|
+
* `data` is the raw PDF bytes (a dynamic or static XFA form). `password` is an
|
|
581
|
+
* optional user password for XFA PDFs protected with PDF user-password
|
|
582
|
+
* encryption; it is ignored for unencrypted input. A wrong or missing password
|
|
583
|
+
* on an encrypted document throws an error whose message starts
|
|
584
|
+
* `E-XFA-ENCRYPTED` and never returns plaintext; a password on an unencrypted
|
|
585
|
+
* PDF is ignored. This does not crack, remove, or bypass owner-password
|
|
586
|
+
* permissions.
|
|
587
|
+
*
|
|
588
|
+
* ```js
|
|
589
|
+
* import init, { flattenXfa } from "@pdfluent/sdk-wasm";
|
|
590
|
+
* await init();
|
|
591
|
+
* const flat = flattenXfa(new Uint8Array(buf)); // unencrypted
|
|
592
|
+
* const flatEnc = flattenXfa(new Uint8Array(buf), "secret"); // encrypted
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
export function flattenXfa(data: Uint8Array, password?: string | null): Uint8Array;
|
|
596
|
+
|
|
422
597
|
/**
|
|
423
598
|
* Return the current license status. Always succeeds; defaults to Trial.
|
|
424
599
|
*/
|
|
@@ -433,6 +608,7 @@ export interface InitOutput {
|
|
|
433
608
|
readonly __wbg_pdfdocmut_free: (a: number, b: number) => void;
|
|
434
609
|
readonly __wbg_xfaengine_free: (a: number, b: number) => void;
|
|
435
610
|
readonly activateLicenseKey: (a: number, b: number, c: number) => void;
|
|
611
|
+
readonly flattenXfa: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
436
612
|
readonly licenseStatus: () => number;
|
|
437
613
|
readonly licensestatus_outputIsMarked: (a: number) => number;
|
|
438
614
|
readonly licensestatus_source: (a: number, b: number) => void;
|
|
@@ -474,18 +650,23 @@ export interface InitOutput {
|
|
|
474
650
|
readonly pdfdocmut_addHighlight: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
475
651
|
readonly pdfdocmut_addStickyNote: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
476
652
|
readonly pdfdocmut_addTextWatermark: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
653
|
+
readonly pdfdocmut_applyTextFormat: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
654
|
+
readonly pdfdocmut_applyTextRunStyle: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
477
655
|
readonly pdfdocmut_compress: (a: number, b: number) => void;
|
|
478
656
|
readonly pdfdocmut_deletePages: (a: number, b: number, c: number, d: number) => void;
|
|
479
657
|
readonly pdfdocmut_extractPages: (a: number, b: number, c: number, d: number) => void;
|
|
658
|
+
readonly pdfdocmut_formatTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
480
659
|
readonly pdfdocmut_open: (a: number, b: number, c: number) => void;
|
|
481
660
|
readonly pdfdocmut_pageCount: (a: number) => number;
|
|
482
661
|
readonly pdfdocmut_redactRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
483
662
|
readonly pdfdocmut_redactSearch: (a: number, b: number, c: number, d: number) => void;
|
|
484
663
|
readonly pdfdocmut_reorderPages: (a: number, b: number, c: number, d: number) => void;
|
|
664
|
+
readonly pdfdocmut_replaceTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
485
665
|
readonly pdfdocmut_rotatePage: (a: number, b: number, c: number, d: number) => void;
|
|
486
666
|
readonly pdfdocmut_save: (a: number, b: number) => void;
|
|
487
667
|
readonly pdfdocmut_setFormField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
488
668
|
readonly pdfdocmut_setFormFields: (a: number, b: number, c: number, d: number) => void;
|
|
669
|
+
readonly pdfdocmut_setTextRunStyle: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
489
670
|
readonly xfaengine_exportJson: (a: number, b: number) => void;
|
|
490
671
|
readonly xfaengine_exportSchema: (a: number, b: number) => void;
|
|
491
672
|
readonly xfaengine_fromFields: (a: number, b: number, c: number) => void;
|
package/xfa_wasm.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* @ts-self-types="./xfa_wasm.d.ts" */
|
|
2
|
+
import { __pdfluent_error_ctor } from './snippets/xfa-wasm-312742e1abcfad9e/inline0.js';
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Chroma subsampling format
|
|
@@ -28,7 +30,6 @@ export const ChromaSampling = Object.freeze({
|
|
|
28
30
|
*/
|
|
29
31
|
export class LicenseStatus {
|
|
30
32
|
static __wrap(ptr) {
|
|
31
|
-
ptr = ptr >>> 0;
|
|
32
33
|
const obj = Object.create(LicenseStatus.prototype);
|
|
33
34
|
obj.__wbg_ptr = ptr;
|
|
34
35
|
LicenseStatusFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
@@ -100,10 +101,36 @@ if (Symbol.dispose) LicenseStatus.prototype[Symbol.dispose] = LicenseStatus.prot
|
|
|
100
101
|
*
|
|
101
102
|
* Uses `pdf-syntax` for metadata/geometry/signatures/compliance and
|
|
102
103
|
* `pdf-engine` for text extraction so the WASM path matches native decoding.
|
|
104
|
+
*
|
|
105
|
+
* # Memory lifecycle
|
|
106
|
+
*
|
|
107
|
+
* `PdfDoc` holds native WASM memory. Call [`PdfDoc.free()`] when done,
|
|
108
|
+
* or use the `using` keyword (TypeScript 5.2+):
|
|
109
|
+
*
|
|
110
|
+
* ```js
|
|
111
|
+
* using doc = PdfDoc.open(bytes);
|
|
112
|
+
* // doc.free() is called automatically at end of block
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* After `free()`, all method calls throw. Do not hold references across `free()`.
|
|
116
|
+
*
|
|
117
|
+
* # Errors
|
|
118
|
+
*
|
|
119
|
+
* All fallible methods throw a `PdfluentError` — a standard `Error` subclass with
|
|
120
|
+
* these properties:
|
|
121
|
+
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
122
|
+
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
123
|
+
* - `message`: human-readable description (stable for backwards compatibility).
|
|
124
|
+
* - `operation`: short identifier of the API call that failed.
|
|
125
|
+
* - `help`: optional actionable hint (may be empty string).
|
|
126
|
+
* - `docsUrl`: deep-link into `https://pdfluent.com/errors/<code>`.
|
|
127
|
+
* - `legacyCode`: the original SCREAMING_SNAKE_CASE identifier from the
|
|
128
|
+
* pre-1.0 WASM binding, preserved so older user code keeps working.
|
|
129
|
+
*
|
|
130
|
+
* JavaScript callers can use `error instanceof PdfluentError` to discriminate.
|
|
103
131
|
*/
|
|
104
132
|
export class PdfDoc {
|
|
105
133
|
static __wrap(ptr) {
|
|
106
|
-
ptr = ptr >>> 0;
|
|
107
134
|
const obj = Object.create(PdfDoc.prototype);
|
|
108
135
|
obj.__wbg_ptr = ptr;
|
|
109
136
|
PdfDocFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
@@ -424,8 +451,30 @@ export class PdfDoc {
|
|
|
424
451
|
*
|
|
425
452
|
* ```js
|
|
426
453
|
* const runs = JSON.parse(doc.getTextPositions(0));
|
|
427
|
-
* // runs[i] = {
|
|
454
|
+
* // runs[i] = {
|
|
455
|
+
* // text: "Hello world",
|
|
456
|
+
* // x: 72.0, y: 100.0, width: 96.0, height: 12.0, fontSize: 12.0,
|
|
457
|
+
* // fontName: "Helvetica-Bold", // G1: stable presence; null when unknown
|
|
458
|
+
* // isBold: true, isItalic: false,
|
|
459
|
+
* // color: [0, 0, 0, 255], // G1: omitted when unknown
|
|
460
|
+
* // widthSource: "Metric", // G2: "Metric" | "Estimate"
|
|
461
|
+
* // charBounds: [[72,100,80,112], …] // G2: per-glyph bounds (omitted when empty)
|
|
462
|
+
* // }
|
|
428
463
|
* ```
|
|
464
|
+
*
|
|
465
|
+
* `fontName` is always present in the JSON: a known PostScript
|
|
466
|
+
* name (embedded font, or resolved standard-14 fallback for
|
|
467
|
+
* non-embedded Type1) emits a string; an unknown name (Type3
|
|
468
|
+
* glyphs, embedded Type1 without a standard-font fallback)
|
|
469
|
+
* emits `null`. This stable presence matches the editor
|
|
470
|
+
* contract; the editor can call `run.fontName ?? "Unknown"`
|
|
471
|
+
* or do `'fontName' in run` tests without conditional logic.
|
|
472
|
+
*
|
|
473
|
+
* `color` is still omitted from the JSON when the source paint
|
|
474
|
+
* is a pattern/shading or the color space could not be
|
|
475
|
+
* resolved. `isBold`/`isItalic` are always present so editor
|
|
476
|
+
* toolbars can render unconditionally. `widthSource` is always
|
|
477
|
+
* present; `charBounds` is omitted only when the span is empty.
|
|
429
478
|
* @param {number} page_index
|
|
430
479
|
* @returns {string}
|
|
431
480
|
*/
|
|
@@ -938,7 +987,6 @@ if (Symbol.dispose) PdfDoc.prototype[Symbol.dispose] = PdfDoc.prototype.free;
|
|
|
938
987
|
*/
|
|
939
988
|
export class PdfDocMut {
|
|
940
989
|
static __wrap(ptr) {
|
|
941
|
-
ptr = ptr >>> 0;
|
|
942
990
|
const obj = Object.create(PdfDocMut.prototype);
|
|
943
991
|
obj.__wbg_ptr = ptr;
|
|
944
992
|
PdfDocMutFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
@@ -1045,6 +1093,68 @@ export class PdfDocMut {
|
|
|
1045
1093
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1046
1094
|
}
|
|
1047
1095
|
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Convenience: open bytes, format a single run, return new bytes.
|
|
1098
|
+
*
|
|
1099
|
+
* One-shot equivalent of `open → formatTextSpan → save`.
|
|
1100
|
+
* @param {Uint8Array} data
|
|
1101
|
+
* @param {number} page_num
|
|
1102
|
+
* @param {number} run_index
|
|
1103
|
+
* @param {number | null} [font_size]
|
|
1104
|
+
* @param {string | null} [color]
|
|
1105
|
+
* @returns {Uint8Array}
|
|
1106
|
+
*/
|
|
1107
|
+
static applyTextFormat(data, page_num, run_index, font_size, color) {
|
|
1108
|
+
try {
|
|
1109
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1110
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
|
|
1111
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1112
|
+
var ptr1 = isLikeNone(color) ? 0 : passStringToWasm0(color, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1113
|
+
var len1 = WASM_VECTOR_LEN;
|
|
1114
|
+
wasm.pdfdocmut_applyTextFormat(retptr, ptr0, len0, page_num, run_index, isLikeNone(font_size) ? Number.MAX_SAFE_INTEGER : Math.fround(font_size), ptr1, len1);
|
|
1115
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1116
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1117
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1118
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1119
|
+
if (r3) {
|
|
1120
|
+
throw takeObject(r2);
|
|
1121
|
+
}
|
|
1122
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
1123
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
1124
|
+
return v3;
|
|
1125
|
+
} finally {
|
|
1126
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Convenience: open bytes, apply style, return new bytes.
|
|
1131
|
+
* @param {Uint8Array} data
|
|
1132
|
+
* @param {number} page_num
|
|
1133
|
+
* @param {number} run_index
|
|
1134
|
+
* @param {boolean | null} [bold]
|
|
1135
|
+
* @param {boolean | null} [italic]
|
|
1136
|
+
* @returns {Uint8Array}
|
|
1137
|
+
*/
|
|
1138
|
+
static applyTextRunStyle(data, page_num, run_index, bold, italic) {
|
|
1139
|
+
try {
|
|
1140
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1141
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
|
|
1142
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1143
|
+
wasm.pdfdocmut_applyTextRunStyle(retptr, ptr0, len0, page_num, run_index, isLikeNone(bold) ? 0xFFFFFF : bold ? 1 : 0, isLikeNone(italic) ? 0xFFFFFF : italic ? 1 : 0);
|
|
1144
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1145
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1146
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1147
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1148
|
+
if (r3) {
|
|
1149
|
+
throw takeObject(r2);
|
|
1150
|
+
}
|
|
1151
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
1152
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
1153
|
+
return v2;
|
|
1154
|
+
} finally {
|
|
1155
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1048
1158
|
/**
|
|
1049
1159
|
* Re-encode content streams with deflate compression.
|
|
1050
1160
|
*/
|
|
@@ -1109,6 +1219,56 @@ export class PdfDocMut {
|
|
|
1109
1219
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1110
1220
|
}
|
|
1111
1221
|
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Format a single text run on `page_num` (1-based) by changing its font
|
|
1224
|
+
* size and/or fill color. The mutation is scoped so other runs on the
|
|
1225
|
+
* page are unaffected (q…Q isolation injected as needed).
|
|
1226
|
+
*
|
|
1227
|
+
* Parameters:
|
|
1228
|
+
* - `page_num`: 1-based page index.
|
|
1229
|
+
* - `run_index`: 0-based index into `extract_page_text_runs(page_num)`.
|
|
1230
|
+
* - `font_size`: optional new font size (points). Pass `None` to keep.
|
|
1231
|
+
* - `color`: optional hex color string (e.g. `"#FF0000"`); pass `None`
|
|
1232
|
+
* to keep the existing fill color.
|
|
1233
|
+
*
|
|
1234
|
+
* Returns a JSON string with the canonical `FormatResult` shape:
|
|
1235
|
+
* `{ "formatted": bool, "bytesChanged": usize, "isolationStrategy": str,
|
|
1236
|
+
* "originalSize": f32?, "originalColor": [f32; 3]?, "code": str? }`.
|
|
1237
|
+
*
|
|
1238
|
+
* Passing both `font_size = None` and `color = None` is a no-op:
|
|
1239
|
+
* `formatted = false`, `bytesChanged = 0`, no error.
|
|
1240
|
+
* @param {number} page_num
|
|
1241
|
+
* @param {number} run_index
|
|
1242
|
+
* @param {number | null} [font_size]
|
|
1243
|
+
* @param {string | null} [color]
|
|
1244
|
+
* @returns {string}
|
|
1245
|
+
*/
|
|
1246
|
+
formatTextSpan(page_num, run_index, font_size, color) {
|
|
1247
|
+
let deferred3_0;
|
|
1248
|
+
let deferred3_1;
|
|
1249
|
+
try {
|
|
1250
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1251
|
+
var ptr0 = isLikeNone(color) ? 0 : passStringToWasm0(color, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1252
|
+
var len0 = WASM_VECTOR_LEN;
|
|
1253
|
+
wasm.pdfdocmut_formatTextSpan(retptr, this.__wbg_ptr, page_num, run_index, isLikeNone(font_size) ? Number.MAX_SAFE_INTEGER : Math.fround(font_size), ptr0, len0);
|
|
1254
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1255
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1256
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1257
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1258
|
+
var ptr2 = r0;
|
|
1259
|
+
var len2 = r1;
|
|
1260
|
+
if (r3) {
|
|
1261
|
+
ptr2 = 0; len2 = 0;
|
|
1262
|
+
throw takeObject(r2);
|
|
1263
|
+
}
|
|
1264
|
+
deferred3_0 = ptr2;
|
|
1265
|
+
deferred3_1 = len2;
|
|
1266
|
+
return getStringFromWasm0(ptr2, len2);
|
|
1267
|
+
} finally {
|
|
1268
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1269
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1112
1272
|
/**
|
|
1113
1273
|
* Open a PDF for editing.
|
|
1114
1274
|
* @param {Uint8Array} bytes
|
|
@@ -1199,6 +1359,81 @@ export class PdfDocMut {
|
|
|
1199
1359
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1200
1360
|
}
|
|
1201
1361
|
}
|
|
1362
|
+
/**
|
|
1363
|
+
* G3 — Replace a text span on a page.
|
|
1364
|
+
*
|
|
1365
|
+
* The editor passes the **exact** text it extracted from
|
|
1366
|
+
* `getTextPositions()` as `original_text`, and the desired
|
|
1367
|
+
* replacement as `replacement_text`. The replacement is
|
|
1368
|
+
* re-encoded into the same font used by the matched span
|
|
1369
|
+
* (subset-font fallback applies when the original font cannot
|
|
1370
|
+
* encode the replacement — see
|
|
1371
|
+
* `pdf-manip::text_replace::replace_text`).
|
|
1372
|
+
*
|
|
1373
|
+
* `page_num` is **1-based** to match the rest of the
|
|
1374
|
+
* `pdf-manip` surface (and the existing `formatTextSpan` /
|
|
1375
|
+
* `setTextRunStyle` methods on this handle).
|
|
1376
|
+
*
|
|
1377
|
+
* Returns a JSON string with the following shape:
|
|
1378
|
+
*
|
|
1379
|
+
* ```jsonc
|
|
1380
|
+
* {
|
|
1381
|
+
* "replaced": false,
|
|
1382
|
+
* "code": "NO_MATCH", // only when replaced=false
|
|
1383
|
+
* "reason": "originalText …", // only when replaced=false
|
|
1384
|
+
* "byteLengthBefore": 12345, // only when replaced=true
|
|
1385
|
+
* "byteLengthAfter": 12378 // only when replaced=true
|
|
1386
|
+
* }
|
|
1387
|
+
* ```
|
|
1388
|
+
*
|
|
1389
|
+
* Typed unsupported codes (all set `replaced=false`):
|
|
1390
|
+
*
|
|
1391
|
+
* - `"NO_MATCH"` — `original_text` not found on the page.
|
|
1392
|
+
* - `"ENCODING_UNSUPPORTED"` — replacement contains characters
|
|
1393
|
+
* the matched font cannot encode and no fallback font is
|
|
1394
|
+
* available.
|
|
1395
|
+
* - `"REPLACE_FAILED"` — anything else (lopdf I/O,
|
|
1396
|
+
* serialisation, FontMap construction, …). `reason` carries
|
|
1397
|
+
* the lower-level error message.
|
|
1398
|
+
*
|
|
1399
|
+
* Layout is preserved within the existing run: same font,
|
|
1400
|
+
* same baseline, same `Tj`/`TJ` operator boundaries. Cross-run
|
|
1401
|
+
* matches (where the search text is split across multiple
|
|
1402
|
+
* content-stream operators) are handled by the underlying
|
|
1403
|
+
* `replace_text` cross-run path.
|
|
1404
|
+
* @param {number} page_num
|
|
1405
|
+
* @param {string} original_text
|
|
1406
|
+
* @param {string} replacement_text
|
|
1407
|
+
* @returns {string}
|
|
1408
|
+
*/
|
|
1409
|
+
replaceTextSpan(page_num, original_text, replacement_text) {
|
|
1410
|
+
let deferred4_0;
|
|
1411
|
+
let deferred4_1;
|
|
1412
|
+
try {
|
|
1413
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1414
|
+
const ptr0 = passStringToWasm0(original_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1415
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1416
|
+
const ptr1 = passStringToWasm0(replacement_text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1417
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1418
|
+
wasm.pdfdocmut_replaceTextSpan(retptr, this.__wbg_ptr, page_num, ptr0, len0, ptr1, len1);
|
|
1419
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1420
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1421
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1422
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1423
|
+
var ptr3 = r0;
|
|
1424
|
+
var len3 = r1;
|
|
1425
|
+
if (r3) {
|
|
1426
|
+
ptr3 = 0; len3 = 0;
|
|
1427
|
+
throw takeObject(r2);
|
|
1428
|
+
}
|
|
1429
|
+
deferred4_0 = ptr3;
|
|
1430
|
+
deferred4_1 = len3;
|
|
1431
|
+
return getStringFromWasm0(ptr3, len3);
|
|
1432
|
+
} finally {
|
|
1433
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1434
|
+
wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1202
1437
|
/**
|
|
1203
1438
|
* Rotate a single page by 90/180/270 (or negative). Multiples of 90 only.
|
|
1204
1439
|
* @param {number} page_index
|
|
@@ -1290,6 +1525,41 @@ export class PdfDocMut {
|
|
|
1290
1525
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1291
1526
|
}
|
|
1292
1527
|
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Apply bold/italic style to a text run on `page_num` (1-based).
|
|
1530
|
+
* @param {number} page_num
|
|
1531
|
+
* @param {string} runs_json
|
|
1532
|
+
* @param {number} run_index
|
|
1533
|
+
* @param {boolean | null} [bold]
|
|
1534
|
+
* @param {boolean | null} [italic]
|
|
1535
|
+
* @returns {string}
|
|
1536
|
+
*/
|
|
1537
|
+
setTextRunStyle(page_num, runs_json, run_index, bold, italic) {
|
|
1538
|
+
let deferred3_0;
|
|
1539
|
+
let deferred3_1;
|
|
1540
|
+
try {
|
|
1541
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1542
|
+
const ptr0 = passStringToWasm0(runs_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1543
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1544
|
+
wasm.pdfdocmut_setTextRunStyle(retptr, this.__wbg_ptr, page_num, ptr0, len0, run_index, isLikeNone(bold) ? 0xFFFFFF : bold ? 1 : 0, isLikeNone(italic) ? 0xFFFFFF : italic ? 1 : 0);
|
|
1545
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1546
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1547
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1548
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1549
|
+
var ptr2 = r0;
|
|
1550
|
+
var len2 = r1;
|
|
1551
|
+
if (r3) {
|
|
1552
|
+
ptr2 = 0; len2 = 0;
|
|
1553
|
+
throw takeObject(r2);
|
|
1554
|
+
}
|
|
1555
|
+
deferred3_0 = ptr2;
|
|
1556
|
+
deferred3_1 = len2;
|
|
1557
|
+
return getStringFromWasm0(ptr2, len2);
|
|
1558
|
+
} finally {
|
|
1559
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1560
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1293
1563
|
}
|
|
1294
1564
|
if (Symbol.dispose) PdfDocMut.prototype[Symbol.dispose] = PdfDocMut.prototype.free;
|
|
1295
1565
|
|
|
@@ -1297,10 +1567,36 @@ if (Symbol.dispose) PdfDocMut.prototype[Symbol.dispose] = PdfDocMut.prototype.fr
|
|
|
1297
1567
|
* The main XFA processing engine for WASM.
|
|
1298
1568
|
*
|
|
1299
1569
|
* Holds a parsed FormTree and provides methods to extract/import data.
|
|
1570
|
+
*
|
|
1571
|
+
* # Memory lifecycle
|
|
1572
|
+
*
|
|
1573
|
+
* `XfaEngine` holds native WASM memory. Call [`XfaEngine.free()`] when done,
|
|
1574
|
+
* or use the `using` keyword (TypeScript 5.2+, TC39 Explicit Resource Management):
|
|
1575
|
+
*
|
|
1576
|
+
* ```js
|
|
1577
|
+
* using engine = XfaEngine.fromFields(fields);
|
|
1578
|
+
* // engine.free() is called automatically at end of block
|
|
1579
|
+
* ```
|
|
1580
|
+
*
|
|
1581
|
+
* After `free()`, all method calls throw. Do not keep references across blocks.
|
|
1582
|
+
*
|
|
1583
|
+
* # Errors
|
|
1584
|
+
*
|
|
1585
|
+
* All fallible methods throw a `PdfluentError` — a standard `Error` subclass with
|
|
1586
|
+
* these properties:
|
|
1587
|
+
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
1588
|
+
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
1589
|
+
* - `message`: human-readable description (stable for backwards compatibility).
|
|
1590
|
+
* - `operation`: short identifier of the API call that failed.
|
|
1591
|
+
* - `help`: optional actionable hint (may be empty string).
|
|
1592
|
+
* - `docsUrl`: deep-link into `https://pdfluent.com/errors/<code>`.
|
|
1593
|
+
* - `legacyCode`: the original SCREAMING_SNAKE_CASE identifier from the
|
|
1594
|
+
* pre-1.0 WASM binding, preserved so older user code keeps working.
|
|
1595
|
+
*
|
|
1596
|
+
* JavaScript callers can use `error instanceof PdfluentError` to discriminate.
|
|
1300
1597
|
*/
|
|
1301
1598
|
export class XfaEngine {
|
|
1302
1599
|
static __wrap(ptr) {
|
|
1303
|
-
ptr = ptr >>> 0;
|
|
1304
1600
|
const obj = Object.create(XfaEngine.prototype);
|
|
1305
1601
|
obj.__wbg_ptr = ptr;
|
|
1306
1602
|
XfaEngineFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
@@ -1560,6 +1856,51 @@ export function activateLicenseKey(key) {
|
|
|
1560
1856
|
}
|
|
1561
1857
|
}
|
|
1562
1858
|
|
|
1859
|
+
/**
|
|
1860
|
+
* Flatten an XFA (XML Forms Architecture) PDF into a static, viewer-agnostic
|
|
1861
|
+
* PDF, entirely in the browser.
|
|
1862
|
+
*
|
|
1863
|
+
* `data` is the raw PDF bytes (a dynamic or static XFA form). `password` is an
|
|
1864
|
+
* optional user password for XFA PDFs protected with PDF user-password
|
|
1865
|
+
* encryption; it is ignored for unencrypted input. A wrong or missing password
|
|
1866
|
+
* on an encrypted document throws an error whose message starts
|
|
1867
|
+
* `E-XFA-ENCRYPTED` and never returns plaintext; a password on an unencrypted
|
|
1868
|
+
* PDF is ignored. This does not crack, remove, or bypass owner-password
|
|
1869
|
+
* permissions.
|
|
1870
|
+
*
|
|
1871
|
+
* ```js
|
|
1872
|
+
* import init, { flattenXfa } from "@pdfluent/sdk-wasm";
|
|
1873
|
+
* await init();
|
|
1874
|
+
* const flat = flattenXfa(new Uint8Array(buf)); // unencrypted
|
|
1875
|
+
* const flatEnc = flattenXfa(new Uint8Array(buf), "secret"); // encrypted
|
|
1876
|
+
* ```
|
|
1877
|
+
* @param {Uint8Array} data
|
|
1878
|
+
* @param {string | null} [password]
|
|
1879
|
+
* @returns {Uint8Array}
|
|
1880
|
+
*/
|
|
1881
|
+
export function flattenXfa(data, password) {
|
|
1882
|
+
try {
|
|
1883
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1884
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
|
|
1885
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1886
|
+
var ptr1 = isLikeNone(password) ? 0 : passStringToWasm0(password, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1887
|
+
var len1 = WASM_VECTOR_LEN;
|
|
1888
|
+
wasm.flattenXfa(retptr, ptr0, len0, ptr1, len1);
|
|
1889
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1890
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1891
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
1892
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
1893
|
+
if (r3) {
|
|
1894
|
+
throw takeObject(r2);
|
|
1895
|
+
}
|
|
1896
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
1897
|
+
wasm.__wbindgen_export4(r0, r1 * 1, 1);
|
|
1898
|
+
return v3;
|
|
1899
|
+
} finally {
|
|
1900
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1563
1904
|
/**
|
|
1564
1905
|
* Return the current license status. Always succeeds; defaults to Trial.
|
|
1565
1906
|
* @returns {LicenseStatus}
|
|
@@ -1568,56 +1909,67 @@ export function licenseStatus() {
|
|
|
1568
1909
|
const ret = wasm.licenseStatus();
|
|
1569
1910
|
return LicenseStatus.__wrap(ret);
|
|
1570
1911
|
}
|
|
1571
|
-
|
|
1572
1912
|
function __wbg_get_imports() {
|
|
1573
1913
|
const import0 = {
|
|
1574
1914
|
__proto__: null,
|
|
1575
|
-
|
|
1915
|
+
__wbg_Error_bce6d499ff0a4aff: function(arg0, arg1) {
|
|
1576
1916
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
1577
1917
|
return addHeapObject(ret);
|
|
1578
1918
|
},
|
|
1579
|
-
|
|
1919
|
+
__wbg___pdfluent_error_ctor_eea54aa1c0fd64d9: function() {
|
|
1920
|
+
const ret = __pdfluent_error_ctor();
|
|
1921
|
+
return addHeapObject(ret);
|
|
1922
|
+
},
|
|
1923
|
+
__wbg___wbindgen_debug_string_edece8177ad01481: function(arg0, arg1) {
|
|
1580
1924
|
const ret = debugString(getObject(arg1));
|
|
1581
1925
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
1582
1926
|
const len1 = WASM_VECTOR_LEN;
|
|
1583
1927
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1584
1928
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1585
1929
|
},
|
|
1586
|
-
|
|
1930
|
+
__wbg___wbindgen_is_function_5cd60d5cf78b4eef: function(arg0) {
|
|
1931
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
1932
|
+
return ret;
|
|
1933
|
+
},
|
|
1934
|
+
__wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
|
|
1587
1935
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1588
1936
|
},
|
|
1589
|
-
|
|
1937
|
+
__wbg_beginPath_0362b3134ed67152: function(arg0) {
|
|
1590
1938
|
getObject(arg0).beginPath();
|
|
1591
1939
|
},
|
|
1592
|
-
|
|
1940
|
+
__wbg_bezierCurveTo_2d7f81b72815a6e9: function(arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
|
|
1593
1941
|
getObject(arg0).bezierCurveTo(arg1, arg2, arg3, arg4, arg5, arg6);
|
|
1594
1942
|
},
|
|
1595
|
-
|
|
1943
|
+
__wbg_clearRect_1ea64f387215d3b8: function(arg0, arg1, arg2, arg3, arg4) {
|
|
1596
1944
|
getObject(arg0).clearRect(arg1, arg2, arg3, arg4);
|
|
1597
1945
|
},
|
|
1598
|
-
|
|
1946
|
+
__wbg_clip_e9791a9cb5940a47: function(arg0, arg1) {
|
|
1599
1947
|
getObject(arg0).clip(__wbindgen_enum_CanvasWindingRule[arg1]);
|
|
1600
1948
|
},
|
|
1601
|
-
|
|
1949
|
+
__wbg_closePath_ab8775c8f9ce941f: function(arg0) {
|
|
1602
1950
|
getObject(arg0).closePath();
|
|
1603
1951
|
},
|
|
1604
|
-
|
|
1952
|
+
__wbg_construct_391d7e1e0b4dda3a: function() { return handleError(function (arg0, arg1) {
|
|
1953
|
+
const ret = Reflect.construct(getObject(arg0), getObject(arg1));
|
|
1954
|
+
return addHeapObject(ret);
|
|
1955
|
+
}, arguments); },
|
|
1956
|
+
__wbg_fillRect_4f7134801b257e68: function(arg0, arg1, arg2, arg3, arg4) {
|
|
1605
1957
|
getObject(arg0).fillRect(arg1, arg2, arg3, arg4);
|
|
1606
1958
|
},
|
|
1607
|
-
|
|
1959
|
+
__wbg_fillText_b32475d6cb52486d: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
|
|
1608
1960
|
getObject(arg0).fillText(getStringFromWasm0(arg1, arg2), arg3, arg4);
|
|
1609
1961
|
}, arguments); },
|
|
1610
|
-
|
|
1962
|
+
__wbg_fill_b52c5e04a3f6413e: function(arg0, arg1) {
|
|
1611
1963
|
getObject(arg0).fill(__wbindgen_enum_CanvasWindingRule[arg1]);
|
|
1612
1964
|
},
|
|
1613
|
-
|
|
1965
|
+
__wbg_getContext_e1463ff7aa682d57: function() { return handleError(function (arg0, arg1, arg2) {
|
|
1614
1966
|
const ret = getObject(arg0).getContext(getStringFromWasm0(arg1, arg2));
|
|
1615
1967
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
1616
1968
|
}, arguments); },
|
|
1617
1969
|
__wbg_getRandomValues_3f44b700395062e5: function() { return handleError(function (arg0, arg1) {
|
|
1618
1970
|
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
1619
1971
|
}, arguments); },
|
|
1620
|
-
|
|
1972
|
+
__wbg_instanceof_CanvasRenderingContext2d_d4be74cff7165c1e: function(arg0) {
|
|
1621
1973
|
let result;
|
|
1622
1974
|
try {
|
|
1623
1975
|
result = getObject(arg0) instanceof CanvasRenderingContext2D;
|
|
@@ -1627,94 +1979,105 @@ function __wbg_get_imports() {
|
|
|
1627
1979
|
const ret = result;
|
|
1628
1980
|
return ret;
|
|
1629
1981
|
},
|
|
1630
|
-
|
|
1982
|
+
__wbg_lineTo_72d6b123d28ab168: function(arg0, arg1, arg2) {
|
|
1631
1983
|
getObject(arg0).lineTo(arg1, arg2);
|
|
1632
1984
|
},
|
|
1633
|
-
|
|
1985
|
+
__wbg_log_eb752234eec406d1: function(arg0) {
|
|
1634
1986
|
console.log(getObject(arg0));
|
|
1635
1987
|
},
|
|
1636
|
-
|
|
1988
|
+
__wbg_moveTo_11bf5a977e6b8610: function(arg0, arg1, arg2) {
|
|
1637
1989
|
getObject(arg0).moveTo(arg1, arg2);
|
|
1638
1990
|
},
|
|
1639
|
-
|
|
1991
|
+
__wbg_new_1f236d63ba0c4784: function(arg0, arg1) {
|
|
1992
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
1993
|
+
return addHeapObject(ret);
|
|
1994
|
+
},
|
|
1995
|
+
__wbg_new_310879b66b6e95e1: function() {
|
|
1640
1996
|
const ret = new Array();
|
|
1641
1997
|
return addHeapObject(ret);
|
|
1642
1998
|
},
|
|
1643
|
-
|
|
1999
|
+
__wbg_new_with_u8_clamped_array_and_sh_13504c3c5394c7c9: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
1644
2000
|
const ret = new ImageData(getClampedArrayU8FromWasm0(arg0, arg1), arg2 >>> 0, arg3 >>> 0);
|
|
1645
2001
|
return addHeapObject(ret);
|
|
1646
2002
|
}, arguments); },
|
|
1647
|
-
|
|
2003
|
+
__wbg_push_b77c476b01548d0a: function(arg0, arg1) {
|
|
1648
2004
|
const ret = getObject(arg0).push(getObject(arg1));
|
|
1649
2005
|
return ret;
|
|
1650
2006
|
},
|
|
1651
|
-
|
|
2007
|
+
__wbg_putImageData_947c369295a5768a: function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
1652
2008
|
getObject(arg0).putImageData(getObject(arg1), arg2, arg3);
|
|
1653
2009
|
}, arguments); },
|
|
1654
|
-
|
|
2010
|
+
__wbg_quadraticCurveTo_5f5e011124b8f464: function(arg0, arg1, arg2, arg3, arg4) {
|
|
1655
2011
|
getObject(arg0).quadraticCurveTo(arg1, arg2, arg3, arg4);
|
|
1656
2012
|
},
|
|
1657
|
-
|
|
2013
|
+
__wbg_resetTransform_6f10bc77e166b888: function() { return handleError(function (arg0) {
|
|
1658
2014
|
getObject(arg0).resetTransform();
|
|
1659
2015
|
}, arguments); },
|
|
1660
|
-
|
|
2016
|
+
__wbg_restore_6a7dd2b862e161a3: function(arg0) {
|
|
1661
2017
|
getObject(arg0).restore();
|
|
1662
2018
|
},
|
|
1663
|
-
|
|
2019
|
+
__wbg_save_14924e966ab6b8b7: function(arg0) {
|
|
1664
2020
|
getObject(arg0).save();
|
|
1665
2021
|
},
|
|
1666
|
-
|
|
2022
|
+
__wbg_setLineDash_52c39bb093201720: function() { return handleError(function (arg0, arg1) {
|
|
1667
2023
|
getObject(arg0).setLineDash(getObject(arg1));
|
|
1668
2024
|
}, arguments); },
|
|
1669
|
-
|
|
2025
|
+
__wbg_set_a0e911be3da02782: function() { return handleError(function (arg0, arg1, arg2) {
|
|
2026
|
+
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
2027
|
+
return ret;
|
|
2028
|
+
}, arguments); },
|
|
2029
|
+
__wbg_set_fillStyle_ac68c79af375566e: function(arg0, arg1, arg2) {
|
|
1670
2030
|
getObject(arg0).fillStyle = getStringFromWasm0(arg1, arg2);
|
|
1671
2031
|
},
|
|
1672
|
-
|
|
2032
|
+
__wbg_set_font_7d34a66f4488295e: function(arg0, arg1, arg2) {
|
|
1673
2033
|
getObject(arg0).font = getStringFromWasm0(arg1, arg2);
|
|
1674
2034
|
},
|
|
1675
|
-
|
|
2035
|
+
__wbg_set_globalAlpha_b733b0d48d14b1c0: function(arg0, arg1) {
|
|
1676
2036
|
getObject(arg0).globalAlpha = arg1;
|
|
1677
2037
|
},
|
|
1678
|
-
|
|
2038
|
+
__wbg_set_globalCompositeOperation_884b1f7507e6f565: function() { return handleError(function (arg0, arg1, arg2) {
|
|
1679
2039
|
getObject(arg0).globalCompositeOperation = getStringFromWasm0(arg1, arg2);
|
|
1680
2040
|
}, arguments); },
|
|
1681
|
-
|
|
2041
|
+
__wbg_set_height_bdd58e6b04e88cca: function(arg0, arg1) {
|
|
1682
2042
|
getObject(arg0).height = arg1 >>> 0;
|
|
1683
2043
|
},
|
|
1684
|
-
|
|
2044
|
+
__wbg_set_lineCap_59e3edc93d8a32b9: function(arg0, arg1, arg2) {
|
|
1685
2045
|
getObject(arg0).lineCap = getStringFromWasm0(arg1, arg2);
|
|
1686
2046
|
},
|
|
1687
|
-
|
|
2047
|
+
__wbg_set_lineDashOffset_6ac8e5b15c55d7f9: function(arg0, arg1) {
|
|
1688
2048
|
getObject(arg0).lineDashOffset = arg1;
|
|
1689
2049
|
},
|
|
1690
|
-
|
|
2050
|
+
__wbg_set_lineJoin_a3878786eac23080: function(arg0, arg1, arg2) {
|
|
1691
2051
|
getObject(arg0).lineJoin = getStringFromWasm0(arg1, arg2);
|
|
1692
2052
|
},
|
|
1693
|
-
|
|
2053
|
+
__wbg_set_lineWidth_e101692cb4fcf2b8: function(arg0, arg1) {
|
|
1694
2054
|
getObject(arg0).lineWidth = arg1;
|
|
1695
2055
|
},
|
|
1696
|
-
|
|
2056
|
+
__wbg_set_miterLimit_75d5333780d1658c: function(arg0, arg1) {
|
|
1697
2057
|
getObject(arg0).miterLimit = arg1;
|
|
1698
2058
|
},
|
|
1699
|
-
|
|
2059
|
+
__wbg_set_name_e500733c75ec36b0: function(arg0, arg1, arg2) {
|
|
2060
|
+
getObject(arg0).name = getStringFromWasm0(arg1, arg2);
|
|
2061
|
+
},
|
|
2062
|
+
__wbg_set_strokeStyle_c6ed1f71bc678b73: function(arg0, arg1, arg2) {
|
|
1700
2063
|
getObject(arg0).strokeStyle = getStringFromWasm0(arg1, arg2);
|
|
1701
2064
|
},
|
|
1702
|
-
|
|
2065
|
+
__wbg_set_width_25112eb6bf1148df: function(arg0, arg1) {
|
|
1703
2066
|
getObject(arg0).width = arg1 >>> 0;
|
|
1704
2067
|
},
|
|
1705
|
-
|
|
2068
|
+
__wbg_strokeRect_3430a0df4158ba67: function(arg0, arg1, arg2, arg3, arg4) {
|
|
1706
2069
|
getObject(arg0).strokeRect(arg1, arg2, arg3, arg4);
|
|
1707
2070
|
},
|
|
1708
|
-
|
|
2071
|
+
__wbg_strokeText_2ada42e0f9d6c857: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4) {
|
|
1709
2072
|
getObject(arg0).strokeText(getStringFromWasm0(arg1, arg2), arg3, arg4);
|
|
1710
2073
|
}, arguments); },
|
|
1711
|
-
|
|
2074
|
+
__wbg_stroke_82139a335b371e81: function(arg0) {
|
|
1712
2075
|
getObject(arg0).stroke();
|
|
1713
2076
|
},
|
|
1714
|
-
|
|
2077
|
+
__wbg_transform_9f749facb9d7d892: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
|
|
1715
2078
|
getObject(arg0).transform(arg1, arg2, arg3, arg4, arg5, arg6);
|
|
1716
2079
|
}, arguments); },
|
|
1717
|
-
|
|
2080
|
+
__wbg_warn_c4e0780980765a86: function(arg0) {
|
|
1718
2081
|
console.warn(getObject(arg0));
|
|
1719
2082
|
},
|
|
1720
2083
|
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
@@ -1740,16 +2103,16 @@ function __wbg_get_imports() {
|
|
|
1740
2103
|
const __wbindgen_enum_CanvasWindingRule = ["nonzero", "evenodd"];
|
|
1741
2104
|
const LicenseStatusFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1742
2105
|
? { register: () => {}, unregister: () => {} }
|
|
1743
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_licensestatus_free(ptr
|
|
2106
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_licensestatus_free(ptr, 1));
|
|
1744
2107
|
const PdfDocFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1745
2108
|
? { register: () => {}, unregister: () => {} }
|
|
1746
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_pdfdoc_free(ptr
|
|
2109
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_pdfdoc_free(ptr, 1));
|
|
1747
2110
|
const PdfDocMutFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1748
2111
|
? { register: () => {}, unregister: () => {} }
|
|
1749
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_pdfdocmut_free(ptr
|
|
2112
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_pdfdocmut_free(ptr, 1));
|
|
1750
2113
|
const XfaEngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
1751
2114
|
? { register: () => {}, unregister: () => {} }
|
|
1752
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_xfaengine_free(ptr
|
|
2115
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_xfaengine_free(ptr, 1));
|
|
1753
2116
|
|
|
1754
2117
|
function addHeapObject(obj) {
|
|
1755
2118
|
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
@@ -1856,8 +2219,7 @@ function getDataViewMemory0() {
|
|
|
1856
2219
|
}
|
|
1857
2220
|
|
|
1858
2221
|
function getStringFromWasm0(ptr, len) {
|
|
1859
|
-
|
|
1860
|
-
return decodeText(ptr, len);
|
|
2222
|
+
return decodeText(ptr >>> 0, len);
|
|
1861
2223
|
}
|
|
1862
2224
|
|
|
1863
2225
|
let cachedUint32ArrayMemory0 = null;
|
|
@@ -1991,8 +2353,9 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
1991
2353
|
|
|
1992
2354
|
let WASM_VECTOR_LEN = 0;
|
|
1993
2355
|
|
|
1994
|
-
let wasmModule, wasm;
|
|
2356
|
+
let wasmModule, wasmInstance, wasm;
|
|
1995
2357
|
function __wbg_finalize_init(instance, module) {
|
|
2358
|
+
wasmInstance = instance;
|
|
1996
2359
|
wasm = instance.exports;
|
|
1997
2360
|
wasmModule = module;
|
|
1998
2361
|
cachedDataViewMemory0 = null;
|
package/xfa_wasm_bg.wasm
CHANGED
|
Binary file
|