@pdfluent/sdk-wasm 1.1.0 → 1.2.0

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 CHANGED
@@ -295,4 +295,4 @@ add-on). The two texts are `LICENSE` and `LICENSE-COMMERCIAL` in this package.
295
295
  - **Documentation:** <https://pdfluent.com/docs>
296
296
  - **Pricing:** <https://pdfluent.com/sdk/pricing>
297
297
  - **PDFluent editor** (source-available): <https://github.com/pdfluent/pdfluent>. The free desktop app this SDK powers.
298
- - Built by [Innovation Trigger BV](https://pdfluent.com)
298
+ - Built by [Innovation Trigger B.V.](https://pdfluent.com)
@@ -321,7 +321,8 @@ unic-char-range, unic-common, unic-ucd-ident, unic-ucd-version, unicode-bidi,
321
321
  unicode-normalization, unicode-properties, unicode-segmentation, unicode-width,
322
322
  unicode-xid, url, utf-8, utf8_iter, utf8parse, uuid, vello_common, vello_cpu,
323
323
  wasm-bindgen, wasm-bindgen-futures, wasm-bindgen-macro,
324
- wasm-bindgen-macro-support, wasm-bindgen-shared, wasm-streams, web-sys,
324
+ wasm-bindgen-macro-support, wasm-bindgen-shared, wasm-streams, wasmi, wasmi_collections, wasmi_core,
325
+ wasmi_ir, web-sys,
325
326
  web-time, web_atoms, weezl, winapi, winapi-i686-pc-windows-gnu,
326
327
  winapi-x86_64-pc-windows-gnu, window-vibrancy, windows, windows-collections,
327
328
  windows-core, windows-future, windows-implement, windows-interface,
@@ -412,8 +413,7 @@ new_debug_unreachable, nom, nom_locate, noop_proc_macro, nu-ansi-term,
412
413
  number_prefix, objc2, objc2-encode, objc2-foundation, open, openssl-sys,
413
414
  os_pipe, pango, pango-sys, pdf-bench, pdf-desktop, pdf-diff, pdf-java,
414
415
  pdfluent-lopdf, phf, phf_generator, phf_macros, phf_shared, plist,
415
- precomputed-hash, quick-xml, redox_syscall, redox_users, rfd, rgb, rquickjs,
416
- rquickjs-core, rquickjs-macro, rquickjs-sys, rusqlite, schannel, schemars,
416
+ precomputed-hash, quick-xml, redox_syscall, redox_users, rfd, rgb, rusqlite, schannel, schemars,
417
417
  schemars_derive, sharded-slab, shared_child, sigchld, simd-adler32,
418
418
  simd_helpers, slab, soup3, soup3-sys, spin, strsim, synstructure, tiff,
419
419
  tokio, tokio-macros, tokio-native-tls, tokio-util, tower, tower-http,
@@ -731,6 +731,44 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
731
731
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
732
732
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
733
733
 
734
+ ================================================================================
735
+ QuickJS-ng — the script engine, compiled into xfa-js-sandboxed's WebAssembly module
736
+ https://github.com/quickjs-ng/quickjs (version 0.7.0)
737
+ ================================================================================
738
+
739
+ QuickJS (MIT) is a component of crates/xfa-js-sandboxed/wasm-guest/qjs_guest.wasm:
740
+ the module is compiled from the C sources in wasm-guest/quickjs/ (two changes,
741
+ listed in wasm-guest/PATCHES.md) and is interpreted by the wasmi crate. No native
742
+ C code runs. The module also contains code from wasi-libc (Apache-2.0 WITH
743
+ LLVM-exception; MIT and BSD-2-Clause parts derived from musl) and LLVM
744
+ compiler-rt (Apache-2.0 WITH LLVM-exception), linked in by the toolchain
745
+ (zig 0.16.0, build tooling only, not shipped). See wasm-guest/NOTICE.
746
+
747
+ The MIT License (MIT)
748
+
749
+ Copyright (c) 2017-2021 Fabrice Bellard
750
+ Copyright (c) 2017-2021 Charlie Gordon
751
+ Copyright (c) 2023 Ben Noordhuis
752
+ Copyright (c) 2023 Saúl Ibarra Corretgé
753
+
754
+ Permission is hereby granted, free of charge, to any person obtaining a copy
755
+ of this software and associated documentation files (the "Software"), to deal
756
+ in the Software without restriction, including without limitation the rights
757
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
758
+ copies of the Software, and to permit persons to whom the Software is
759
+ furnished to do so, subject to the following conditions:
760
+
761
+ The above copyright notice and this permission notice shall be included in
762
+ all copies or substantial portions of the Software.
763
+
764
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
765
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
766
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
767
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
768
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
769
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
770
+ THE SOFTWARE.
771
+
734
772
  ================================================================================
735
773
  tract — ONNX inference for the optional vision layer (#636)
736
774
  https://github.com/sonos/tract
package/package.json CHANGED
@@ -2,8 +2,12 @@
2
2
  "name": "@pdfluent/sdk-wasm",
3
3
  "type": "module",
4
4
  "description": "PDFluent browser SDK — find and replace PDF text programmatically while preserving fonts and layout, plus edit, annotate, redact, sign and validate PDFs (including XFA), entirely client-side via WASM.",
5
- "version": "1.1.0",
5
+ "version": "1.2.0",
6
6
  "license": "SEE LICENSE IN LICENSE-OFFER",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/pdfluent/pdfluent-sdk"
10
+ },
7
11
  "files": [
8
12
  "xfa_wasm_bg.wasm",
9
13
  "xfa_wasm.js",
@@ -14,7 +18,8 @@
14
18
  "LICENSE-COMMERCIAL",
15
19
  "LICENSE-OFFER",
16
20
  "NOTICE",
17
- "THIRD_PARTY_LICENSES.txt"
21
+ "THIRD_PARTY_LICENSES.txt",
22
+ "xfa_wasm.augment.d.ts"
18
23
  ],
19
24
  "main": "xfa_wasm.js",
20
25
  "types": "xfa_wasm.d.ts",
@@ -39,9 +44,21 @@
39
44
  "redact"
40
45
  ],
41
46
  "homepage": "https://pdfluent.com",
42
- "author": "Innovation Trigger BV <team@pdfluent.com>",
43
- "repository": {
44
- "type": "git",
45
- "url": "https://github.com/pdfluent/pdfluent-sdk"
47
+ "author": "Innovation Trigger B.V. <team@pdfluent.com>",
48
+ "bugs": {
49
+ "url": "https://github.com/pdfluent/pdfluent-sdk/issues"
50
+ },
51
+ "exports": {
52
+ ".": {
53
+ "types": "./xfa_wasm.d.ts",
54
+ "import": "./xfa_wasm.js",
55
+ "default": "./xfa_wasm.js"
56
+ },
57
+ "./augment": {
58
+ "types": "./xfa_wasm.augment.d.ts"
59
+ },
60
+ "./xfa_wasm_bg.wasm": "./xfa_wasm_bg.wasm",
61
+ "./package.json": "./package.json",
62
+ "./*": "./*"
46
63
  }
47
64
  }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Hand-maintained TypeScript supplement for `@pdfluent/sdk-wasm`.
3
+ *
4
+ * Augments the generated `xfa_wasm.d.ts` with:
5
+ * - `PdfluentError` class declaration (errors thrown by all WASM methods)
6
+ * - `XfaWasmError` legacy alias (kept for older consumer code that imported
7
+ * the pre-1.0 type name)
8
+ * - `free()` lifecycle documentation for `PdfDoc` and `XfaEngine`
9
+ *
10
+ * Usage: import this file alongside the main module in projects that need
11
+ * strict error handling:
12
+ *
13
+ * ```ts
14
+ * import init, { PdfDoc } from '@pdfluent/sdk-wasm';
15
+ * import type { PdfluentError } from '@pdfluent/sdk-wasm/pkg-types/xfa_wasm.augment';
16
+ * ```
17
+ *
18
+ * Or add this file to your `tsconfig.json` `types` array for global augmentation.
19
+ */
20
+
21
+ /* --- Typed error class ----------------------------------------------------- */
22
+
23
+ /**
24
+ * Structured error thrown by every fallible PDFluent WASM operation.
25
+ *
26
+ * `PdfluentError` is a real `class` (extends `Error`) registered on
27
+ * `globalThis.__PdfluentError` the first time the WASM module loads. The
28
+ * thrown instance is a true subclass of `Error`, so
29
+ * `error instanceof PdfluentError` works in user code.
30
+ *
31
+ * ## Example
32
+ *
33
+ * ```ts
34
+ * import init, { PdfDoc, PdfluentError } from '@pdfluent/sdk-wasm';
35
+ * await init();
36
+ *
37
+ * try {
38
+ * using doc = PdfDoc.open(corruptBytes);
39
+ * } catch (e) {
40
+ * if (e instanceof PdfluentError) {
41
+ * console.error(`[${e.code}] ${e.message} (in ${e.operation})`);
42
+ * if (e.code === 'E-PARSE-INVALID-PDF') {
43
+ * // show "not a valid PDF" UI feedback
44
+ * }
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * ## Properties
50
+ *
51
+ * | Property | Type | Description |
52
+ * |----------|------|-------------|
53
+ * | `code` | `string` | Stable C8 catalogue code, format `E-<CATEGORY>-<SPECIFIC>`. |
54
+ * | `message` | `string` | Human-readable description. |
55
+ * | `operation` | `string` | API call that failed (e.g. `"PdfDoc.open"`). |
56
+ * | `help` | `string` | Optional actionable hint (may be empty). |
57
+ * | `docsUrl` | `string` | Deep-link to documentation at `https://pdfluent.com/errors/<code>`. |
58
+ * | `legacyCode` | `string` | Pre-1.0 SCREAMING_SNAKE_CASE identifier, preserved for backward compatibility. |
59
+ *
60
+ * ## C8 Error codes (canonical, from `docs/error_catalogue.md`)
61
+ *
62
+ * | Code | Thrown by |
63
+ * |------|-----------|
64
+ * | `E-PARSE-INVALID-PDF` | `PdfDoc.open` — bytes are not a valid PDF |
65
+ * | `E-IO-GENERIC` | I/O failure |
66
+ * | `E-PARSE-UNSUPPORTED-VERSION` | `PdfDoc.open` — PDF version too new |
67
+ * | `E-COMPLIANCE-PDFA-INVALID` | `convertToPdfa`, `validatePdfA` |
68
+ * | `E-ENV-UNSUPPORTED-ON-WASM` | Native-only operation invoked from WASM |
69
+ * | `E-INTERNAL` | Internal safety-net |
70
+ * | `E-WASM-INVALID-ARGUMENT` | Argument validation (e.g. `validatePdfA("xyz")`) |
71
+ * | `E-WASM-PAGE-OUT-OF-RANGE` | Page index outside `0..page_count` |
72
+ * | `E-WASM-RENDER-FAILED` | `renderPage`, `renderPageToCanvas` |
73
+ * | `E-WASM-RENDER-FALLBACK` | Vector renderer hit unsupported feature |
74
+ * | `E-WASM-TEXT-EXTRACT-FAILED` | `getTextPositions` |
75
+ * | `E-WASM-XFA-FAILED` | `flattenXfa` |
76
+ * | `E-WASM-MERGE-FAILED` | `merge` |
77
+ * | `E-WASM-SAVE-FAILED` | Internal save / serialize |
78
+ * | `E-WASM-INVALID-JSON` | `fromFields`, `fromJson`, `importJson`, schema export |
79
+ * | `E-WASM-FORMCALC-FAILED` | `runCalculations` |
80
+ * | `E-SECURITY-DECRYPTION-FAILED` | `decryptPdf`, `signPdf`: wrong password, or one that does not entitle the call |
81
+ * | `E-WASM-SIGN-FAILED` | `signPdf` |
82
+ *
83
+ * ## Backward compatibility
84
+ *
85
+ * Before 1.0 the WASM binding threw `XfaWasmError` with a SCREAMING_SNAKE_CASE
86
+ * `.code` property. That identifier is preserved on the new `.legacyCode`
87
+ * property and on the `XfaWasmError` type alias (see below) so existing
88
+ * consumer code keeps working. Newly-written code should use `.code` with the
89
+ * `E-<CATEGORY>-<SPECIFIC>` strings.
90
+ */
91
+ export declare class PdfluentError extends Error {
92
+ /** Stable C8 catalogue code in `E-<CATEGORY>-<SPECIFIC>` format. */
93
+ readonly code: string;
94
+ /** Short identifier of the API call that failed (e.g. `"PdfDoc.open"`). */
95
+ readonly operation: string;
96
+ /** Optional actionable hint for developers. May be empty string. */
97
+ readonly help: string;
98
+ /** Deep-link into the error documentation. */
99
+ readonly docsUrl: string;
100
+ /** Pre-1.0 SCREAMING_SNAKE_CASE identifier, kept for backward compatibility. */
101
+ readonly legacyCode: string;
102
+ }
103
+
104
+ /**
105
+ * Legacy alias for `PdfluentError`. Existing code that does
106
+ * `import { XfaWasmError }` keeps compiling; new code should use
107
+ * `PdfluentError`.
108
+ *
109
+ * @deprecated Use {@link PdfluentError}.
110
+ */
111
+ export type XfaWasmError = PdfluentError;
112
+
113
+ /* --- Type guards ----------------------------------------------------------- */
114
+
115
+ /**
116
+ * Type guard: returns `true` when `e` is a `PdfluentError` thrown by the WASM module.
117
+ *
118
+ * ```ts
119
+ * try {
120
+ * doc.flattenXfa();
121
+ * } catch (e) {
122
+ * if (isPdfluentError(e)) {
123
+ * console.error(e.code, e.help);
124
+ * }
125
+ * }
126
+ * ```
127
+ */
128
+ export declare function isPdfluentError(e: unknown): e is PdfluentError;
129
+
130
+ /**
131
+ * Legacy alias for {@link isPdfluentError}.
132
+ * @deprecated Use {@link isPdfluentError}.
133
+ */
134
+ export declare function isXfaWasmError(e: unknown): e is PdfluentError;
135
+
136
+ /* --- Lifecycle augmentation ----------------------------------------------- */
137
+
138
+ /**
139
+ * Lifecycle contract for WASM objects that hold native memory.
140
+ *
141
+ * Both `PdfDoc` and `XfaEngine` allocate memory in the WASM heap. The JavaScript
142
+ * garbage collector does **not** free WASM heap memory — you must call `free()`
143
+ * explicitly, or use the `using` keyword (TypeScript 5.2+, requires `--target ES2022`
144
+ * or newer and `lib: ["ESNext.Disposable"]`).
145
+ *
146
+ * ### Option 1 — `using` (recommended, TypeScript 5.2+)
147
+ *
148
+ * ```ts
149
+ * {
150
+ * using doc = PdfDoc.open(bytes);
151
+ * const count = doc.pageCount();
152
+ * } // doc.free() called automatically here
153
+ * ```
154
+ *
155
+ * ### Option 2 — explicit `free()`
156
+ *
157
+ * ```ts
158
+ * const doc = PdfDoc.open(bytes);
159
+ * try {
160
+ * const count = doc.pageCount();
161
+ * } finally {
162
+ * doc.free();
163
+ * }
164
+ * ```
165
+ *
166
+ * ### After `free()`
167
+ *
168
+ * Once `free()` is called, the object's native pointer is invalidated. Any
169
+ * subsequent method call throws a `PdfluentError` with code `"E-INTERNAL"`.
170
+ */
171
+ export interface WasmLifecycle {
172
+ /**
173
+ * Release all native WASM heap memory owned by this object.
174
+ *
175
+ * - Must be called when you are done with the object, unless you used `using`.
176
+ * - After calling `free()`, all methods throw.
177
+ * - Calling `free()` twice is safe (no-op).
178
+ * - Equivalent to `[Symbol.dispose]()`.
179
+ */
180
+ free(): void;
181
+
182
+ /**
183
+ * Alias for `free()`, called automatically by the `using` statement.
184
+ *
185
+ * See {@link WasmLifecycle.free} for full lifecycle documentation.
186
+ */
187
+ [Symbol.dispose](): void;
188
+ }
package/xfa_wasm.d.ts CHANGED
@@ -330,6 +330,10 @@ export class PdfDoc {
330
330
  /**
331
331
  * Search-and-redact: every match of `query` (literal text, case-sensitive)
332
332
  * is permanently removed from every page.
333
+ *
334
+ * Throws `E-PARSE-INVALID-PDF` when a page's text could not be read:
335
+ * that page was not searched, so returning bytes would read as "no
336
+ * matches there" (#698).
333
337
  */
334
338
  redactSearch(query: string): Uint8Array;
335
339
  /**
@@ -426,6 +430,16 @@ export class PdfDoc {
426
430
  * extraction fails.
427
431
  */
428
432
  text(page_index: number): string;
433
+ /**
434
+ * Every text block of the document with its page and enclosing box, as
435
+ * JSON (#416): `[{"text": "...", "bbox": [xMin, yMin, xMax, yMax], "page": 0}]`.
436
+ *
437
+ * `page` is 0-based like every page index in this binding; `bbox` is in PDF
438
+ * points with the origin at the bottom left (PDF space, not the y-down CSS
439
+ * space `getTextPositions` returns). An XFA form is read from its flattened
440
+ * form, as `text` and `getTextPositions` do.
441
+ */
442
+ textWithLayout(): string;
429
443
  /**
430
444
  * Convert this PDF to a Word `.docx` package.
431
445
  *
@@ -532,6 +546,15 @@ export class PdfDocMut {
532
546
  * `formatted = false`, `bytesChanged = 0`, no error.
533
547
  */
534
548
  formatTextSpan(page_num: number, run_index: number, font_size?: number | null, color?: string | null): string;
549
+ /**
550
+ * The images drawn on a page (0-based `pageIndex`) as JSON, in drawing
551
+ * order, form-nested and inline images included:
552
+ * `[{"formPath":[…],"opIndex":n,"kind":"xobject"|"inline","resourceName":…,
553
+ * "formNames":[…],"ctm":[6],"bbox":[x0,y0,x1,y1],"pixelWidth":…,
554
+ * "pixelHeight":…,"hasSmask":…}]`. `bbox` is in page space, origin at the
555
+ * bottom left. An entry is the handle the three edit methods take.
556
+ */
557
+ imagePlacements(page_index: number): string;
535
558
  /**
536
559
  * Open a PDF for editing.
537
560
  */
@@ -547,12 +570,26 @@ export class PdfDocMut {
547
570
  /**
548
571
  * Search-and-redact: every literal match of `query` is permanently
549
572
  * removed from every page.
573
+ *
574
+ * Throws `E-PARSE-INVALID-PDF` when a page's text could not be read:
575
+ * that page was not searched, so success would read as "no matches
576
+ * there" (#698). The document is then left as it was.
550
577
  */
551
578
  redactSearch(query: string): void;
579
+ /**
580
+ * Remove one placed image. The image data leaves the file when nothing
581
+ * else uses it.
582
+ */
583
+ removeImage(page_index: number, handle_json: string): void;
552
584
  /**
553
585
  * Re-order pages. `new_order` is a permutation of `0..page_count`.
554
586
  */
555
587
  reorderPages(new_order: Uint32Array): void;
588
+ /**
589
+ * Swap the picture of one placed image for JPEG or PNG `data`, fitted
590
+ * inside the old placement and centred. Returns the new handle as JSON.
591
+ */
592
+ replaceImage(page_index: number, handle_json: string, data: Uint8Array): string;
556
593
  /**
557
594
  * G3 — Replace a text span on a page.
558
595
  *
@@ -622,6 +659,13 @@ export class PdfDocMut {
622
659
  * `{"field.path": "value", ...}`.
623
660
  */
624
661
  setFormFields(fields_json: string): void;
662
+ /**
663
+ * Move or resize one placed image so its bounding box becomes
664
+ * `[x0, y0, x1, y1]` in page space. `handleJson` is an entry of
665
+ * `imagePlacements`. Returns the new handle as JSON. An edit inside a Form
666
+ * XObject copies the form for this page, so other pages keep the original.
667
+ */
668
+ setImageRect(page_index: number, handle_json: string, x0: number, y0: number, x1: number, y1: number): string;
625
669
  /**
626
670
  * Select multiple options on a multi-select list box.
627
671
  *
@@ -893,6 +937,7 @@ export interface InitOutput {
893
937
  readonly pdfdoc_setFormFields: (a: number, b: number, c: number, d: number) => void;
894
938
  readonly pdfdoc_signatures: (a: number, b: number) => void;
895
939
  readonly pdfdoc_text: (a: number, b: number, c: number) => void;
940
+ readonly pdfdoc_textWithLayout: (a: number, b: number) => void;
896
941
  readonly pdfdoc_toDocx: (a: number, b: number) => void;
897
942
  readonly pdfdoc_toPptx: (a: number, b: number) => void;
898
943
  readonly pdfdoc_toXlsx: (a: number, b: number) => void;
@@ -908,16 +953,20 @@ export interface InitOutput {
908
953
  readonly pdfdocmut_deletePages: (a: number, b: number, c: number, d: number) => void;
909
954
  readonly pdfdocmut_extractPages: (a: number, b: number, c: number, d: number) => void;
910
955
  readonly pdfdocmut_formatTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
956
+ readonly pdfdocmut_imagePlacements: (a: number, b: number, c: number) => void;
911
957
  readonly pdfdocmut_open: (a: number, b: number, c: number) => void;
912
958
  readonly pdfdocmut_pageCount: (a: number) => number;
913
959
  readonly pdfdocmut_redactRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
914
960
  readonly pdfdocmut_redactSearch: (a: number, b: number, c: number, d: number) => void;
961
+ readonly pdfdocmut_removeImage: (a: number, b: number, c: number, d: number, e: number) => void;
915
962
  readonly pdfdocmut_reorderPages: (a: number, b: number, c: number, d: number) => void;
963
+ readonly pdfdocmut_replaceImage: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
916
964
  readonly pdfdocmut_replaceTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
917
965
  readonly pdfdocmut_rotatePage: (a: number, b: number, c: number, d: number) => void;
918
966
  readonly pdfdocmut_save: (a: number, b: number) => void;
919
967
  readonly pdfdocmut_setFormField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
920
968
  readonly pdfdocmut_setFormFields: (a: number, b: number, c: number, d: number) => void;
969
+ readonly pdfdocmut_setImageRect: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
921
970
  readonly pdfdocmut_setMultiSelect: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
922
971
  readonly pdfdocmut_setTextRunStyle: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
923
972
  readonly signPdf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
package/xfa_wasm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* @ts-self-types="./xfa_wasm.d.ts" */
2
- import { __pdfluent_error_ctor } from './snippets/xfa-wasm-d1985887593da269/inline0.js';
2
+ import { __pdfluent_error_ctor } from './snippets/xfa-wasm-0357326a9eb2f21e/inline0.js';
3
3
 
4
4
 
5
5
  /**
@@ -725,6 +725,10 @@ export class PdfDoc {
725
725
  /**
726
726
  * Search-and-redact: every match of `query` (literal text, case-sensitive)
727
727
  * is permanently removed from every page.
728
+ *
729
+ * Throws `E-PARSE-INVALID-PDF` when a page's text could not be read:
730
+ * that page was not searched, so returning bytes would read as "no
731
+ * matches there" (#698).
728
732
  * @param {string} query
729
733
  * @returns {Uint8Array}
730
734
  */
@@ -1048,6 +1052,40 @@ export class PdfDoc {
1048
1052
  wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
1049
1053
  }
1050
1054
  }
1055
+ /**
1056
+ * Every text block of the document with its page and enclosing box, as
1057
+ * JSON (#416): `[{"text": "...", "bbox": [xMin, yMin, xMax, yMax], "page": 0}]`.
1058
+ *
1059
+ * `page` is 0-based like every page index in this binding; `bbox` is in PDF
1060
+ * points with the origin at the bottom left (PDF space, not the y-down CSS
1061
+ * space `getTextPositions` returns). An XFA form is read from its flattened
1062
+ * form, as `text` and `getTextPositions` do.
1063
+ * @returns {string}
1064
+ */
1065
+ textWithLayout() {
1066
+ let deferred2_0;
1067
+ let deferred2_1;
1068
+ try {
1069
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1070
+ wasm.pdfdoc_textWithLayout(retptr, this.__wbg_ptr);
1071
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1072
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1073
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1074
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1075
+ var ptr1 = r0;
1076
+ var len1 = r1;
1077
+ if (r3) {
1078
+ ptr1 = 0; len1 = 0;
1079
+ throw takeObject(r2);
1080
+ }
1081
+ deferred2_0 = ptr1;
1082
+ deferred2_1 = len1;
1083
+ return getStringFromWasm0(ptr1, len1);
1084
+ } finally {
1085
+ wasm.__wbindgen_add_to_stack_pointer(16);
1086
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1087
+ }
1088
+ }
1051
1089
  /**
1052
1090
  * Convert this PDF to a Word `.docx` package.
1053
1091
  *
@@ -1469,6 +1507,40 @@ export class PdfDocMut {
1469
1507
  wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
1470
1508
  }
1471
1509
  }
1510
+ /**
1511
+ * The images drawn on a page (0-based `pageIndex`) as JSON, in drawing
1512
+ * order, form-nested and inline images included:
1513
+ * `[{"formPath":[…],"opIndex":n,"kind":"xobject"|"inline","resourceName":…,
1514
+ * "formNames":[…],"ctm":[6],"bbox":[x0,y0,x1,y1],"pixelWidth":…,
1515
+ * "pixelHeight":…,"hasSmask":…}]`. `bbox` is in page space, origin at the
1516
+ * bottom left. An entry is the handle the three edit methods take.
1517
+ * @param {number} page_index
1518
+ * @returns {string}
1519
+ */
1520
+ imagePlacements(page_index) {
1521
+ let deferred2_0;
1522
+ let deferred2_1;
1523
+ try {
1524
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1525
+ wasm.pdfdocmut_imagePlacements(retptr, this.__wbg_ptr, page_index);
1526
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1527
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1528
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1529
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1530
+ var ptr1 = r0;
1531
+ var len1 = r1;
1532
+ if (r3) {
1533
+ ptr1 = 0; len1 = 0;
1534
+ throw takeObject(r2);
1535
+ }
1536
+ deferred2_0 = ptr1;
1537
+ deferred2_1 = len1;
1538
+ return getStringFromWasm0(ptr1, len1);
1539
+ } finally {
1540
+ wasm.__wbindgen_add_to_stack_pointer(16);
1541
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
1542
+ }
1543
+ }
1472
1544
  /**
1473
1545
  * Open a PDF for editing.
1474
1546
  * @param {Uint8Array} bytes
@@ -1523,6 +1595,10 @@ export class PdfDocMut {
1523
1595
  /**
1524
1596
  * Search-and-redact: every literal match of `query` is permanently
1525
1597
  * removed from every page.
1598
+ *
1599
+ * Throws `E-PARSE-INVALID-PDF` when a page's text could not be read:
1600
+ * that page was not searched, so success would read as "no matches
1601
+ * there" (#698). The document is then left as it was.
1526
1602
  * @param {string} query
1527
1603
  */
1528
1604
  redactSearch(query) {
@@ -1540,6 +1616,27 @@ export class PdfDocMut {
1540
1616
  wasm.__wbindgen_add_to_stack_pointer(16);
1541
1617
  }
1542
1618
  }
1619
+ /**
1620
+ * Remove one placed image. The image data leaves the file when nothing
1621
+ * else uses it.
1622
+ * @param {number} page_index
1623
+ * @param {string} handle_json
1624
+ */
1625
+ removeImage(page_index, handle_json) {
1626
+ try {
1627
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1628
+ const ptr0 = passStringToWasm0(handle_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1629
+ const len0 = WASM_VECTOR_LEN;
1630
+ wasm.pdfdocmut_removeImage(retptr, this.__wbg_ptr, page_index, ptr0, len0);
1631
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1632
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1633
+ if (r1) {
1634
+ throw takeObject(r0);
1635
+ }
1636
+ } finally {
1637
+ wasm.__wbindgen_add_to_stack_pointer(16);
1638
+ }
1639
+ }
1543
1640
  /**
1544
1641
  * Re-order pages. `new_order` is a permutation of `0..page_count`.
1545
1642
  * @param {Uint32Array} new_order
@@ -1559,6 +1656,42 @@ export class PdfDocMut {
1559
1656
  wasm.__wbindgen_add_to_stack_pointer(16);
1560
1657
  }
1561
1658
  }
1659
+ /**
1660
+ * Swap the picture of one placed image for JPEG or PNG `data`, fitted
1661
+ * inside the old placement and centred. Returns the new handle as JSON.
1662
+ * @param {number} page_index
1663
+ * @param {string} handle_json
1664
+ * @param {Uint8Array} data
1665
+ * @returns {string}
1666
+ */
1667
+ replaceImage(page_index, handle_json, data) {
1668
+ let deferred4_0;
1669
+ let deferred4_1;
1670
+ try {
1671
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1672
+ const ptr0 = passStringToWasm0(handle_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1673
+ const len0 = WASM_VECTOR_LEN;
1674
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_export);
1675
+ const len1 = WASM_VECTOR_LEN;
1676
+ wasm.pdfdocmut_replaceImage(retptr, this.__wbg_ptr, page_index, ptr0, len0, ptr1, len1);
1677
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1678
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1679
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1680
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1681
+ var ptr3 = r0;
1682
+ var len3 = r1;
1683
+ if (r3) {
1684
+ ptr3 = 0; len3 = 0;
1685
+ throw takeObject(r2);
1686
+ }
1687
+ deferred4_0 = ptr3;
1688
+ deferred4_1 = len3;
1689
+ return getStringFromWasm0(ptr3, len3);
1690
+ } finally {
1691
+ wasm.__wbindgen_add_to_stack_pointer(16);
1692
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
1693
+ }
1694
+ }
1562
1695
  /**
1563
1696
  * G3 — Replace a text span on a page.
1564
1697
  *
@@ -1724,6 +1857,45 @@ export class PdfDocMut {
1724
1857
  wasm.__wbindgen_add_to_stack_pointer(16);
1725
1858
  }
1726
1859
  }
1860
+ /**
1861
+ * Move or resize one placed image so its bounding box becomes
1862
+ * `[x0, y0, x1, y1]` in page space. `handleJson` is an entry of
1863
+ * `imagePlacements`. Returns the new handle as JSON. An edit inside a Form
1864
+ * XObject copies the form for this page, so other pages keep the original.
1865
+ * @param {number} page_index
1866
+ * @param {string} handle_json
1867
+ * @param {number} x0
1868
+ * @param {number} y0
1869
+ * @param {number} x1
1870
+ * @param {number} y1
1871
+ * @returns {string}
1872
+ */
1873
+ setImageRect(page_index, handle_json, x0, y0, x1, y1) {
1874
+ let deferred3_0;
1875
+ let deferred3_1;
1876
+ try {
1877
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1878
+ const ptr0 = passStringToWasm0(handle_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1879
+ const len0 = WASM_VECTOR_LEN;
1880
+ wasm.pdfdocmut_setImageRect(retptr, this.__wbg_ptr, page_index, ptr0, len0, x0, y0, x1, y1);
1881
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1882
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1883
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1884
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1885
+ var ptr2 = r0;
1886
+ var len2 = r1;
1887
+ if (r3) {
1888
+ ptr2 = 0; len2 = 0;
1889
+ throw takeObject(r2);
1890
+ }
1891
+ deferred3_0 = ptr2;
1892
+ deferred3_1 = len2;
1893
+ return getStringFromWasm0(ptr2, len2);
1894
+ } finally {
1895
+ wasm.__wbindgen_add_to_stack_pointer(16);
1896
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
1897
+ }
1898
+ }
1727
1899
  /**
1728
1900
  * Select multiple options on a multi-select list box.
1729
1901
  *
@@ -2416,7 +2588,7 @@ export function signPdf(bytes, pkcs12, password, options) {
2416
2588
  function __wbg_get_imports() {
2417
2589
  const import0 = {
2418
2590
  __proto__: null,
2419
- __wbg___pdfluent_error_ctor_17e86bb485874967: function() {
2591
+ __wbg___pdfluent_error_ctor_9f2854a17b02ffba: function() {
2420
2592
  const ret = __pdfluent_error_ctor();
2421
2593
  return addHeapObject(ret);
2422
2594
  },
package/xfa_wasm_bg.wasm CHANGED
Binary file
@@ -44,6 +44,7 @@ export const pdfdoc_setFormField: (a: number, b: number, c: number, d: number, e
44
44
  export const pdfdoc_setFormFields: (a: number, b: number, c: number, d: number) => void;
45
45
  export const pdfdoc_signatures: (a: number, b: number) => void;
46
46
  export const pdfdoc_text: (a: number, b: number, c: number) => void;
47
+ export const pdfdoc_textWithLayout: (a: number, b: number) => void;
47
48
  export const pdfdoc_toDocx: (a: number, b: number) => void;
48
49
  export const pdfdoc_toPptx: (a: number, b: number) => void;
49
50
  export const pdfdoc_toXlsx: (a: number, b: number) => void;
@@ -59,16 +60,20 @@ export const pdfdocmut_compress: (a: number, b: number) => void;
59
60
  export const pdfdocmut_deletePages: (a: number, b: number, c: number, d: number) => void;
60
61
  export const pdfdocmut_extractPages: (a: number, b: number, c: number, d: number) => void;
61
62
  export const pdfdocmut_formatTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
63
+ export const pdfdocmut_imagePlacements: (a: number, b: number, c: number) => void;
62
64
  export const pdfdocmut_open: (a: number, b: number, c: number) => void;
63
65
  export const pdfdocmut_pageCount: (a: number) => number;
64
66
  export const pdfdocmut_redactRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
65
67
  export const pdfdocmut_redactSearch: (a: number, b: number, c: number, d: number) => void;
68
+ export const pdfdocmut_removeImage: (a: number, b: number, c: number, d: number, e: number) => void;
66
69
  export const pdfdocmut_reorderPages: (a: number, b: number, c: number, d: number) => void;
70
+ export const pdfdocmut_replaceImage: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
67
71
  export const pdfdocmut_replaceTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
68
72
  export const pdfdocmut_rotatePage: (a: number, b: number, c: number, d: number) => void;
69
73
  export const pdfdocmut_save: (a: number, b: number) => void;
70
74
  export const pdfdocmut_setFormField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
71
75
  export const pdfdocmut_setFormFields: (a: number, b: number, c: number, d: number) => void;
76
+ export const pdfdocmut_setImageRect: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
72
77
  export const pdfdocmut_setMultiSelect: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
73
78
  export const pdfdocmut_setTextRunStyle: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
74
79
  export const signPdf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;