@lpdfio/lpdf 0.30.0 → 0.32.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/LICENSE +1 -1
- package/README.md +2 -2
- package/dist/_shared.d.ts +42 -3
- package/dist/_shared.js +52 -3
- package/dist/attrs.d.ts +580 -89
- package/dist/browser.js +125 -61
- package/dist/canvas.d.ts +10 -9
- package/dist/constants.d.ts +27 -0
- package/dist/constants.js +25 -1
- package/dist/engine.d.ts +23 -41
- package/dist/engine.js +114 -43
- package/dist/index.d.ts +3 -4
- package/dist/index.js +4 -1
- package/dist/kit.d.ts +97 -32
- package/dist/kit.js +7 -1
- package/dist/layout.d.ts +20 -19
- package/dist/markdown.d.ts +5 -4
- package/dist/wasm/lpdf-web.js +64 -50
- package/dist/wasm/lpdf.js +64 -50
- package/dist/wasm/lpdf_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -11,10 +11,17 @@ var LpdfEngine = class {
|
|
|
11
11
|
wasm.__wbg_lpdfengine_free(ptr, 0);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Register the bytes of a file a document carries, for the `<file>` of its `<attachments>` whose `ref`, or with
|
|
15
|
+
* no ref whose name, is `name`. The PDF carries them as they are.
|
|
16
|
+
* @param {string} name
|
|
17
|
+
* @param {Uint8Array} bytes
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
wasm.
|
|
19
|
+
load_file(name, bytes) {
|
|
20
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
21
|
+
const len0 = WASM_VECTOR_LEN;
|
|
22
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
23
|
+
const len1 = WASM_VECTOR_LEN;
|
|
24
|
+
wasm.lpdfengine_load_file(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
18
25
|
}
|
|
19
26
|
/**
|
|
20
27
|
* Register raw font bytes (TTF/OTF) for a custom font name.
|
|
@@ -59,6 +66,19 @@ var LpdfEngine = class {
|
|
|
59
66
|
const len1 = WASM_VECTOR_LEN;
|
|
60
67
|
wasm.lpdfengine_load_markdown_styles(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
61
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Register the bytes of an ICC colour profile, for the `<profile>` of a document's `<assets>` whose `ref`, or with
|
|
71
|
+
* no ref whose name, is `name`: the press profile a PDF/X document names in `<output profile>`.
|
|
72
|
+
* @param {string} name
|
|
73
|
+
* @param {Uint8Array} bytes
|
|
74
|
+
*/
|
|
75
|
+
load_profile(name, bytes) {
|
|
76
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
77
|
+
const len0 = WASM_VECTOR_LEN;
|
|
78
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
79
|
+
const len1 = WASM_VECTOR_LEN;
|
|
80
|
+
wasm.lpdfengine_load_profile(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
81
|
+
}
|
|
62
82
|
/**
|
|
63
83
|
* @param {string} license_key
|
|
64
84
|
*/
|
|
@@ -97,22 +117,38 @@ var LpdfEngine = class {
|
|
|
97
117
|
* `json_data` is an optional JSON string used to resolve `data-*`
|
|
98
118
|
* attributes in the template. Pass `None` (or `null` / `undefined` from
|
|
99
119
|
* JavaScript) to render the template with its inline fallback content.
|
|
120
|
+
*
|
|
121
|
+
* The rest is for a document that asks for encryption in its `<output>`, which sets the cipher and
|
|
122
|
+
* the permissions: the passwords, which the template never holds, and `entropy`, at least 32 random
|
|
123
|
+
* bytes from the host's secure generator for AES-256. A document that asks for encryption needs an
|
|
124
|
+
* owner password, or `skip_encryption` to render it unencrypted, as a preview does; passwords for a
|
|
125
|
+
* document that doesn't ask for it are an error, and so are passwords with `skip_encryption`.
|
|
100
126
|
* @param {string} xml
|
|
101
|
-
* @param {string | null}
|
|
127
|
+
* @param {string | null | undefined} json_data
|
|
128
|
+
* @param {string | null | undefined} user_password
|
|
129
|
+
* @param {string | null | undefined} owner_password
|
|
130
|
+
* @param {boolean} skip_encryption
|
|
131
|
+
* @param {Uint8Array} entropy
|
|
102
132
|
* @returns {Uint8Array}
|
|
103
133
|
*/
|
|
104
|
-
render_pdf(xml, json_data) {
|
|
134
|
+
render_pdf(xml, json_data, user_password, owner_password, skip_encryption, entropy) {
|
|
105
135
|
const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
106
136
|
const len0 = WASM_VECTOR_LEN;
|
|
107
137
|
var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
108
138
|
var len1 = WASM_VECTOR_LEN;
|
|
109
|
-
|
|
139
|
+
var ptr2 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
140
|
+
var len2 = WASM_VECTOR_LEN;
|
|
141
|
+
var ptr3 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
142
|
+
var len3 = WASM_VECTOR_LEN;
|
|
143
|
+
const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
144
|
+
const len4 = WASM_VECTOR_LEN;
|
|
145
|
+
const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, skip_encryption, ptr4, len4);
|
|
110
146
|
if (ret[3]) {
|
|
111
147
|
throw takeFromExternrefTable0(ret[2]);
|
|
112
148
|
}
|
|
113
|
-
var
|
|
149
|
+
var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
114
150
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
115
|
-
return
|
|
151
|
+
return v6;
|
|
116
152
|
}
|
|
117
153
|
/**
|
|
118
154
|
* @param {string} json
|
|
@@ -139,23 +175,37 @@ var LpdfEngine = class {
|
|
|
139
175
|
* when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
|
|
140
176
|
* intermediate XML serialisation step. PHP, Python, and .NET adapters also
|
|
141
177
|
* use this entry point.
|
|
178
|
+
*
|
|
179
|
+
* The passwords, `skip_encryption` and `entropy` are those of `render_pdf`, for a document whose
|
|
180
|
+
* `output` asks for encryption.
|
|
142
181
|
* @param {string} json
|
|
182
|
+
* @param {string | null | undefined} user_password
|
|
183
|
+
* @param {string | null | undefined} owner_password
|
|
184
|
+
* @param {boolean} skip_encryption
|
|
185
|
+
* @param {Uint8Array} entropy
|
|
143
186
|
* @returns {Uint8Array}
|
|
144
187
|
*/
|
|
145
|
-
render_tree_pdf(json) {
|
|
188
|
+
render_tree_pdf(json, user_password, owner_password, skip_encryption, entropy) {
|
|
146
189
|
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
147
190
|
const len0 = WASM_VECTOR_LEN;
|
|
148
|
-
|
|
191
|
+
var ptr1 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
192
|
+
var len1 = WASM_VECTOR_LEN;
|
|
193
|
+
var ptr2 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
194
|
+
var len2 = WASM_VECTOR_LEN;
|
|
195
|
+
const ptr3 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
196
|
+
const len3 = WASM_VECTOR_LEN;
|
|
197
|
+
const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, skip_encryption, ptr3, len3);
|
|
149
198
|
if (ret[3]) {
|
|
150
199
|
throw takeFromExternrefTable0(ret[2]);
|
|
151
200
|
}
|
|
152
|
-
var
|
|
201
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
153
202
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
154
|
-
return
|
|
203
|
+
return v5;
|
|
155
204
|
}
|
|
156
205
|
/**
|
|
157
|
-
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`
|
|
158
|
-
* When provided, written as `/CreationDate` in the PDF info dictionary
|
|
206
|
+
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`, `"2024-06-01T12:00:00.000Z"` or
|
|
207
|
+
* `"2024-06-01T12:00:00+01:00"`). When provided, written as `/CreationDate` in the PDF info dictionary, with
|
|
208
|
+
* the precision and the time zone it was given in; a value that is not a date makes the render an error.
|
|
159
209
|
* Omitting this keeps builds reproducible (no embedded timestamp).
|
|
160
210
|
* @param {string} iso
|
|
161
211
|
*/
|
|
@@ -164,42 +214,6 @@ var LpdfEngine = class {
|
|
|
164
214
|
const len0 = WASM_VECTOR_LEN;
|
|
165
215
|
wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
|
|
166
216
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Configure encryption applied to every subsequent `render_pdf` call.
|
|
169
|
-
*
|
|
170
|
-
* `permissions_json` is a JSON object with boolean fields matching the
|
|
171
|
-
* `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
|
|
172
|
-
* `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
|
|
173
|
-
*
|
|
174
|
-
* `algorithm` is `"aes-256"` or `"rc4-128"`. AES-256 needs `entropy`: at least 32
|
|
175
|
-
* random bytes from the host's secure generator, from which the core cuts the file
|
|
176
|
-
* key, salts and IVs. RC4-128 ignores it. Fails when the algorithm is unknown or
|
|
177
|
-
* AES-256 gets too little entropy.
|
|
178
|
-
*
|
|
179
|
-
* To apply permissions without an open password, pass an empty `user_password`
|
|
180
|
-
* and a non-empty `owner_password`.
|
|
181
|
-
* @param {string} user_password
|
|
182
|
-
* @param {string} owner_password
|
|
183
|
-
* @param {string} permissions_json
|
|
184
|
-
* @param {string} algorithm
|
|
185
|
-
* @param {Uint8Array} entropy
|
|
186
|
-
*/
|
|
187
|
-
set_encryption(user_password, owner_password, permissions_json, algorithm, entropy) {
|
|
188
|
-
const ptr0 = passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
189
|
-
const len0 = WASM_VECTOR_LEN;
|
|
190
|
-
const ptr1 = passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
191
|
-
const len1 = WASM_VECTOR_LEN;
|
|
192
|
-
const ptr2 = passStringToWasm0(permissions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
193
|
-
const len2 = WASM_VECTOR_LEN;
|
|
194
|
-
const ptr3 = passStringToWasm0(algorithm, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
195
|
-
const len3 = WASM_VECTOR_LEN;
|
|
196
|
-
const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
197
|
-
const len4 = WASM_VECTOR_LEN;
|
|
198
|
-
const ret = wasm.lpdfengine_set_encryption(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
|
199
|
-
if (ret[1]) {
|
|
200
|
-
throw takeFromExternrefTable0(ret[0]);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
217
|
/**
|
|
204
218
|
* Inject glyph advance-width tables for custom fonts.
|
|
205
219
|
*
|
|
@@ -420,6 +434,18 @@ async function __wbg_init(module_or_path) {
|
|
|
420
434
|
return __wbg_finalize_init(instance, module);
|
|
421
435
|
}
|
|
422
436
|
|
|
437
|
+
// src/_shared.ts
|
|
438
|
+
var ENTROPY_BYTES = 32;
|
|
439
|
+
function encryptionArguments(options, randomBytes) {
|
|
440
|
+
const hasPassword = options.userPassword !== void 0 || options.ownerPassword !== void 0;
|
|
441
|
+
return [
|
|
442
|
+
options.userPassword ?? null,
|
|
443
|
+
options.ownerPassword ?? null,
|
|
444
|
+
options.skipEncryption ?? false,
|
|
445
|
+
hasPassword ? randomBytes(ENTROPY_BYTES) : new Uint8Array(0)
|
|
446
|
+
];
|
|
447
|
+
}
|
|
448
|
+
|
|
423
449
|
// src/constants.ts
|
|
424
450
|
var FieldType = {
|
|
425
451
|
Text: "text",
|
|
@@ -446,6 +472,27 @@ var FootnoteCounter = {
|
|
|
446
472
|
Section: "section",
|
|
447
473
|
Document: "document"
|
|
448
474
|
};
|
|
475
|
+
var Cipher = {
|
|
476
|
+
Aes256: "aes-256",
|
|
477
|
+
Rc4128: "rc4-128"
|
|
478
|
+
};
|
|
479
|
+
var Permission = {
|
|
480
|
+
All: "all",
|
|
481
|
+
Print: "print",
|
|
482
|
+
Modify: "modify",
|
|
483
|
+
Copy: "copy",
|
|
484
|
+
Annotate: "annotate",
|
|
485
|
+
FillForms: "fill-forms",
|
|
486
|
+
Accessibility: "accessibility",
|
|
487
|
+
Assemble: "assemble"
|
|
488
|
+
};
|
|
489
|
+
var FileRelationship = {
|
|
490
|
+
Source: "source",
|
|
491
|
+
Data: "data",
|
|
492
|
+
Alternative: "alternative",
|
|
493
|
+
Supplement: "supplement",
|
|
494
|
+
Unspecified: "unspecified"
|
|
495
|
+
};
|
|
449
496
|
var BuiltinFont = {
|
|
450
497
|
Courier: "Courier",
|
|
451
498
|
CourierBold: "Courier-Bold",
|
|
@@ -475,10 +522,15 @@ var NoAttr = null;
|
|
|
475
522
|
function nowUnix() {
|
|
476
523
|
return BigInt(Math.floor(Date.now() / 1e3));
|
|
477
524
|
}
|
|
525
|
+
function secureRandomBytes(count) {
|
|
526
|
+
return crypto.getRandomValues(new Uint8Array(count));
|
|
527
|
+
}
|
|
478
528
|
async function initLpdf(wasmSource, licenseKey = "") {
|
|
479
529
|
await __wbg_init(wasmSource);
|
|
480
530
|
const fontMap = /* @__PURE__ */ new Map();
|
|
481
531
|
const imageMap = /* @__PURE__ */ new Map();
|
|
532
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
533
|
+
const profileMap = /* @__PURE__ */ new Map();
|
|
482
534
|
const markdownStyles = /* @__PURE__ */ new Map();
|
|
483
535
|
return {
|
|
484
536
|
loadFont(name, bytes) {
|
|
@@ -487,6 +539,12 @@ async function initLpdf(wasmSource, licenseKey = "") {
|
|
|
487
539
|
loadImage(name, bytes) {
|
|
488
540
|
imageMap.set(name, bytes);
|
|
489
541
|
},
|
|
542
|
+
loadFile(name, bytes) {
|
|
543
|
+
fileMap.set(name, bytes);
|
|
544
|
+
},
|
|
545
|
+
loadProfile(name, bytes) {
|
|
546
|
+
profileMap.set(name, bytes);
|
|
547
|
+
},
|
|
490
548
|
loadMarkdownStyles(src, text) {
|
|
491
549
|
markdownStyles.set(src, text);
|
|
492
550
|
},
|
|
@@ -502,38 +560,44 @@ async function initLpdf(wasmSource, licenseKey = "") {
|
|
|
502
560
|
for (const [name, bytes] of imageMap) {
|
|
503
561
|
engine.load_image(name, bytes);
|
|
504
562
|
}
|
|
563
|
+
for (const [name, bytes] of fileMap) {
|
|
564
|
+
engine.load_file(name, bytes);
|
|
565
|
+
}
|
|
566
|
+
for (const [name, bytes] of profileMap) {
|
|
567
|
+
engine.load_profile(name, bytes);
|
|
568
|
+
}
|
|
505
569
|
for (const [src, text] of markdownStyles) {
|
|
506
570
|
engine.load_markdown_styles(src, text);
|
|
507
571
|
}
|
|
508
572
|
if (callOptions.createdOn) {
|
|
509
573
|
engine.set_created_on(callOptions.createdOn);
|
|
510
574
|
}
|
|
575
|
+
const encryption = encryptionArguments(callOptions, secureRandomBytes);
|
|
511
576
|
let pdf;
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const wasmExt = engine;
|
|
517
|
-
if (typeof wasmExt.render_tree_pdf === "function") {
|
|
518
|
-
pdf = wasmExt.render_tree_pdf(JSON.stringify(input));
|
|
577
|
+
try {
|
|
578
|
+
if (typeof input === "string") {
|
|
579
|
+
const dataJson = callOptions.data != null ? JSON.stringify(callOptions.data) : null;
|
|
580
|
+
pdf = engine.render_pdf(input, dataJson, ...encryption);
|
|
519
581
|
} else {
|
|
520
|
-
|
|
521
|
-
const xml = mod.constructor.kit_to_xml?.(JSON.stringify(input)) ?? "";
|
|
522
|
-
pdf = engine.render_pdf(xml, null);
|
|
582
|
+
pdf = engine.render_tree_pdf(JSON.stringify(input), ...encryption);
|
|
523
583
|
}
|
|
584
|
+
} finally {
|
|
585
|
+
engine.free();
|
|
524
586
|
}
|
|
525
|
-
engine.free();
|
|
526
587
|
return pdf;
|
|
527
588
|
}
|
|
528
589
|
};
|
|
529
590
|
}
|
|
530
591
|
export {
|
|
531
592
|
BuiltinFont,
|
|
593
|
+
Cipher,
|
|
532
594
|
FieldType,
|
|
595
|
+
FileRelationship,
|
|
533
596
|
FootnoteCounter,
|
|
534
597
|
NoAttr,
|
|
535
598
|
Orientation,
|
|
536
599
|
PageScope,
|
|
600
|
+
Permission,
|
|
537
601
|
Pin,
|
|
538
602
|
SectionType,
|
|
539
603
|
initLpdf
|
package/dist/canvas.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, TextAtAttr, ImgAtAttr, BarcodeAtAttr, LayerAttr } from './attrs';
|
|
2
2
|
import type { LpdfSpanNode, LpdfCodeSpanNode } from './layout';
|
|
3
|
+
import { type AttrValue } from './_shared';
|
|
3
4
|
/**
|
|
4
5
|
* Builds the `transform` string of a layer. `String(CanvasTransform.rotate(45))` is
|
|
5
6
|
* `matrix(...)`, which a layer's `transform` attribute accepts like `rotate(45)`.
|
|
@@ -23,41 +24,41 @@ export declare class CanvasTransform {
|
|
|
23
24
|
}
|
|
24
25
|
export interface LpdfCanvasRectNode {
|
|
25
26
|
type: 'rect';
|
|
26
|
-
attrs: Record<string,
|
|
27
|
+
attrs: Record<string, AttrValue>;
|
|
27
28
|
}
|
|
28
29
|
export interface LpdfCanvasLineNode {
|
|
29
30
|
type: 'line';
|
|
30
|
-
attrs: Record<string,
|
|
31
|
+
attrs: Record<string, AttrValue>;
|
|
31
32
|
}
|
|
32
33
|
export interface LpdfCanvasEllipseNode {
|
|
33
34
|
type: 'ellipse';
|
|
34
|
-
attrs: Record<string,
|
|
35
|
+
attrs: Record<string, AttrValue>;
|
|
35
36
|
}
|
|
36
37
|
export interface LpdfCanvasCircleNode {
|
|
37
38
|
type: 'circle';
|
|
38
|
-
attrs: Record<string,
|
|
39
|
+
attrs: Record<string, AttrValue>;
|
|
39
40
|
}
|
|
40
41
|
export interface LpdfCanvasPathNode {
|
|
41
42
|
type: 'path';
|
|
42
|
-
attrs: Record<string,
|
|
43
|
+
attrs: Record<string, AttrValue>;
|
|
43
44
|
}
|
|
44
45
|
export interface LpdfCanvasTextAtNode {
|
|
45
46
|
type: 'text-at';
|
|
46
|
-
attrs: Record<string,
|
|
47
|
+
attrs: Record<string, AttrValue>;
|
|
47
48
|
nodes: (string | LpdfSpanNode | LpdfCodeSpanNode)[];
|
|
48
49
|
}
|
|
49
50
|
export interface LpdfCanvasImgAtNode {
|
|
50
51
|
type: 'img-at';
|
|
51
|
-
attrs: Record<string,
|
|
52
|
+
attrs: Record<string, AttrValue>;
|
|
52
53
|
}
|
|
53
54
|
export interface LpdfCanvasBarcodeAtNode {
|
|
54
55
|
type: 'barcode-at';
|
|
55
|
-
attrs: Record<string,
|
|
56
|
+
attrs: Record<string, AttrValue>;
|
|
56
57
|
}
|
|
57
58
|
export type LpdfCanvasPrimitiveNode = LpdfCanvasRectNode | LpdfCanvasLineNode | LpdfCanvasEllipseNode | LpdfCanvasCircleNode | LpdfCanvasPathNode | LpdfCanvasTextAtNode | LpdfCanvasImgAtNode | LpdfCanvasBarcodeAtNode;
|
|
58
59
|
export interface LpdfCanvasLayerNode {
|
|
59
60
|
type: 'layer';
|
|
60
|
-
attrs: Record<string,
|
|
61
|
+
attrs: Record<string, AttrValue>;
|
|
61
62
|
nodes: LpdfCanvasPrimitiveNode[];
|
|
62
63
|
}
|
|
63
64
|
declare function rect(attrs: RectAttr): LpdfCanvasRectNode;
|
package/dist/constants.d.ts
CHANGED
|
@@ -33,6 +33,33 @@ export declare const FootnoteCounter: {
|
|
|
33
33
|
readonly Document: "document";
|
|
34
34
|
};
|
|
35
35
|
export type FootnoteCounter = (typeof FootnoteCounter)[keyof typeof FootnoteCounter];
|
|
36
|
+
/** The values of the `encrypt` attribute of the output: the cipher the PDF is encrypted with. */
|
|
37
|
+
export declare const Cipher: {
|
|
38
|
+
readonly Aes256: "aes-256";
|
|
39
|
+
readonly Rc4128: "rc4-128";
|
|
40
|
+
};
|
|
41
|
+
export type Cipher = (typeof Cipher)[keyof typeof Cipher];
|
|
42
|
+
/** The words of the `allow` attribute of the output, separated by spaces: what a reader of an encrypted PDF may do. */
|
|
43
|
+
export declare const Permission: {
|
|
44
|
+
readonly All: "all";
|
|
45
|
+
readonly Print: "print";
|
|
46
|
+
readonly Modify: "modify";
|
|
47
|
+
readonly Copy: "copy";
|
|
48
|
+
readonly Annotate: "annotate";
|
|
49
|
+
readonly FillForms: "fill-forms";
|
|
50
|
+
readonly Accessibility: "accessibility";
|
|
51
|
+
readonly Assemble: "assemble";
|
|
52
|
+
};
|
|
53
|
+
export type Permission = (typeof Permission)[keyof typeof Permission];
|
|
54
|
+
/** The values of the `relationship` attribute of a file the PDF carries: how it relates to the document. */
|
|
55
|
+
export declare const FileRelationship: {
|
|
56
|
+
readonly Source: "source";
|
|
57
|
+
readonly Data: "data";
|
|
58
|
+
readonly Alternative: "alternative";
|
|
59
|
+
readonly Supplement: "supplement";
|
|
60
|
+
readonly Unspecified: "unspecified";
|
|
61
|
+
};
|
|
62
|
+
export type FileRelationship = (typeof FileRelationship)[keyof typeof FileRelationship];
|
|
36
63
|
/** The values of the `core` attribute of a font: the built-in PDF fonts, which need no file. */
|
|
37
64
|
export declare const BuiltinFont: {
|
|
38
65
|
readonly Courier: "Courier";
|
package/dist/constants.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Generated from lpdf.xsd by scripts/gen-sdk-api.mjs.
|
|
3
3
|
// Do not edit: change the schema and run `make gen-sdk-api`.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.PageScope = exports.BuiltinFont = exports.FootnoteCounter = exports.SectionType = exports.Orientation = exports.Pin = exports.FieldType = void 0;
|
|
5
|
+
exports.PageScope = exports.BuiltinFont = exports.FileRelationship = exports.Permission = exports.Cipher = exports.FootnoteCounter = exports.SectionType = exports.Orientation = exports.Pin = exports.FieldType = void 0;
|
|
6
6
|
/** The values of the `type` attribute of a field. */
|
|
7
7
|
exports.FieldType = {
|
|
8
8
|
Text: 'text',
|
|
@@ -33,6 +33,30 @@ exports.FootnoteCounter = {
|
|
|
33
33
|
Section: 'section',
|
|
34
34
|
Document: 'document',
|
|
35
35
|
};
|
|
36
|
+
/** The values of the `encrypt` attribute of the output: the cipher the PDF is encrypted with. */
|
|
37
|
+
exports.Cipher = {
|
|
38
|
+
Aes256: 'aes-256',
|
|
39
|
+
Rc4128: 'rc4-128',
|
|
40
|
+
};
|
|
41
|
+
/** The words of the `allow` attribute of the output, separated by spaces: what a reader of an encrypted PDF may do. */
|
|
42
|
+
exports.Permission = {
|
|
43
|
+
All: 'all',
|
|
44
|
+
Print: 'print',
|
|
45
|
+
Modify: 'modify',
|
|
46
|
+
Copy: 'copy',
|
|
47
|
+
Annotate: 'annotate',
|
|
48
|
+
FillForms: 'fill-forms',
|
|
49
|
+
Accessibility: 'accessibility',
|
|
50
|
+
Assemble: 'assemble',
|
|
51
|
+
};
|
|
52
|
+
/** The values of the `relationship` attribute of a file the PDF carries: how it relates to the document. */
|
|
53
|
+
exports.FileRelationship = {
|
|
54
|
+
Source: 'source',
|
|
55
|
+
Data: 'data',
|
|
56
|
+
Alternative: 'alternative',
|
|
57
|
+
Supplement: 'supplement',
|
|
58
|
+
Unspecified: 'unspecified',
|
|
59
|
+
};
|
|
36
60
|
/** The values of the `core` attribute of a font: the built-in PDF fonts, which need no file. */
|
|
37
61
|
exports.BuiltinFont = {
|
|
38
62
|
Courier: 'Courier',
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RenderOptions } from './_shared';
|
|
2
2
|
import type { PdfDocument } from './kit';
|
|
3
3
|
/** How a license key stands with this build of the engine. */
|
|
4
4
|
export type LicenseStatus = 'licensed' | 'no_key' | 'expired' | 'version_mismatch' | 'wrong_product' | 'unknown_key' | 'bad_signature' | 'malformed';
|
|
@@ -26,43 +26,14 @@ export interface LicenseCheck {
|
|
|
26
26
|
export declare class LpdfRenderError extends Error {
|
|
27
27
|
constructor(message: string);
|
|
28
28
|
}
|
|
29
|
-
/** PDF permission flags. All flags default to `true` (allowed). */
|
|
30
|
-
export interface EncryptPermissions {
|
|
31
|
-
print?: boolean;
|
|
32
|
-
modify?: boolean;
|
|
33
|
-
copy?: boolean;
|
|
34
|
-
annotate?: boolean;
|
|
35
|
-
fill_forms?: boolean;
|
|
36
|
-
accessibility?: boolean;
|
|
37
|
-
assemble?: boolean;
|
|
38
|
-
print_hq?: boolean;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* The cipher a PDF is encrypted with. `'aes-256'` is the default. `'rc4-128'` is deprecated by
|
|
42
|
-
* PDF 2.0; use it only for readers that cannot open AES-256.
|
|
43
|
-
*/
|
|
44
|
-
export type EncryptAlgorithm = 'aes-256' | 'rc4-128';
|
|
45
|
-
/** Encryption options passed to {@link PdfEngine.setEncryption}. */
|
|
46
|
-
export interface EncryptOptions {
|
|
47
|
-
/** Open password shown to readers. Empty string = no open password required. */
|
|
48
|
-
userPassword: string;
|
|
49
|
-
/** Owner (permissions) password. Required; must be non-empty. */
|
|
50
|
-
ownerPassword: string;
|
|
51
|
-
/** Permission flags applied to the document. Omitted flags default to `true`. */
|
|
52
|
-
permissions?: EncryptPermissions;
|
|
53
|
-
/**
|
|
54
|
-
* The cipher. Defaults to `'aes-256'`, which makes every render of the same document differ
|
|
55
|
-
* in its bytes, since each one gets a fresh random key.
|
|
56
|
-
*/
|
|
57
|
-
algorithm?: EncryptAlgorithm;
|
|
58
|
-
}
|
|
59
29
|
export declare class PdfEngine {
|
|
60
30
|
private _licenseKey;
|
|
61
31
|
private readonly _fonts;
|
|
62
32
|
private readonly _images;
|
|
33
|
+
private readonly _files;
|
|
34
|
+
private readonly _profiles;
|
|
63
35
|
private readonly _markdownStyles;
|
|
64
36
|
private _disposed;
|
|
65
|
-
private _encrypt;
|
|
66
37
|
constructor();
|
|
67
38
|
/**
|
|
68
39
|
* Set the license key. Returns `this` for chaining.
|
|
@@ -91,20 +62,21 @@ export declare class PdfEngine {
|
|
|
91
62
|
*/
|
|
92
63
|
loadImage(name: string, bytes: Uint8Array): this;
|
|
93
64
|
/**
|
|
94
|
-
* Register the
|
|
95
|
-
*
|
|
65
|
+
* Register the bytes of a file the document carries, for the `<file>` of its `<attachments>` whose `ref`, or with
|
|
66
|
+
* no ref whose name, is `name`. The PDF carries them as they are. Call before `render`. Returns `this` for chaining.
|
|
96
67
|
*/
|
|
97
|
-
|
|
68
|
+
loadFile(name: string, bytes: Uint8Array): this;
|
|
98
69
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
70
|
+
* Register the bytes of an ICC color profile, for the `<profile>` of the document's `<assets>` whose `ref`, or with
|
|
71
|
+
* no ref whose name, is `name`: the press profile a PDF/X document names in its output. Call before `render`.
|
|
72
|
+
* Returns `this` for chaining.
|
|
101
73
|
*/
|
|
102
|
-
|
|
74
|
+
loadProfile(name: string, bytes: Uint8Array): this;
|
|
103
75
|
/**
|
|
104
|
-
*
|
|
105
|
-
* Returns `this` for chaining.
|
|
76
|
+
* Register the text of a file of Markdown rules, the root of which is a `<markdown-styles>`, for the `src` that
|
|
77
|
+
* names it, as `<markdown-styles src="…">` does. Call before `render`. Returns `this` for chaining.
|
|
106
78
|
*/
|
|
107
|
-
|
|
79
|
+
loadMarkdownStyles(src: string, text: string): this;
|
|
108
80
|
/**
|
|
109
81
|
* Release held resources. Idempotent. Subsequent `render` / `loadFont`
|
|
110
82
|
* calls after disposal will throw.
|
|
@@ -116,6 +88,16 @@ export declare class PdfEngine {
|
|
|
116
88
|
* their `src`. A file that can't be read is left for the engine to report, naming the `src`.
|
|
117
89
|
*/
|
|
118
90
|
private _loadMarkdownStyles;
|
|
91
|
+
/**
|
|
92
|
+
* Hand the engine the files the document carries: the ones loaded here, and the ones read from the `src` of a file
|
|
93
|
+
* that wasn't. A `src` that can't be read is an error that names the file and the path.
|
|
94
|
+
*/
|
|
95
|
+
private _loadFiles;
|
|
96
|
+
/**
|
|
97
|
+
* Hand the engine the color profiles the document declares: the ones loaded here, and the ones read from the `src`
|
|
98
|
+
* of a profile that wasn't. A `src` that can't be read is an error that names the profile and the path.
|
|
99
|
+
*/
|
|
100
|
+
private _loadProfiles;
|
|
119
101
|
private _throwIfDisposed;
|
|
120
102
|
/**
|
|
121
103
|
* Render an lpdf XML string to PDF bytes (Node.js).
|