@lpdfio/lpdf 0.30.0 → 0.31.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 +157 -82
- package/dist/browser.js +105 -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 +12 -42
- package/dist/engine.js +85 -47
- package/dist/index.d.ts +3 -4
- package/dist/index.js +4 -1
- package/dist/kit.d.ts +45 -30
- 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 +51 -50
- package/dist/wasm/lpdf.js +51 -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.
|
|
@@ -97,22 +104,38 @@ var LpdfEngine = class {
|
|
|
97
104
|
* `json_data` is an optional JSON string used to resolve `data-*`
|
|
98
105
|
* attributes in the template. Pass `None` (or `null` / `undefined` from
|
|
99
106
|
* JavaScript) to render the template with its inline fallback content.
|
|
107
|
+
*
|
|
108
|
+
* The rest is for a document that asks for encryption in its `<output>`, which sets the cipher and
|
|
109
|
+
* the permissions: the passwords, which the template never holds, and `entropy`, at least 32 random
|
|
110
|
+
* bytes from the host's secure generator for AES-256. A document that asks for encryption needs an
|
|
111
|
+
* owner password, or `skip_encryption` to render it unencrypted, as a preview does; passwords for a
|
|
112
|
+
* document that doesn't ask for it are an error, and so are passwords with `skip_encryption`.
|
|
100
113
|
* @param {string} xml
|
|
101
|
-
* @param {string | null}
|
|
114
|
+
* @param {string | null | undefined} json_data
|
|
115
|
+
* @param {string | null | undefined} user_password
|
|
116
|
+
* @param {string | null | undefined} owner_password
|
|
117
|
+
* @param {boolean} skip_encryption
|
|
118
|
+
* @param {Uint8Array} entropy
|
|
102
119
|
* @returns {Uint8Array}
|
|
103
120
|
*/
|
|
104
|
-
render_pdf(xml, json_data) {
|
|
121
|
+
render_pdf(xml, json_data, user_password, owner_password, skip_encryption, entropy) {
|
|
105
122
|
const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
106
123
|
const len0 = WASM_VECTOR_LEN;
|
|
107
124
|
var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
108
125
|
var len1 = WASM_VECTOR_LEN;
|
|
109
|
-
|
|
126
|
+
var ptr2 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
127
|
+
var len2 = WASM_VECTOR_LEN;
|
|
128
|
+
var ptr3 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
129
|
+
var len3 = WASM_VECTOR_LEN;
|
|
130
|
+
const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
131
|
+
const len4 = WASM_VECTOR_LEN;
|
|
132
|
+
const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, skip_encryption, ptr4, len4);
|
|
110
133
|
if (ret[3]) {
|
|
111
134
|
throw takeFromExternrefTable0(ret[2]);
|
|
112
135
|
}
|
|
113
|
-
var
|
|
136
|
+
var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
114
137
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
115
|
-
return
|
|
138
|
+
return v6;
|
|
116
139
|
}
|
|
117
140
|
/**
|
|
118
141
|
* @param {string} json
|
|
@@ -139,23 +162,37 @@ var LpdfEngine = class {
|
|
|
139
162
|
* when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
|
|
140
163
|
* intermediate XML serialisation step. PHP, Python, and .NET adapters also
|
|
141
164
|
* use this entry point.
|
|
165
|
+
*
|
|
166
|
+
* The passwords, `skip_encryption` and `entropy` are those of `render_pdf`, for a document whose
|
|
167
|
+
* `output` asks for encryption.
|
|
142
168
|
* @param {string} json
|
|
169
|
+
* @param {string | null | undefined} user_password
|
|
170
|
+
* @param {string | null | undefined} owner_password
|
|
171
|
+
* @param {boolean} skip_encryption
|
|
172
|
+
* @param {Uint8Array} entropy
|
|
143
173
|
* @returns {Uint8Array}
|
|
144
174
|
*/
|
|
145
|
-
render_tree_pdf(json) {
|
|
175
|
+
render_tree_pdf(json, user_password, owner_password, skip_encryption, entropy) {
|
|
146
176
|
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
147
177
|
const len0 = WASM_VECTOR_LEN;
|
|
148
|
-
|
|
178
|
+
var ptr1 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
179
|
+
var len1 = WASM_VECTOR_LEN;
|
|
180
|
+
var ptr2 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
181
|
+
var len2 = WASM_VECTOR_LEN;
|
|
182
|
+
const ptr3 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
|
|
183
|
+
const len3 = WASM_VECTOR_LEN;
|
|
184
|
+
const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, skip_encryption, ptr3, len3);
|
|
149
185
|
if (ret[3]) {
|
|
150
186
|
throw takeFromExternrefTable0(ret[2]);
|
|
151
187
|
}
|
|
152
|
-
var
|
|
188
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
153
189
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
154
|
-
return
|
|
190
|
+
return v5;
|
|
155
191
|
}
|
|
156
192
|
/**
|
|
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
|
|
193
|
+
* Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`, `"2024-06-01T12:00:00.000Z"` or
|
|
194
|
+
* `"2024-06-01T12:00:00+01:00"`). When provided, written as `/CreationDate` in the PDF info dictionary, with
|
|
195
|
+
* the precision and the time zone it was given in; a value that is not a date makes the render an error.
|
|
159
196
|
* Omitting this keeps builds reproducible (no embedded timestamp).
|
|
160
197
|
* @param {string} iso
|
|
161
198
|
*/
|
|
@@ -164,42 +201,6 @@ var LpdfEngine = class {
|
|
|
164
201
|
const len0 = WASM_VECTOR_LEN;
|
|
165
202
|
wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
|
|
166
203
|
}
|
|
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
204
|
/**
|
|
204
205
|
* Inject glyph advance-width tables for custom fonts.
|
|
205
206
|
*
|
|
@@ -420,6 +421,18 @@ async function __wbg_init(module_or_path) {
|
|
|
420
421
|
return __wbg_finalize_init(instance, module);
|
|
421
422
|
}
|
|
422
423
|
|
|
424
|
+
// src/_shared.ts
|
|
425
|
+
var ENTROPY_BYTES = 32;
|
|
426
|
+
function encryptionArguments(options, randomBytes) {
|
|
427
|
+
const hasPassword = options.userPassword !== void 0 || options.ownerPassword !== void 0;
|
|
428
|
+
return [
|
|
429
|
+
options.userPassword ?? null,
|
|
430
|
+
options.ownerPassword ?? null,
|
|
431
|
+
options.skipEncryption ?? false,
|
|
432
|
+
hasPassword ? randomBytes(ENTROPY_BYTES) : new Uint8Array(0)
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
|
|
423
436
|
// src/constants.ts
|
|
424
437
|
var FieldType = {
|
|
425
438
|
Text: "text",
|
|
@@ -446,6 +459,27 @@ var FootnoteCounter = {
|
|
|
446
459
|
Section: "section",
|
|
447
460
|
Document: "document"
|
|
448
461
|
};
|
|
462
|
+
var Cipher = {
|
|
463
|
+
Aes256: "aes-256",
|
|
464
|
+
Rc4128: "rc4-128"
|
|
465
|
+
};
|
|
466
|
+
var Permission = {
|
|
467
|
+
All: "all",
|
|
468
|
+
Print: "print",
|
|
469
|
+
Modify: "modify",
|
|
470
|
+
Copy: "copy",
|
|
471
|
+
Annotate: "annotate",
|
|
472
|
+
FillForms: "fill-forms",
|
|
473
|
+
Accessibility: "accessibility",
|
|
474
|
+
Assemble: "assemble"
|
|
475
|
+
};
|
|
476
|
+
var FileRelationship = {
|
|
477
|
+
Source: "source",
|
|
478
|
+
Data: "data",
|
|
479
|
+
Alternative: "alternative",
|
|
480
|
+
Supplement: "supplement",
|
|
481
|
+
Unspecified: "unspecified"
|
|
482
|
+
};
|
|
449
483
|
var BuiltinFont = {
|
|
450
484
|
Courier: "Courier",
|
|
451
485
|
CourierBold: "Courier-Bold",
|
|
@@ -475,10 +509,14 @@ var NoAttr = null;
|
|
|
475
509
|
function nowUnix() {
|
|
476
510
|
return BigInt(Math.floor(Date.now() / 1e3));
|
|
477
511
|
}
|
|
512
|
+
function secureRandomBytes(count) {
|
|
513
|
+
return crypto.getRandomValues(new Uint8Array(count));
|
|
514
|
+
}
|
|
478
515
|
async function initLpdf(wasmSource, licenseKey = "") {
|
|
479
516
|
await __wbg_init(wasmSource);
|
|
480
517
|
const fontMap = /* @__PURE__ */ new Map();
|
|
481
518
|
const imageMap = /* @__PURE__ */ new Map();
|
|
519
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
482
520
|
const markdownStyles = /* @__PURE__ */ new Map();
|
|
483
521
|
return {
|
|
484
522
|
loadFont(name, bytes) {
|
|
@@ -487,6 +525,9 @@ async function initLpdf(wasmSource, licenseKey = "") {
|
|
|
487
525
|
loadImage(name, bytes) {
|
|
488
526
|
imageMap.set(name, bytes);
|
|
489
527
|
},
|
|
528
|
+
loadFile(name, bytes) {
|
|
529
|
+
fileMap.set(name, bytes);
|
|
530
|
+
},
|
|
490
531
|
loadMarkdownStyles(src, text) {
|
|
491
532
|
markdownStyles.set(src, text);
|
|
492
533
|
},
|
|
@@ -502,38 +543,41 @@ async function initLpdf(wasmSource, licenseKey = "") {
|
|
|
502
543
|
for (const [name, bytes] of imageMap) {
|
|
503
544
|
engine.load_image(name, bytes);
|
|
504
545
|
}
|
|
546
|
+
for (const [name, bytes] of fileMap) {
|
|
547
|
+
engine.load_file(name, bytes);
|
|
548
|
+
}
|
|
505
549
|
for (const [src, text] of markdownStyles) {
|
|
506
550
|
engine.load_markdown_styles(src, text);
|
|
507
551
|
}
|
|
508
552
|
if (callOptions.createdOn) {
|
|
509
553
|
engine.set_created_on(callOptions.createdOn);
|
|
510
554
|
}
|
|
555
|
+
const encryption = encryptionArguments(callOptions, secureRandomBytes);
|
|
511
556
|
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));
|
|
557
|
+
try {
|
|
558
|
+
if (typeof input === "string") {
|
|
559
|
+
const dataJson = callOptions.data != null ? JSON.stringify(callOptions.data) : null;
|
|
560
|
+
pdf = engine.render_pdf(input, dataJson, ...encryption);
|
|
519
561
|
} else {
|
|
520
|
-
|
|
521
|
-
const xml = mod.constructor.kit_to_xml?.(JSON.stringify(input)) ?? "";
|
|
522
|
-
pdf = engine.render_pdf(xml, null);
|
|
562
|
+
pdf = engine.render_tree_pdf(JSON.stringify(input), ...encryption);
|
|
523
563
|
}
|
|
564
|
+
} finally {
|
|
565
|
+
engine.free();
|
|
524
566
|
}
|
|
525
|
-
engine.free();
|
|
526
567
|
return pdf;
|
|
527
568
|
}
|
|
528
569
|
};
|
|
529
570
|
}
|
|
530
571
|
export {
|
|
531
572
|
BuiltinFont,
|
|
573
|
+
Cipher,
|
|
532
574
|
FieldType,
|
|
575
|
+
FileRelationship,
|
|
533
576
|
FootnoteCounter,
|
|
534
577
|
NoAttr,
|
|
535
578
|
Orientation,
|
|
536
579
|
PageScope,
|
|
580
|
+
Permission,
|
|
537
581
|
Pin,
|
|
538
582
|
SectionType,
|
|
539
583
|
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,13 @@ 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;
|
|
63
34
|
private readonly _markdownStyles;
|
|
64
35
|
private _disposed;
|
|
65
|
-
private _encrypt;
|
|
66
36
|
constructor();
|
|
67
37
|
/**
|
|
68
38
|
* Set the license key. Returns `this` for chaining.
|
|
@@ -90,21 +60,16 @@ export declare class PdfEngine {
|
|
|
90
60
|
* Call before `render`. Returns `this` for chaining.
|
|
91
61
|
*/
|
|
92
62
|
loadImage(name: string, bytes: Uint8Array): this;
|
|
63
|
+
/**
|
|
64
|
+
* Register the bytes of a file the document carries, for the `<file>` of its `<attachments>` whose `ref`, or with
|
|
65
|
+
* no ref whose name, is `name`. The PDF carries them as they are. Call before `render`. Returns `this` for chaining.
|
|
66
|
+
*/
|
|
67
|
+
loadFile(name: string, bytes: Uint8Array): this;
|
|
93
68
|
/**
|
|
94
69
|
* Register the text of a file of Markdown rules, the root of which is a `<markdown-styles>`, for the `src` that
|
|
95
70
|
* names it, as `<markdown-styles src="…">` does. Call before `render`. Returns `this` for chaining.
|
|
96
71
|
*/
|
|
97
72
|
loadMarkdownStyles(src: string, text: string): this;
|
|
98
|
-
/**
|
|
99
|
-
* Configure encryption for all subsequent `render` calls: AES-256 unless
|
|
100
|
-
* `options.algorithm` says `'rc4-128'`. Returns `this` for chaining.
|
|
101
|
-
*/
|
|
102
|
-
setEncryption(options: EncryptOptions): this;
|
|
103
|
-
/**
|
|
104
|
-
* Remove any previously configured encryption.
|
|
105
|
-
* Returns `this` for chaining.
|
|
106
|
-
*/
|
|
107
|
-
clearEncryption(): this;
|
|
108
73
|
/**
|
|
109
74
|
* Release held resources. Idempotent. Subsequent `render` / `loadFont`
|
|
110
75
|
* calls after disposal will throw.
|
|
@@ -116,6 +81,11 @@ export declare class PdfEngine {
|
|
|
116
81
|
* their `src`. A file that can't be read is left for the engine to report, naming the `src`.
|
|
117
82
|
*/
|
|
118
83
|
private _loadMarkdownStyles;
|
|
84
|
+
/**
|
|
85
|
+
* Hand the engine the files the document carries: the ones loaded here, and the ones read from the `src` of a file
|
|
86
|
+
* that wasn't. A `src` that can't be read is an error that names the file and the path.
|
|
87
|
+
*/
|
|
88
|
+
private _loadFiles;
|
|
119
89
|
private _throwIfDisposed;
|
|
120
90
|
/**
|
|
121
91
|
* Render an lpdf XML string to PDF bytes (Node.js).
|