@pdfluent/sdk-wasm 1.1.0 → 1.3.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 +9 -9
- package/THIRD_PARTY_LICENSES.txt +84 -3
- package/package.json +23 -6
- package/xfa_wasm.augment.d.ts +188 -0
- package/xfa_wasm.d.ts +59 -10
- package/xfa_wasm.js +184 -12
- package/xfa_wasm_bg.wasm +0 -0
- package/xfa_wasm_bg.wasm.d.ts +5 -0
- /package/snippets/{xfa-wasm-d1985887593da269 → xfa-wasm-d23d7ce846a87fdd}/inline0.js +0 -0
package/README.md
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
[Source on GitHub](https://github.com/pdfluent/pdfluent-sdk) · [Documentation](https://pdfluent.com/docs) · [Report an issue](https://github.com/pdfluent/pdfluent-sdk/issues)
|
|
4
4
|
|
|
5
5
|
WebAssembly distribution of the PDFluent PDF engine. Read, edit, annotate,
|
|
6
|
-
redact, sign, and validate PDFs (including XFA) entirely in the browser
|
|
6
|
+
redact, sign, and validate PDFs (including XFA) entirely in the browser -
|
|
7
7
|
zero bytes go to a server.
|
|
8
8
|
|
|
9
9
|
Published as `@pdfluent/sdk-wasm` on npm. (The crate directory is named
|
|
10
|
-
`xfa-wasm` for historical XFA roots
|
|
10
|
+
`xfa-wasm` for historical XFA roots - the published npm package covers the
|
|
11
11
|
full SDK surface needed for an in-browser PDF editor. Previously known as
|
|
12
12
|
`@pdfluent/xfa-wasm`; renamed to `@pdfluent/sdk-wasm`.)
|
|
13
13
|
|
|
@@ -22,7 +22,7 @@ full SDK surface needed for an in-browser PDF editor. Previously known as
|
|
|
22
22
|
- **Text watermark**: diagonal text watermark with configurable opacity
|
|
23
23
|
- **Redaction**: by region (rectangle) or by search query (permanent removal: the content is gone, not covered)
|
|
24
24
|
- **Stream compression**: re-deflate content streams for smaller file size
|
|
25
|
-
- **`PdfDocMut`**: stateful editing handle
|
|
25
|
+
- **`PdfDocMut`**: stateful editing handle - open once, mutate in place,
|
|
26
26
|
save once. One parse and one serialise for a whole editing session instead
|
|
27
27
|
of one per operation, with identical output bytes.
|
|
28
28
|
|
|
@@ -216,7 +216,7 @@ wasm-pack build crates/xfa-wasm --target web -- --no-default-features
|
|
|
216
216
|
| `redactSearch(query)` | Find all literal matches of `query` and redact each |
|
|
217
217
|
| `compress()` | Re-deflate content streams; returns optimised bytes |
|
|
218
218
|
|
|
219
|
-
### PdfDocMut
|
|
219
|
+
### PdfDocMut - **recommended for editor workflows**
|
|
220
220
|
|
|
221
221
|
`PdfDocMut` is a stateful editing handle. Open once, mutate in place,
|
|
222
222
|
save once. The `PdfDoc` class above is great for inspection and
|
|
@@ -229,14 +229,14 @@ serialise per step.
|
|
|
229
229
|
|--------|-------------|
|
|
230
230
|
| `PdfDocMut.open(bytes)` | Open for editing |
|
|
231
231
|
| `pageCount()` | Live page count after any mutations so far |
|
|
232
|
-
| `save()` | Serialise current state to `Uint8Array`. Non-consuming
|
|
232
|
+
| `save()` | Serialise current state to `Uint8Array`. Non-consuming - keep editing after |
|
|
233
233
|
| `free()` | Release the WASM-side memory deterministically |
|
|
234
234
|
| `deletePages(pages)` | In place |
|
|
235
235
|
| `rotatePage(pageIndex, degrees)` | In place |
|
|
236
236
|
| `reorderPages(newOrder)` | In place |
|
|
237
237
|
| `extractPages(pages)` | Returns bytes for a NEW subdocument; current editor unchanged |
|
|
238
|
-
| `setFormField(path, value)` | In place
|
|
239
|
-
| `setFormFields(jsonObject)` | In place, bulk
|
|
238
|
+
| `setFormField(path, value)` | In place - text, checkbox, radio, and choice; updates `/V`, `/AS`, and `/AP` |
|
|
239
|
+
| `setFormFields(jsonObject)` | In place, bulk - same full chain for each entry |
|
|
240
240
|
| `addHighlight(pageIndex, x, y, w, h, colorHex?)` | In place (feature: annotate) |
|
|
241
241
|
| `addStickyNote(pageIndex, x, y, contents)` | In place (feature: annotate) |
|
|
242
242
|
| `addFreeText(pageIndex, x, y, w, h, contents)` | In place (feature: annotate) |
|
|
@@ -254,7 +254,7 @@ await init();
|
|
|
254
254
|
const bytes = new Uint8Array(await (await fetch('/document.pdf')).arrayBuffer());
|
|
255
255
|
const editor = PdfDocMut.open(bytes);
|
|
256
256
|
|
|
257
|
-
// All edits operate on the same internal lopdf::Document
|
|
257
|
+
// All edits operate on the same internal lopdf::Document - no re-parse.
|
|
258
258
|
editor.reorderPages(new Uint32Array([1, 0, 2]));
|
|
259
259
|
editor.addTextWatermark('CONCEPT', 0.3);
|
|
260
260
|
editor.addHighlight(0, 100, 700, 200, 20, '#ffeb3b');
|
|
@@ -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
|
|
298
|
+
- Built by [Innovation Trigger B.V.](https://pdfluent.com)
|
package/THIRD_PARTY_LICENSES.txt
CHANGED
|
@@ -133,8 +133,27 @@ Two vendored files, both Adobe's own CMap resources, both BSD-3-Clause:
|
|
|
133
133
|
form, read by the PDF/A fixups for
|
|
134
134
|
EUC-encoded CID text
|
|
135
135
|
Copyright 1990-2019 Adobe
|
|
136
|
+
crates/pdf-manip/resources/predefined-cmaps/pack.z
|
|
137
|
+
the 61 predefined CMaps of the PDF
|
|
138
|
+
specification as one compressed
|
|
139
|
+
pack, built by
|
|
140
|
+
scripts/pdfa/build_cmap_pack.py
|
|
141
|
+
from github.com/adobe-type-tools/
|
|
142
|
+
cmap-resources, commit f5cf3bca
|
|
143
|
+
(BSD-3-Clause); read by the PDF/A
|
|
144
|
+
conversion so it needs no
|
|
145
|
+
poppler-data on the host
|
|
146
|
+
Copyright 1990-2023 Adobe
|
|
147
|
+
crates/pdf-manip/resources/predefined-cmaps/PROVENANCE.sha256
|
|
148
|
+
ours: the SHA-256 of each source
|
|
149
|
+
file and of the pack built from
|
|
150
|
+
them
|
|
151
|
+
crates/pdf-manip/resources/predefined-cmaps/LICENSE-Adobe-CMap.txt
|
|
152
|
+
the full BSD-3-Clause text and
|
|
153
|
+
Adobe's notice for the pack above
|
|
136
154
|
|
|
137
155
|
Upstream licence texts in the tree:
|
|
156
|
+
crates/pdf-manip/resources/predefined-cmaps/LICENSE-Adobe-CMap.txt (BSD-3-Clause, full text)
|
|
138
157
|
crates/pdf-font/assets/LICENSE.txt (BSD-3-Clause, full text)
|
|
139
158
|
crates/pdf-manip/resources/cmap/GB-EUC-H (the notice is the file's own
|
|
140
159
|
header, as Adobe ships it)
|
|
@@ -321,7 +340,8 @@ unic-char-range, unic-common, unic-ucd-ident, unic-ucd-version, unicode-bidi,
|
|
|
321
340
|
unicode-normalization, unicode-properties, unicode-segmentation, unicode-width,
|
|
322
341
|
unicode-xid, url, utf-8, utf8_iter, utf8parse, uuid, vello_common, vello_cpu,
|
|
323
342
|
wasm-bindgen, wasm-bindgen-futures, wasm-bindgen-macro,
|
|
324
|
-
wasm-bindgen-macro-support, wasm-bindgen-shared, wasm-streams,
|
|
343
|
+
wasm-bindgen-macro-support, wasm-bindgen-shared, wasm-streams, wasmi, wasmi_collections, wasmi_core,
|
|
344
|
+
wasmi_ir, web-sys,
|
|
325
345
|
web-time, web_atoms, weezl, winapi, winapi-i686-pc-windows-gnu,
|
|
326
346
|
winapi-x86_64-pc-windows-gnu, window-vibrancy, windows, windows-collections,
|
|
327
347
|
windows-core, windows-future, windows-implement, windows-interface,
|
|
@@ -412,8 +432,7 @@ new_debug_unreachable, nom, nom_locate, noop_proc_macro, nu-ansi-term,
|
|
|
412
432
|
number_prefix, objc2, objc2-encode, objc2-foundation, open, openssl-sys,
|
|
413
433
|
os_pipe, pango, pango-sys, pdf-bench, pdf-desktop, pdf-diff, pdf-java,
|
|
414
434
|
pdfluent-lopdf, phf, phf_generator, phf_macros, phf_shared, plist,
|
|
415
|
-
precomputed-hash, quick-xml, redox_syscall, redox_users, rfd, rgb,
|
|
416
|
-
rquickjs-core, rquickjs-macro, rquickjs-sys, rusqlite, schannel, schemars,
|
|
435
|
+
precomputed-hash, quick-xml, redox_syscall, redox_users, rfd, rgb, rusqlite, schannel, schemars,
|
|
417
436
|
schemars_derive, sharded-slab, shared_child, sigchld, simd-adler32,
|
|
418
437
|
simd_helpers, slab, soup3, soup3-sys, spin, strsim, synstructure, tiff,
|
|
419
438
|
tokio, tokio-macros, tokio-native-tls, tokio-util, tower, tower-http,
|
|
@@ -731,6 +750,44 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
731
750
|
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
732
751
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
733
752
|
|
|
753
|
+
================================================================================
|
|
754
|
+
QuickJS-ng — the script engine, compiled into xfa-js-sandboxed's WebAssembly module
|
|
755
|
+
https://github.com/quickjs-ng/quickjs (version 0.7.0)
|
|
756
|
+
================================================================================
|
|
757
|
+
|
|
758
|
+
QuickJS (MIT) is a component of crates/xfa-js-sandboxed/wasm-guest/qjs_guest.wasm:
|
|
759
|
+
the module is compiled from the C sources in wasm-guest/quickjs/ (two changes,
|
|
760
|
+
listed in wasm-guest/PATCHES.md) and is interpreted by the wasmi crate. No native
|
|
761
|
+
C code runs. The module also contains code from wasi-libc (Apache-2.0 WITH
|
|
762
|
+
LLVM-exception; MIT and BSD-2-Clause parts derived from musl) and LLVM
|
|
763
|
+
compiler-rt (Apache-2.0 WITH LLVM-exception), linked in by the toolchain
|
|
764
|
+
(zig 0.16.0, build tooling only, not shipped). See wasm-guest/NOTICE.
|
|
765
|
+
|
|
766
|
+
The MIT License (MIT)
|
|
767
|
+
|
|
768
|
+
Copyright (c) 2017-2021 Fabrice Bellard
|
|
769
|
+
Copyright (c) 2017-2021 Charlie Gordon
|
|
770
|
+
Copyright (c) 2023 Ben Noordhuis
|
|
771
|
+
Copyright (c) 2023 Saúl Ibarra Corretgé
|
|
772
|
+
|
|
773
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
774
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
775
|
+
in the Software without restriction, including without limitation the rights
|
|
776
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
777
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
778
|
+
furnished to do so, subject to the following conditions:
|
|
779
|
+
|
|
780
|
+
The above copyright notice and this permission notice shall be included in
|
|
781
|
+
all copies or substantial portions of the Software.
|
|
782
|
+
|
|
783
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
784
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
785
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
786
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
787
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
788
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
789
|
+
THE SOFTWARE.
|
|
790
|
+
|
|
734
791
|
================================================================================
|
|
735
792
|
tract — ONNX inference for the optional vision layer (#636)
|
|
736
793
|
https://github.com/sonos/tract
|
|
@@ -842,3 +899,27 @@ SOFTWARE
|
|
|
842
899
|
================================================================================
|
|
843
900
|
END OF THIRD PARTY LICENSES
|
|
844
901
|
================================================================================
|
|
902
|
+
|
|
903
|
+
================================================================================
|
|
904
|
+
qrcodegen 1.8.0 — QR Code generator library (MIT)
|
|
905
|
+
https://www.nayuki.io/page/qr-code-generator-library
|
|
906
|
+
================================================================================
|
|
907
|
+
|
|
908
|
+
Copyright (c) Project Nayuki. (MIT License)
|
|
909
|
+
https://www.nayuki.io/page/qr-code-generator-library
|
|
910
|
+
|
|
911
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
912
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
913
|
+
the Software without restriction, including without limitation the rights to
|
|
914
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
915
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
916
|
+
subject to the following conditions:
|
|
917
|
+
- The above copyright notice and this permission notice shall be included in
|
|
918
|
+
all copies or substantial portions of the Software.
|
|
919
|
+
- The Software is provided "as is", without warranty of any kind, express or
|
|
920
|
+
implied, including but not limited to the warranties of merchantability,
|
|
921
|
+
fitness for a particular purpose and noninfringement. In no event shall the
|
|
922
|
+
authors or copyright holders be liable for any claim, damages or other
|
|
923
|
+
liability, whether in an action of contract, tort or otherwise, arising from,
|
|
924
|
+
out of or in connection with the Software or the use or other dealings in the
|
|
925
|
+
Software.
|
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.
|
|
5
|
+
"version": "1.3.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
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
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
|
@@ -122,7 +122,7 @@ export enum ChromaSampling {
|
|
|
122
122
|
*
|
|
123
123
|
* # Errors
|
|
124
124
|
*
|
|
125
|
-
* All fallible methods throw a `PdfluentError`
|
|
125
|
+
* All fallible methods throw a `PdfluentError` - a standard `Error` subclass with
|
|
126
126
|
* these properties:
|
|
127
127
|
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
128
128
|
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
@@ -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
|
/**
|
|
@@ -368,7 +372,7 @@ export class PdfDoc {
|
|
|
368
372
|
* Render a page directly to an HTML canvas element (wasm32 only).
|
|
369
373
|
*
|
|
370
374
|
* Calls `canvas.getContext("2d")`, sets the canvas dimensions to the
|
|
371
|
-
* rendered pixel size, and calls `putImageData`
|
|
375
|
+
* rendered pixel size, and calls `putImageData` - no round-trip through
|
|
372
376
|
* a JS Uint8Array. XFA documents are auto-flattened before rendering.
|
|
373
377
|
*
|
|
374
378
|
* ```js
|
|
@@ -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
|
*
|
|
@@ -475,7 +489,7 @@ export class PdfDocMut {
|
|
|
475
489
|
addFreeText(page_index: number, x: number, y: number, w: number, h: number, contents: string): void;
|
|
476
490
|
/**
|
|
477
491
|
* Add a highlight annotation over the given page rectangle.
|
|
478
|
-
* `color_hex` like `"#ffeb3b"`
|
|
492
|
+
* `color_hex` like `"#ffeb3b"` - defaults to yellow when `None`.
|
|
479
493
|
*/
|
|
480
494
|
addHighlight(page_index: number, x: number, y: number, w: number, h: number, color_hex?: string | null): void;
|
|
481
495
|
/**
|
|
@@ -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,21 +570,35 @@ 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;
|
|
556
588
|
/**
|
|
557
|
-
*
|
|
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;
|
|
593
|
+
/**
|
|
594
|
+
* G3 - Replace a text span on a page.
|
|
558
595
|
*
|
|
559
596
|
* The editor passes the **exact** text it extracted from
|
|
560
597
|
* `getTextPositions()` as `original_text`, and the desired
|
|
561
598
|
* replacement as `replacement_text`. The replacement is
|
|
562
599
|
* re-encoded into the same font used by the matched span
|
|
563
600
|
* (subset-font fallback applies when the original font cannot
|
|
564
|
-
* encode the replacement
|
|
601
|
+
* encode the replacement - see
|
|
565
602
|
* `pdf-manip::text_replace::replace_text`).
|
|
566
603
|
*
|
|
567
604
|
* `page_num` is **1-based** to match the rest of the
|
|
@@ -582,11 +619,11 @@ export class PdfDocMut {
|
|
|
582
619
|
*
|
|
583
620
|
* Typed unsupported codes (all set `replaced=false`):
|
|
584
621
|
*
|
|
585
|
-
* - `"NO_MATCH"`
|
|
586
|
-
* - `"ENCODING_UNSUPPORTED"`
|
|
622
|
+
* - `"NO_MATCH"` - `original_text` not found on the page.
|
|
623
|
+
* - `"ENCODING_UNSUPPORTED"` - replacement contains characters
|
|
587
624
|
* the matched font cannot encode and no fallback font is
|
|
588
625
|
* available.
|
|
589
|
-
* - `"REPLACE_FAILED"`
|
|
626
|
+
* - `"REPLACE_FAILED"` - anything else (lopdf I/O,
|
|
590
627
|
* serialisation, FontMap construction, …). `reason` carries
|
|
591
628
|
* the lower-level error message.
|
|
592
629
|
*
|
|
@@ -611,7 +648,7 @@ export class PdfDocMut {
|
|
|
611
648
|
/**
|
|
612
649
|
* Set a single AcroForm field value (text, checkbox, radio, or choice).
|
|
613
650
|
*
|
|
614
|
-
* Delegates to [`pdf_forms::apply_field_value`]
|
|
651
|
+
* Delegates to [`pdf_forms::apply_field_value`] - the single SDK
|
|
615
652
|
* writeback chain. It keeps `/V` (ASCII literal else UTF-16BE+BOM),
|
|
616
653
|
* per-widget `/AS`, and regenerated `/AP` streams consistent, resolves
|
|
617
654
|
* fully-qualified names through `/Kids`, and rejects read-only fields.
|
|
@@ -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
|
*
|
|
@@ -723,7 +767,7 @@ export class TextEditor {
|
|
|
723
767
|
*
|
|
724
768
|
* # Errors
|
|
725
769
|
*
|
|
726
|
-
* All fallible methods throw a `PdfluentError`
|
|
770
|
+
* All fallible methods throw a `PdfluentError` - a standard `Error` subclass with
|
|
727
771
|
* these properties:
|
|
728
772
|
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
729
773
|
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
@@ -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-
|
|
2
|
+
import { __pdfluent_error_ctor } from './snippets/xfa-wasm-d23d7ce846a87fdd/inline0.js';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -45,7 +45,7 @@ export const ChromaSampling = Object.freeze({
|
|
|
45
45
|
*
|
|
46
46
|
* # Errors
|
|
47
47
|
*
|
|
48
|
-
* All fallible methods throw a `PdfluentError`
|
|
48
|
+
* All fallible methods throw a `PdfluentError` - a standard `Error` subclass with
|
|
49
49
|
* these properties:
|
|
50
50
|
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
51
51
|
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
@@ -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
|
*/
|
|
@@ -819,7 +823,7 @@ export class PdfDoc {
|
|
|
819
823
|
* Render a page directly to an HTML canvas element (wasm32 only).
|
|
820
824
|
*
|
|
821
825
|
* Calls `canvas.getContext("2d")`, sets the canvas dimensions to the
|
|
822
|
-
* rendered pixel size, and calls `putImageData`
|
|
826
|
+
* rendered pixel size, and calls `putImageData` - no round-trip through
|
|
823
827
|
* a JS Uint8Array. XFA documents are auto-flattened before rendering.
|
|
824
828
|
*
|
|
825
829
|
* ```js
|
|
@@ -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
|
*
|
|
@@ -1228,7 +1266,7 @@ export class PdfDocMut {
|
|
|
1228
1266
|
}
|
|
1229
1267
|
/**
|
|
1230
1268
|
* Add a highlight annotation over the given page rectangle.
|
|
1231
|
-
* `color_hex` like `"#ffeb3b"`
|
|
1269
|
+
* `color_hex` like `"#ffeb3b"` - defaults to yellow when `None`.
|
|
1232
1270
|
* @param {number} page_index
|
|
1233
1271
|
* @param {number} x
|
|
1234
1272
|
* @param {number} y
|
|
@@ -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
|
|
@@ -1560,14 +1657,50 @@ export class PdfDocMut {
|
|
|
1560
1657
|
}
|
|
1561
1658
|
}
|
|
1562
1659
|
/**
|
|
1563
|
-
*
|
|
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
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* G3 - Replace a text span on a page.
|
|
1564
1697
|
*
|
|
1565
1698
|
* The editor passes the **exact** text it extracted from
|
|
1566
1699
|
* `getTextPositions()` as `original_text`, and the desired
|
|
1567
1700
|
* replacement as `replacement_text`. The replacement is
|
|
1568
1701
|
* re-encoded into the same font used by the matched span
|
|
1569
1702
|
* (subset-font fallback applies when the original font cannot
|
|
1570
|
-
* encode the replacement
|
|
1703
|
+
* encode the replacement - see
|
|
1571
1704
|
* `pdf-manip::text_replace::replace_text`).
|
|
1572
1705
|
*
|
|
1573
1706
|
* `page_num` is **1-based** to match the rest of the
|
|
@@ -1588,11 +1721,11 @@ export class PdfDocMut {
|
|
|
1588
1721
|
*
|
|
1589
1722
|
* Typed unsupported codes (all set `replaced=false`):
|
|
1590
1723
|
*
|
|
1591
|
-
* - `"NO_MATCH"`
|
|
1592
|
-
* - `"ENCODING_UNSUPPORTED"`
|
|
1724
|
+
* - `"NO_MATCH"` - `original_text` not found on the page.
|
|
1725
|
+
* - `"ENCODING_UNSUPPORTED"` - replacement contains characters
|
|
1593
1726
|
* the matched font cannot encode and no fallback font is
|
|
1594
1727
|
* available.
|
|
1595
|
-
* - `"REPLACE_FAILED"`
|
|
1728
|
+
* - `"REPLACE_FAILED"` - anything else (lopdf I/O,
|
|
1596
1729
|
* serialisation, FontMap construction, …). `reason` carries
|
|
1597
1730
|
* the lower-level error message.
|
|
1598
1731
|
*
|
|
@@ -1680,7 +1813,7 @@ export class PdfDocMut {
|
|
|
1680
1813
|
/**
|
|
1681
1814
|
* Set a single AcroForm field value (text, checkbox, radio, or choice).
|
|
1682
1815
|
*
|
|
1683
|
-
* Delegates to [`pdf_forms::apply_field_value`]
|
|
1816
|
+
* Delegates to [`pdf_forms::apply_field_value`] - the single SDK
|
|
1684
1817
|
* writeback chain. It keeps `/V` (ASCII literal else UTF-16BE+BOM),
|
|
1685
1818
|
* per-widget `/AS`, and regenerated `/AP` streams consistent, resolves
|
|
1686
1819
|
* fully-qualified names through `/Kids`, and rejects read-only fields.
|
|
@@ -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
|
*
|
|
@@ -2019,7 +2191,7 @@ if (Symbol.dispose) TextEditor.prototype[Symbol.dispose] = TextEditor.prototype.
|
|
|
2019
2191
|
*
|
|
2020
2192
|
* # Errors
|
|
2021
2193
|
*
|
|
2022
|
-
* All fallible methods throw a `PdfluentError`
|
|
2194
|
+
* All fallible methods throw a `PdfluentError` - a standard `Error` subclass with
|
|
2023
2195
|
* these properties:
|
|
2024
2196
|
* - `code`: stable C8 catalogue identifier in `E-<CATEGORY>-<SPECIFIC>` format
|
|
2025
2197
|
* (e.g. `"E-PARSE-INVALID-PDF"`). Use this for programmatic dispatch.
|
|
@@ -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
|
-
|
|
2591
|
+
__wbg___pdfluent_error_ctor_ed1ceb6e41324c5c: function() {
|
|
2420
2592
|
const ret = __pdfluent_error_ctor();
|
|
2421
2593
|
return addHeapObject(ret);
|
|
2422
2594
|
},
|
package/xfa_wasm_bg.wasm
CHANGED
|
Binary file
|
package/xfa_wasm_bg.wasm.d.ts
CHANGED
|
@@ -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;
|
|
File without changes
|