@lpdfio/lpdf 0.0.3
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/LICENSE +131 -0
- package/README.md +60 -0
- package/dist/_shared.d.ts +28 -0
- package/dist/_shared.js +5 -0
- package/dist/browser.js +468 -0
- package/dist/canvas.d.ts +131 -0
- package/dist/canvas.js +181 -0
- package/dist/engine.d.ts +70 -0
- package/dist/engine.js +191 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +34 -0
- package/dist/kit-to-xml.d.ts +30 -0
- package/dist/kit-to-xml.js +37 -0
- package/dist/kit.d.ts +109 -0
- package/dist/kit.js +78 -0
- package/dist/layout.d.ts +260 -0
- package/dist/layout.js +131 -0
- package/dist/wasm/lpdf-web.js +460 -0
- package/dist/wasm/lpdf.d.ts +95 -0
- package/dist/wasm/lpdf.js +368 -0
- package/dist/wasm/lpdf_bg.wasm +0 -0
- package/package.json +45 -0
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/* @ts-self-types="./lpdf.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class LpdfEngine {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
LpdfEngineFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_lpdfengine_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Remove any previously configured encryption.
|
|
16
|
+
*/
|
|
17
|
+
clear_encryption() {
|
|
18
|
+
wasm.lpdfengine_clear_encryption(this.__wbg_ptr);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register raw font bytes (TTF/OTF) for a custom font name.
|
|
22
|
+
* Call this once per font before calling `render_pdf`.
|
|
23
|
+
* Glyph advance-width metrics are extracted automatically from the font
|
|
24
|
+
* bytes so the layout engine can measure text accurately — no separate
|
|
25
|
+
* `set_font_metrics` call is required.
|
|
26
|
+
* @param {string} name
|
|
27
|
+
* @param {Uint8Array} bytes
|
|
28
|
+
*/
|
|
29
|
+
load_font(name, bytes) {
|
|
30
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
31
|
+
const len0 = WASM_VECTOR_LEN;
|
|
32
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
33
|
+
const len1 = WASM_VECTOR_LEN;
|
|
34
|
+
wasm.lpdfengine_load_font(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register raw image bytes (JPEG or PNG) for an image name.
|
|
38
|
+
* Call this for every image referenced by `<img name="…">` nodes.
|
|
39
|
+
* @param {string} name
|
|
40
|
+
* @param {Uint8Array} bytes
|
|
41
|
+
*/
|
|
42
|
+
load_image(name, bytes) {
|
|
43
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
44
|
+
const len0 = WASM_VECTOR_LEN;
|
|
45
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
46
|
+
const len1 = WASM_VECTOR_LEN;
|
|
47
|
+
wasm.lpdfengine_load_image(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @param {string} license_key
|
|
51
|
+
*/
|
|
52
|
+
constructor(license_key) {
|
|
53
|
+
const ptr0 = passStringToWasm0(license_key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
54
|
+
const len0 = WASM_VECTOR_LEN;
|
|
55
|
+
const ret = wasm.lpdfengine_new(ptr0, len0);
|
|
56
|
+
this.__wbg_ptr = ret >>> 0;
|
|
57
|
+
LpdfEngineFinalization.register(this, this.__wbg_ptr, this);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} xml
|
|
62
|
+
* @returns {string}
|
|
63
|
+
*/
|
|
64
|
+
render(xml) {
|
|
65
|
+
let deferred2_0;
|
|
66
|
+
let deferred2_1;
|
|
67
|
+
try {
|
|
68
|
+
const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
69
|
+
const len0 = WASM_VECTOR_LEN;
|
|
70
|
+
const ret = wasm.lpdfengine_render(this.__wbg_ptr, ptr0, len0);
|
|
71
|
+
deferred2_0 = ret[0];
|
|
72
|
+
deferred2_1 = ret[1];
|
|
73
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
74
|
+
} finally {
|
|
75
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Render `xml` to binary PDF bytes.
|
|
80
|
+
*
|
|
81
|
+
* Any custom fonts referenced in `<font src="…">` declarations must have
|
|
82
|
+
* their bytes registered via `load_font` before calling this method.
|
|
83
|
+
*
|
|
84
|
+
* `json_data` is an optional JSON string used to resolve `data-*`
|
|
85
|
+
* attributes in the template. Pass `None` (or `null` / `undefined` from
|
|
86
|
+
* JavaScript) to render the template with its inline fallback content.
|
|
87
|
+
* @param {string} xml
|
|
88
|
+
* @param {string | null} [json_data]
|
|
89
|
+
* @returns {Uint8Array}
|
|
90
|
+
*/
|
|
91
|
+
render_pdf(xml, json_data) {
|
|
92
|
+
const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
93
|
+
const len0 = WASM_VECTOR_LEN;
|
|
94
|
+
var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
95
|
+
var len1 = WASM_VECTOR_LEN;
|
|
96
|
+
const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
97
|
+
if (ret[3]) {
|
|
98
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
99
|
+
}
|
|
100
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
101
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
102
|
+
return v3;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} json
|
|
106
|
+
* @returns {string}
|
|
107
|
+
*/
|
|
108
|
+
render_tree(json) {
|
|
109
|
+
let deferred2_0;
|
|
110
|
+
let deferred2_1;
|
|
111
|
+
try {
|
|
112
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
113
|
+
const len0 = WASM_VECTOR_LEN;
|
|
114
|
+
const ret = wasm.lpdfengine_render_tree(this.__wbg_ptr, ptr0, len0);
|
|
115
|
+
deferred2_0 = ret[0];
|
|
116
|
+
deferred2_1 = ret[1];
|
|
117
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
118
|
+
} finally {
|
|
119
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Render a JSON kit-tree or canvas-tree document to PDF bytes.
|
|
124
|
+
*
|
|
125
|
+
* This is the JSON counterpart of `render_pdf`. The Node adapter uses it
|
|
126
|
+
* when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
|
|
127
|
+
* intermediate XML serialisation step. PHP, Python, and .NET adapters also
|
|
128
|
+
* use this entry point.
|
|
129
|
+
* @param {string} json
|
|
130
|
+
* @returns {Uint8Array}
|
|
131
|
+
*/
|
|
132
|
+
render_tree_pdf(json) {
|
|
133
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
134
|
+
const len0 = WASM_VECTOR_LEN;
|
|
135
|
+
const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0);
|
|
136
|
+
if (ret[3]) {
|
|
137
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
138
|
+
}
|
|
139
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
140
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
141
|
+
return v2;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
|
|
145
|
+
* When provided, written as `/CreationDate` in the PDF info dictionary.
|
|
146
|
+
* Omitting this keeps builds reproducible (no embedded timestamp).
|
|
147
|
+
* @param {string} iso
|
|
148
|
+
*/
|
|
149
|
+
set_created_on(iso) {
|
|
150
|
+
const ptr0 = passStringToWasm0(iso, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
151
|
+
const len0 = WASM_VECTOR_LEN;
|
|
152
|
+
wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Configure RC4-128 encryption applied to every subsequent `render_pdf` call.
|
|
156
|
+
*
|
|
157
|
+
* `permissions_json` is a JSON object with boolean fields matching the
|
|
158
|
+
* `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
|
|
159
|
+
* `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
|
|
160
|
+
*
|
|
161
|
+
* To apply permissions without an open password, pass an empty `user_password`
|
|
162
|
+
* and a non-empty `owner_password`.
|
|
163
|
+
* @param {string} user_password
|
|
164
|
+
* @param {string} owner_password
|
|
165
|
+
* @param {string} permissions_json
|
|
166
|
+
*/
|
|
167
|
+
set_encryption(user_password, owner_password, permissions_json) {
|
|
168
|
+
const ptr0 = passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
169
|
+
const len0 = WASM_VECTOR_LEN;
|
|
170
|
+
const ptr1 = passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
171
|
+
const len1 = WASM_VECTOR_LEN;
|
|
172
|
+
const ptr2 = passStringToWasm0(permissions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
173
|
+
const len2 = WASM_VECTOR_LEN;
|
|
174
|
+
wasm.lpdfengine_set_encryption(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Inject glyph advance-width tables for custom fonts.
|
|
178
|
+
*
|
|
179
|
+
* Call this *before* `render_pdf` / `render` when the document uses custom
|
|
180
|
+
* fonts (declared via `<font src="…"`). The adapter extracts these widths
|
|
181
|
+
* from the font binary and passes them as a JSON object:
|
|
182
|
+
*
|
|
183
|
+
* ```json
|
|
184
|
+
* { "fontName": { "default": 500, "ascii": [260, 285, …] } }
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* `ascii` is a 95-element array for code points 32–126. `default` is used
|
|
188
|
+
* for code points outside that range. All values are in 1/1000 em units.
|
|
189
|
+
* @param {string} json
|
|
190
|
+
*/
|
|
191
|
+
set_font_metrics(json) {
|
|
192
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
193
|
+
const len0 = WASM_VECTOR_LEN;
|
|
194
|
+
wasm.lpdfengine_set_font_metrics(this.__wbg_ptr, ptr0, len0);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Set the current Unix timestamp (seconds) for license expiry checking.
|
|
198
|
+
* Must be called before `render_pdf` when using a time-limited token.
|
|
199
|
+
* If not set (default `0`), expiry is not checked.
|
|
200
|
+
* @param {bigint} unix
|
|
201
|
+
*/
|
|
202
|
+
set_now(unix) {
|
|
203
|
+
wasm.lpdfengine_set_now(this.__wbg_ptr, unix);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (Symbol.dispose) LpdfEngine.prototype[Symbol.dispose] = LpdfEngine.prototype.free;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Convert a JSON kit-tree (produced by `LpdfKit` in any adapter) to an lpdf
|
|
210
|
+
* XML string.
|
|
211
|
+
*
|
|
212
|
+
* Useful for debugging Kit-generated documents, saving them as `.xml` files,
|
|
213
|
+
* or feeding them into the XML render path. The output is equivalent to
|
|
214
|
+
* hand-authored XML and passes through `render_pdf` without modification.
|
|
215
|
+
* @param {string} json
|
|
216
|
+
* @returns {string}
|
|
217
|
+
*/
|
|
218
|
+
export function kit_to_xml(json) {
|
|
219
|
+
let deferred3_0;
|
|
220
|
+
let deferred3_1;
|
|
221
|
+
try {
|
|
222
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
223
|
+
const len0 = WASM_VECTOR_LEN;
|
|
224
|
+
const ret = wasm.kit_to_xml(ptr0, len0);
|
|
225
|
+
var ptr2 = ret[0];
|
|
226
|
+
var len2 = ret[1];
|
|
227
|
+
if (ret[3]) {
|
|
228
|
+
ptr2 = 0; len2 = 0;
|
|
229
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
230
|
+
}
|
|
231
|
+
deferred3_0 = ptr2;
|
|
232
|
+
deferred3_1 = len2;
|
|
233
|
+
return getStringFromWasm0(ptr2, len2);
|
|
234
|
+
} finally {
|
|
235
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function __wbg_get_imports() {
|
|
239
|
+
const import0 = {
|
|
240
|
+
__proto__: null,
|
|
241
|
+
__wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
|
|
242
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
243
|
+
},
|
|
244
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
245
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
246
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
247
|
+
return ret;
|
|
248
|
+
},
|
|
249
|
+
__wbindgen_init_externref_table: function() {
|
|
250
|
+
const table = wasm.__wbindgen_externrefs;
|
|
251
|
+
const offset = table.grow(4);
|
|
252
|
+
table.set(0, undefined);
|
|
253
|
+
table.set(offset + 0, undefined);
|
|
254
|
+
table.set(offset + 1, null);
|
|
255
|
+
table.set(offset + 2, true);
|
|
256
|
+
table.set(offset + 3, false);
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
return {
|
|
260
|
+
__proto__: null,
|
|
261
|
+
"./lpdf_bg.js": import0,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const LpdfEngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
266
|
+
? { register: () => {}, unregister: () => {} }
|
|
267
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_lpdfengine_free(ptr >>> 0, 1));
|
|
268
|
+
|
|
269
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
270
|
+
ptr = ptr >>> 0;
|
|
271
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
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 isLikeNone(x) {
|
|
288
|
+
return x === undefined || x === null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
292
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
293
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
294
|
+
WASM_VECTOR_LEN = arg.length;
|
|
295
|
+
return ptr;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
299
|
+
if (realloc === undefined) {
|
|
300
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
301
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
302
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
303
|
+
WASM_VECTOR_LEN = buf.length;
|
|
304
|
+
return ptr;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
let len = arg.length;
|
|
308
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
309
|
+
|
|
310
|
+
const mem = getUint8ArrayMemory0();
|
|
311
|
+
|
|
312
|
+
let offset = 0;
|
|
313
|
+
|
|
314
|
+
for (; offset < len; offset++) {
|
|
315
|
+
const code = arg.charCodeAt(offset);
|
|
316
|
+
if (code > 0x7F) break;
|
|
317
|
+
mem[ptr + offset] = code;
|
|
318
|
+
}
|
|
319
|
+
if (offset !== len) {
|
|
320
|
+
if (offset !== 0) {
|
|
321
|
+
arg = arg.slice(offset);
|
|
322
|
+
}
|
|
323
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
324
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
325
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
326
|
+
|
|
327
|
+
offset += ret.written;
|
|
328
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
WASM_VECTOR_LEN = offset;
|
|
332
|
+
return ptr;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function takeFromExternrefTable0(idx) {
|
|
336
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
337
|
+
wasm.__externref_table_dealloc(idx);
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
342
|
+
cachedTextDecoder.decode();
|
|
343
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
344
|
+
let numBytesDecoded = 0;
|
|
345
|
+
function decodeText(ptr, len) {
|
|
346
|
+
numBytesDecoded += len;
|
|
347
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
348
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
349
|
+
cachedTextDecoder.decode();
|
|
350
|
+
numBytesDecoded = len;
|
|
351
|
+
}
|
|
352
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const cachedTextEncoder = new TextEncoder();
|
|
356
|
+
|
|
357
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
358
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
359
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
360
|
+
view.set(buf);
|
|
361
|
+
return {
|
|
362
|
+
read: arg.length,
|
|
363
|
+
written: buf.length
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
let WASM_VECTOR_LEN = 0;
|
|
369
|
+
|
|
370
|
+
let wasmModule, wasm;
|
|
371
|
+
function __wbg_finalize_init(instance, module) {
|
|
372
|
+
wasm = instance.exports;
|
|
373
|
+
wasmModule = module;
|
|
374
|
+
cachedUint8ArrayMemory0 = null;
|
|
375
|
+
wasm.__wbindgen_start();
|
|
376
|
+
return wasm;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function __wbg_load(module, imports) {
|
|
380
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
381
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
382
|
+
try {
|
|
383
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
384
|
+
} catch (e) {
|
|
385
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
386
|
+
|
|
387
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
388
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
389
|
+
|
|
390
|
+
} else { throw e; }
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const bytes = await module.arrayBuffer();
|
|
395
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
396
|
+
} else {
|
|
397
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
398
|
+
|
|
399
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
400
|
+
return { instance, module };
|
|
401
|
+
} else {
|
|
402
|
+
return instance;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function expectedResponseType(type) {
|
|
407
|
+
switch (type) {
|
|
408
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function initSync(module) {
|
|
415
|
+
if (wasm !== undefined) return wasm;
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
if (module !== undefined) {
|
|
419
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
420
|
+
({module} = module)
|
|
421
|
+
} else {
|
|
422
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const imports = __wbg_get_imports();
|
|
427
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
428
|
+
module = new WebAssembly.Module(module);
|
|
429
|
+
}
|
|
430
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
431
|
+
return __wbg_finalize_init(instance, module);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
async function __wbg_init(module_or_path) {
|
|
435
|
+
if (wasm !== undefined) return wasm;
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
if (module_or_path !== undefined) {
|
|
439
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
440
|
+
({module_or_path} = module_or_path)
|
|
441
|
+
} else {
|
|
442
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (module_or_path === undefined) {
|
|
447
|
+
module_or_path = new URL('lpdf_bg.wasm', import.meta.url);
|
|
448
|
+
}
|
|
449
|
+
const imports = __wbg_get_imports();
|
|
450
|
+
|
|
451
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
452
|
+
module_or_path = fetch(module_or_path);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
456
|
+
|
|
457
|
+
return __wbg_finalize_init(instance, module);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export { initSync, __wbg_init as default };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class LpdfEngine {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
/**
|
|
8
|
+
* Remove any previously configured encryption.
|
|
9
|
+
*/
|
|
10
|
+
clear_encryption(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Register raw font bytes (TTF/OTF) for a custom font name.
|
|
13
|
+
* Call this once per font before calling `render_pdf`.
|
|
14
|
+
* Glyph advance-width metrics are extracted automatically from the font
|
|
15
|
+
* bytes so the layout engine can measure text accurately — no separate
|
|
16
|
+
* `set_font_metrics` call is required.
|
|
17
|
+
*/
|
|
18
|
+
load_font(name: string, bytes: Uint8Array): void;
|
|
19
|
+
/**
|
|
20
|
+
* Register raw image bytes (JPEG or PNG) for an image name.
|
|
21
|
+
* Call this for every image referenced by `<img name="…">` nodes.
|
|
22
|
+
*/
|
|
23
|
+
load_image(name: string, bytes: Uint8Array): void;
|
|
24
|
+
constructor(license_key: string);
|
|
25
|
+
render(xml: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Render `xml` to binary PDF bytes.
|
|
28
|
+
*
|
|
29
|
+
* Any custom fonts referenced in `<font src="…">` declarations must have
|
|
30
|
+
* their bytes registered via `load_font` before calling this method.
|
|
31
|
+
*
|
|
32
|
+
* `json_data` is an optional JSON string used to resolve `data-*`
|
|
33
|
+
* attributes in the template. Pass `None` (or `null` / `undefined` from
|
|
34
|
+
* JavaScript) to render the template with its inline fallback content.
|
|
35
|
+
*/
|
|
36
|
+
render_pdf(xml: string, json_data?: string | null): Uint8Array;
|
|
37
|
+
render_tree(json: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Render a JSON kit-tree or canvas-tree document to PDF bytes.
|
|
40
|
+
*
|
|
41
|
+
* This is the JSON counterpart of `render_pdf`. The Node adapter uses it
|
|
42
|
+
* when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
|
|
43
|
+
* intermediate XML serialisation step. PHP, Python, and .NET adapters also
|
|
44
|
+
* use this entry point.
|
|
45
|
+
*/
|
|
46
|
+
render_tree_pdf(json: string): Uint8Array;
|
|
47
|
+
/**
|
|
48
|
+
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
|
|
49
|
+
* When provided, written as `/CreationDate` in the PDF info dictionary.
|
|
50
|
+
* Omitting this keeps builds reproducible (no embedded timestamp).
|
|
51
|
+
*/
|
|
52
|
+
set_created_on(iso: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Configure RC4-128 encryption applied to every subsequent `render_pdf` call.
|
|
55
|
+
*
|
|
56
|
+
* `permissions_json` is a JSON object with boolean fields matching the
|
|
57
|
+
* `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
|
|
58
|
+
* `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
|
|
59
|
+
*
|
|
60
|
+
* To apply permissions without an open password, pass an empty `user_password`
|
|
61
|
+
* and a non-empty `owner_password`.
|
|
62
|
+
*/
|
|
63
|
+
set_encryption(user_password: string, owner_password: string, permissions_json: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Inject glyph advance-width tables for custom fonts.
|
|
66
|
+
*
|
|
67
|
+
* Call this *before* `render_pdf` / `render` when the document uses custom
|
|
68
|
+
* fonts (declared via `<font src="…"`). The adapter extracts these widths
|
|
69
|
+
* from the font binary and passes them as a JSON object:
|
|
70
|
+
*
|
|
71
|
+
* ```json
|
|
72
|
+
* { "fontName": { "default": 500, "ascii": [260, 285, …] } }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* `ascii` is a 95-element array for code points 32–126. `default` is used
|
|
76
|
+
* for code points outside that range. All values are in 1/1000 em units.
|
|
77
|
+
*/
|
|
78
|
+
set_font_metrics(json: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* Set the current Unix timestamp (seconds) for license expiry checking.
|
|
81
|
+
* Must be called before `render_pdf` when using a time-limited token.
|
|
82
|
+
* If not set (default `0`), expiry is not checked.
|
|
83
|
+
*/
|
|
84
|
+
set_now(unix: bigint): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Convert a JSON kit-tree (produced by `LpdfKit` in any adapter) to an lpdf
|
|
89
|
+
* XML string.
|
|
90
|
+
*
|
|
91
|
+
* Useful for debugging Kit-generated documents, saving them as `.xml` files,
|
|
92
|
+
* or feeding them into the XML render path. The output is equivalent to
|
|
93
|
+
* hand-authored XML and passes through `render_pdf` without modification.
|
|
94
|
+
*/
|
|
95
|
+
export function kit_to_xml(json: string): string;
|