@formepdf/core 0.9.2 → 0.10.1
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/dist/browser.d.ts +11 -25
- package/dist/browser.js +30 -175
- package/dist/index.js +13 -32
- package/dist/shared/browserHelpers.d.ts +19 -0
- package/dist/shared/browserHelpers.js +128 -0
- package/dist/worker.d.ts +68 -0
- package/dist/worker.js +158 -0
- package/package.json +27 -12
- package/pkg/forme.d.ts +0 -46
- package/pkg/forme.js +7 -477
- package/pkg/forme_bg.js +379 -0
- package/pkg/forme_bg.wasm +0 -0
- package/pkg/package.json +3 -1
- package/pkg-node/LICENSE +21 -0
- package/pkg-node/README.md +84 -0
- package/pkg-node/forme.d.ts +39 -0
- package/pkg-node/forme.js +394 -0
- package/pkg-node/forme_bg.wasm +0 -0
- package/pkg-node/forme_bg.wasm.d.ts +21 -0
- package/pkg-node/package.json +25 -0
- package/pkg-web/LICENSE +21 -0
- package/pkg-web/README.md +84 -0
- package/pkg-web/forme.d.ts +85 -0
- package/pkg-web/forme.js +479 -0
- package/pkg-web/forme_bg.wasm +0 -0
- package/pkg-web/forme_bg.wasm.d.ts +21 -0
- package/pkg-web/package.json +29 -0
- package/scripts/assert-tarball.sh +62 -0
package/pkg/forme_bg.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
|
|
3
|
+
* @param {Uint8Array} pdf_bytes
|
|
4
|
+
* @param {string} config_json
|
|
5
|
+
* @returns {Uint8Array}
|
|
6
|
+
*/
|
|
7
|
+
export function certify_pdf(pdf_bytes, config_json) {
|
|
8
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
9
|
+
const len0 = WASM_VECTOR_LEN;
|
|
10
|
+
const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
11
|
+
const len1 = WASM_VECTOR_LEN;
|
|
12
|
+
const ret = wasm.certify_pdf(ptr0, len0, ptr1, len1);
|
|
13
|
+
if (ret[3]) {
|
|
14
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
15
|
+
}
|
|
16
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
17
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
18
|
+
return v3;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Find text regions matching patterns in a PDF.
|
|
23
|
+
* Returns JSON string of Vec<RedactionRegion>.
|
|
24
|
+
* @param {Uint8Array} pdf_bytes
|
|
25
|
+
* @param {string} patterns_json
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
export function find_text_regions(pdf_bytes, patterns_json) {
|
|
29
|
+
let deferred4_0;
|
|
30
|
+
let deferred4_1;
|
|
31
|
+
try {
|
|
32
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
33
|
+
const len0 = WASM_VECTOR_LEN;
|
|
34
|
+
const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
35
|
+
const len1 = WASM_VECTOR_LEN;
|
|
36
|
+
const ret = wasm.find_text_regions(ptr0, len0, ptr1, len1);
|
|
37
|
+
var ptr3 = ret[0];
|
|
38
|
+
var len3 = ret[1];
|
|
39
|
+
if (ret[3]) {
|
|
40
|
+
ptr3 = 0; len3 = 0;
|
|
41
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
42
|
+
}
|
|
43
|
+
deferred4_0 = ptr3;
|
|
44
|
+
deferred4_1 = len3;
|
|
45
|
+
return getStringFromWasm0(ptr3, len3);
|
|
46
|
+
} finally {
|
|
47
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function init_panic_hook() {
|
|
52
|
+
wasm.init_panic_hook();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Merge multiple PDFs into a single document.
|
|
57
|
+
* Accepts a JSON array of base64-encoded PDF strings.
|
|
58
|
+
* @param {string} pdfs_json
|
|
59
|
+
* @returns {Uint8Array}
|
|
60
|
+
*/
|
|
61
|
+
export function merge_pdfs(pdfs_json) {
|
|
62
|
+
const ptr0 = passStringToWasm0(pdfs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
63
|
+
const len0 = WASM_VECTOR_LEN;
|
|
64
|
+
const ret = wasm.merge_pdfs(ptr0, len0);
|
|
65
|
+
if (ret[3]) {
|
|
66
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
67
|
+
}
|
|
68
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
69
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
70
|
+
return v2;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Redact regions of a PDF by overlaying opaque rectangles.
|
|
75
|
+
* @param {Uint8Array} pdf_bytes
|
|
76
|
+
* @param {string} redactions_json
|
|
77
|
+
* @returns {Uint8Array}
|
|
78
|
+
*/
|
|
79
|
+
export function redact_pdf(pdf_bytes, redactions_json) {
|
|
80
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
81
|
+
const len0 = WASM_VECTOR_LEN;
|
|
82
|
+
const ptr1 = passStringToWasm0(redactions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
83
|
+
const len1 = WASM_VECTOR_LEN;
|
|
84
|
+
const ret = wasm.redact_pdf(ptr0, len0, ptr1, len1);
|
|
85
|
+
if (ret[3]) {
|
|
86
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
87
|
+
}
|
|
88
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
89
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
90
|
+
return v3;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Redact text matching patterns from a PDF.
|
|
95
|
+
* @param {Uint8Array} pdf_bytes
|
|
96
|
+
* @param {string} patterns_json
|
|
97
|
+
* @returns {Uint8Array}
|
|
98
|
+
*/
|
|
99
|
+
export function redact_text(pdf_bytes, patterns_json) {
|
|
100
|
+
const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
|
|
101
|
+
const len0 = WASM_VECTOR_LEN;
|
|
102
|
+
const ptr1 = passStringToWasm0(patterns_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
103
|
+
const len1 = WASM_VECTOR_LEN;
|
|
104
|
+
const ret = wasm.redact_text(ptr0, len0, ptr1, len1);
|
|
105
|
+
if (ret[3]) {
|
|
106
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
107
|
+
}
|
|
108
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
109
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
110
|
+
return v3;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {string} json
|
|
115
|
+
* @returns {Uint8Array}
|
|
116
|
+
*/
|
|
117
|
+
export function render_pdf(json) {
|
|
118
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
119
|
+
const len0 = WASM_VECTOR_LEN;
|
|
120
|
+
const ret = wasm.render_pdf(ptr0, len0);
|
|
121
|
+
if (ret[3]) {
|
|
122
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
123
|
+
}
|
|
124
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
125
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
126
|
+
return v2;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} json
|
|
131
|
+
* @returns {any}
|
|
132
|
+
*/
|
|
133
|
+
export function render_pdf_with_layout(json) {
|
|
134
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
135
|
+
const len0 = WASM_VECTOR_LEN;
|
|
136
|
+
const ret = wasm.render_pdf_with_layout(ptr0, len0);
|
|
137
|
+
if (ret[2]) {
|
|
138
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
139
|
+
}
|
|
140
|
+
return takeFromExternrefTable0(ret[0]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {string} template_json
|
|
145
|
+
* @param {string} data_json
|
|
146
|
+
* @returns {Uint8Array}
|
|
147
|
+
*/
|
|
148
|
+
export function render_template_pdf(template_json, data_json) {
|
|
149
|
+
const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
150
|
+
const len0 = WASM_VECTOR_LEN;
|
|
151
|
+
const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
152
|
+
const len1 = WASM_VECTOR_LEN;
|
|
153
|
+
const ret = wasm.render_template_pdf(ptr0, len0, ptr1, len1);
|
|
154
|
+
if (ret[3]) {
|
|
155
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
156
|
+
}
|
|
157
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
158
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
159
|
+
return v3;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {string} template_json
|
|
164
|
+
* @param {string} data_json
|
|
165
|
+
* @returns {any}
|
|
166
|
+
*/
|
|
167
|
+
export function render_template_pdf_with_layout(template_json, data_json) {
|
|
168
|
+
const ptr0 = passStringToWasm0(template_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
169
|
+
const len0 = WASM_VECTOR_LEN;
|
|
170
|
+
const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
171
|
+
const len1 = WASM_VECTOR_LEN;
|
|
172
|
+
const ret = wasm.render_template_pdf_with_layout(ptr0, len0, ptr1, len1);
|
|
173
|
+
if (ret[2]) {
|
|
174
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
175
|
+
}
|
|
176
|
+
return takeFromExternrefTable0(ret[0]);
|
|
177
|
+
}
|
|
178
|
+
export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
|
|
179
|
+
const ret = String(arg1);
|
|
180
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
181
|
+
const len1 = WASM_VECTOR_LEN;
|
|
182
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
183
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
184
|
+
}
|
|
185
|
+
export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
|
|
186
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
187
|
+
}
|
|
188
|
+
export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) {
|
|
189
|
+
let deferred0_0;
|
|
190
|
+
let deferred0_1;
|
|
191
|
+
try {
|
|
192
|
+
deferred0_0 = arg0;
|
|
193
|
+
deferred0_1 = arg1;
|
|
194
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
195
|
+
} finally {
|
|
196
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
export function __wbg_new_361308b2356cecd0() {
|
|
200
|
+
const ret = new Object();
|
|
201
|
+
return ret;
|
|
202
|
+
}
|
|
203
|
+
export function __wbg_new_3eb36ae241fe6f44() {
|
|
204
|
+
const ret = new Array();
|
|
205
|
+
return ret;
|
|
206
|
+
}
|
|
207
|
+
export function __wbg_new_8a6f238a6ece86ea() {
|
|
208
|
+
const ret = new Error();
|
|
209
|
+
return ret;
|
|
210
|
+
}
|
|
211
|
+
export function __wbg_new_from_slice_a3d2629dc1826784(arg0, arg1) {
|
|
212
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
213
|
+
return ret;
|
|
214
|
+
}
|
|
215
|
+
export function __wbg_now_a3af9a2f4bbaa4d1() {
|
|
216
|
+
const ret = Date.now();
|
|
217
|
+
return ret;
|
|
218
|
+
}
|
|
219
|
+
export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) {
|
|
220
|
+
arg0[arg1] = arg2;
|
|
221
|
+
}
|
|
222
|
+
export function __wbg_set_6cb8631f80447a67() { return handleError(function (arg0, arg1, arg2) {
|
|
223
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
224
|
+
return ret;
|
|
225
|
+
}, arguments); }
|
|
226
|
+
export function __wbg_set_f43e577aea94465b(arg0, arg1, arg2) {
|
|
227
|
+
arg0[arg1 >>> 0] = arg2;
|
|
228
|
+
}
|
|
229
|
+
export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
|
|
230
|
+
const ret = arg1.stack;
|
|
231
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
232
|
+
const len1 = WASM_VECTOR_LEN;
|
|
233
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
234
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
235
|
+
}
|
|
236
|
+
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
237
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
238
|
+
const ret = arg0;
|
|
239
|
+
return ret;
|
|
240
|
+
}
|
|
241
|
+
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
|
242
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
243
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
244
|
+
return ret;
|
|
245
|
+
}
|
|
246
|
+
export function __wbindgen_init_externref_table() {
|
|
247
|
+
const table = wasm.__wbindgen_externrefs;
|
|
248
|
+
const offset = table.grow(4);
|
|
249
|
+
table.set(0, undefined);
|
|
250
|
+
table.set(offset + 0, undefined);
|
|
251
|
+
table.set(offset + 1, null);
|
|
252
|
+
table.set(offset + 2, true);
|
|
253
|
+
table.set(offset + 3, false);
|
|
254
|
+
}
|
|
255
|
+
function addToExternrefTable0(obj) {
|
|
256
|
+
const idx = wasm.__externref_table_alloc();
|
|
257
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
258
|
+
return idx;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
262
|
+
ptr = ptr >>> 0;
|
|
263
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let cachedDataViewMemory0 = null;
|
|
267
|
+
function getDataViewMemory0() {
|
|
268
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
269
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
270
|
+
}
|
|
271
|
+
return cachedDataViewMemory0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function getStringFromWasm0(ptr, len) {
|
|
275
|
+
ptr = ptr >>> 0;
|
|
276
|
+
return decodeText(ptr, len);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let cachedUint8ArrayMemory0 = null;
|
|
280
|
+
function getUint8ArrayMemory0() {
|
|
281
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
282
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
283
|
+
}
|
|
284
|
+
return cachedUint8ArrayMemory0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function handleError(f, args) {
|
|
288
|
+
try {
|
|
289
|
+
return f.apply(this, args);
|
|
290
|
+
} catch (e) {
|
|
291
|
+
const idx = addToExternrefTable0(e);
|
|
292
|
+
wasm.__wbindgen_exn_store(idx);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
297
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
298
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
299
|
+
WASM_VECTOR_LEN = arg.length;
|
|
300
|
+
return ptr;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
304
|
+
if (realloc === undefined) {
|
|
305
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
306
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
307
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
308
|
+
WASM_VECTOR_LEN = buf.length;
|
|
309
|
+
return ptr;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let len = arg.length;
|
|
313
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
314
|
+
|
|
315
|
+
const mem = getUint8ArrayMemory0();
|
|
316
|
+
|
|
317
|
+
let offset = 0;
|
|
318
|
+
|
|
319
|
+
for (; offset < len; offset++) {
|
|
320
|
+
const code = arg.charCodeAt(offset);
|
|
321
|
+
if (code > 0x7F) break;
|
|
322
|
+
mem[ptr + offset] = code;
|
|
323
|
+
}
|
|
324
|
+
if (offset !== len) {
|
|
325
|
+
if (offset !== 0) {
|
|
326
|
+
arg = arg.slice(offset);
|
|
327
|
+
}
|
|
328
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
329
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
330
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
331
|
+
|
|
332
|
+
offset += ret.written;
|
|
333
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
WASM_VECTOR_LEN = offset;
|
|
337
|
+
return ptr;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function takeFromExternrefTable0(idx) {
|
|
341
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
342
|
+
wasm.__externref_table_dealloc(idx);
|
|
343
|
+
return value;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
347
|
+
cachedTextDecoder.decode();
|
|
348
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
349
|
+
let numBytesDecoded = 0;
|
|
350
|
+
function decodeText(ptr, len) {
|
|
351
|
+
numBytesDecoded += len;
|
|
352
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
353
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
354
|
+
cachedTextDecoder.decode();
|
|
355
|
+
numBytesDecoded = len;
|
|
356
|
+
}
|
|
357
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const cachedTextEncoder = new TextEncoder();
|
|
361
|
+
|
|
362
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
363
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
364
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
365
|
+
view.set(buf);
|
|
366
|
+
return {
|
|
367
|
+
read: arg.length,
|
|
368
|
+
written: buf.length
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
let WASM_VECTOR_LEN = 0;
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
let wasm;
|
|
377
|
+
export function __wbg_set_wasm(val) {
|
|
378
|
+
wasm = val;
|
|
379
|
+
}
|
package/pkg/forme_bg.wasm
CHANGED
|
Binary file
|
package/pkg/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "forme-pdf",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "A page-native PDF rendering engine. Layout INTO pages, not onto an infinite canvas.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.10.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"forme_bg.wasm",
|
|
13
13
|
"forme.js",
|
|
14
|
+
"forme_bg.js",
|
|
14
15
|
"forme.d.ts"
|
|
15
16
|
],
|
|
16
17
|
"main": "forme.js",
|
|
17
18
|
"homepage": "https://formepdf.com",
|
|
18
19
|
"types": "forme.d.ts",
|
|
19
20
|
"sideEffects": [
|
|
21
|
+
"./forme.js",
|
|
20
22
|
"./snippets/*"
|
|
21
23
|
],
|
|
22
24
|
"keywords": [
|
package/pkg-node/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Molitor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# forme-pdf
|
|
2
|
+
|
|
3
|
+
A page-native PDF rendering engine written in Rust. Layout happens **into** pages, not onto an infinite canvas that gets sliced afterward — so page breaks, table headers, and flex layout all work correctly across pages.
|
|
4
|
+
|
|
5
|
+
`cargo add forme-pdf` installs the crate. The library name is `forme`:
|
|
6
|
+
|
|
7
|
+
```rust
|
|
8
|
+
use forme::{render_json, Document, FormeError};
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Page-native layout** — flexbox, tables, and text reflow with real page boundary awareness
|
|
14
|
+
- **CSS-like styling** — flexbox (`row`/`column`, `wrap`, `grow`/`shrink`), CSS Grid, absolute positioning
|
|
15
|
+
- **Text** — OpenType shaping, Knuth-Plass line breaking, hyphenation (35+ languages), BiDi, per-character font fallback
|
|
16
|
+
- **Tables** — automatic header repetition on page breaks, column spans
|
|
17
|
+
- **Images** — JPEG, PNG, WebP (embedded or data URI)
|
|
18
|
+
- **SVG** — inline SVG rendering (rect, circle, line, path, arc)
|
|
19
|
+
- **Charts** — BarChart, LineChart, PieChart, AreaChart, DotPlot (engine-native, no JS)
|
|
20
|
+
- **QR codes & barcodes** — vector rendering (Code128, Code39, EAN13, EAN8, Codabar)
|
|
21
|
+
- **Canvas** — arbitrary vector drawing via a Canvas-like API
|
|
22
|
+
- **Watermarks** — rotated text behind page content
|
|
23
|
+
- **AcroForms** — fillable PDF forms (TextField, Checkbox, Dropdown, RadioButton) with form flattening
|
|
24
|
+
- **PDF/UA-1** — accessibility compliance with structure tree, tab order, role map, artifact tagging
|
|
25
|
+
- **PDF/A** — archival compliance (PDF/A-2b, PDF/A-2a) with full font embedding and XMP metadata
|
|
26
|
+
- **Digital signatures** — PKCS#7 detached signatures with X.509 certificates
|
|
27
|
+
- **Templates** — expression language for dynamic documents (`$ref`, `$each`, `$if`)
|
|
28
|
+
- **WASM** — compiles to WebAssembly for browser and serverless use
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```rust
|
|
33
|
+
use forme::{render_json, FormeError};
|
|
34
|
+
|
|
35
|
+
fn main() -> Result<(), FormeError> {
|
|
36
|
+
let json = r#"{
|
|
37
|
+
"pages": [{ "size": "A4" }],
|
|
38
|
+
"children": [{
|
|
39
|
+
"kind": "text",
|
|
40
|
+
"content": "Hello from Forme!",
|
|
41
|
+
"style": { "fontSize": 24, "margin": { "top": 72, "left": 72 } }
|
|
42
|
+
}]
|
|
43
|
+
}"#;
|
|
44
|
+
|
|
45
|
+
let pdf_bytes = render_json(json)?;
|
|
46
|
+
std::fs::write("hello.pdf", pdf_bytes).unwrap();
|
|
47
|
+
Ok(())
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### Rendering
|
|
54
|
+
|
|
55
|
+
| Function | Description |
|
|
56
|
+
|----------|-------------|
|
|
57
|
+
| `render(&Document)` | Render a document struct to PDF bytes |
|
|
58
|
+
| `render_json(&str)` | Parse JSON and render to PDF bytes |
|
|
59
|
+
| `render_with_layout(&Document)` | Render and return PDF bytes + layout metadata |
|
|
60
|
+
| `render_json_with_layout(&str)` | Parse JSON, render, and return PDF bytes + layout metadata |
|
|
61
|
+
| `render_template(&str, &str)` | Evaluate a template with data, then render |
|
|
62
|
+
| `render_template_with_layout(&str, &str)` | Evaluate a template with data, render, and return PDF bytes + layout metadata |
|
|
63
|
+
|
|
64
|
+
### PDF Operations
|
|
65
|
+
|
|
66
|
+
| Function | Description |
|
|
67
|
+
|----------|-------------|
|
|
68
|
+
| `merge_pdfs(&[&[u8]])` | Combine multiple PDFs into one |
|
|
69
|
+
| `certify_pdf(&[u8], &str, &str, ...)` | Apply a PKCS#7 digital signature to an existing PDF |
|
|
70
|
+
| `redact_pdf(&[u8], &[RedactionRegion])` | Redact regions from a PDF (removes underlying text) |
|
|
71
|
+
| `redact_text(&[u8], &[TextSearchRedaction])` | Find text by pattern and redact matching regions |
|
|
72
|
+
| `find_text_regions(&[u8], &[TextSearchPattern])` | Find text regions in a PDF without redacting |
|
|
73
|
+
|
|
74
|
+
All functions return `Result<Vec<u8>, FormeError>` (or a tuple with `LayoutInfo` for the `_with_layout` variants).
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
- [Full docs](https://docs.formepdf.com) — component reference, styling guide, examples
|
|
79
|
+
- [API reference](https://docs.rs/forme-pdf) — Rust API docs
|
|
80
|
+
- [GitHub](https://github.com/formepdf/forme) — source, issues, JSX/TypeScript packages
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Certify PDF bytes with an X.509 certificate (PKCS#7 detached signature).
|
|
6
|
+
*/
|
|
7
|
+
export function certify_pdf(pdf_bytes: Uint8Array, config_json: string): Uint8Array;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Find text regions matching patterns in a PDF.
|
|
11
|
+
* Returns JSON string of Vec<RedactionRegion>.
|
|
12
|
+
*/
|
|
13
|
+
export function find_text_regions(pdf_bytes: Uint8Array, patterns_json: string): string;
|
|
14
|
+
|
|
15
|
+
export function init_panic_hook(): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Merge multiple PDFs into a single document.
|
|
19
|
+
* Accepts a JSON array of base64-encoded PDF strings.
|
|
20
|
+
*/
|
|
21
|
+
export function merge_pdfs(pdfs_json: string): Uint8Array;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Redact regions of a PDF by overlaying opaque rectangles.
|
|
25
|
+
*/
|
|
26
|
+
export function redact_pdf(pdf_bytes: Uint8Array, redactions_json: string): Uint8Array;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Redact text matching patterns from a PDF.
|
|
30
|
+
*/
|
|
31
|
+
export function redact_text(pdf_bytes: Uint8Array, patterns_json: string): Uint8Array;
|
|
32
|
+
|
|
33
|
+
export function render_pdf(json: string): Uint8Array;
|
|
34
|
+
|
|
35
|
+
export function render_pdf_with_layout(json: string): any;
|
|
36
|
+
|
|
37
|
+
export function render_template_pdf(template_json: string, data_json: string): Uint8Array;
|
|
38
|
+
|
|
39
|
+
export function render_template_pdf_with_layout(template_json: string, data_json: string): any;
|