@lpdfio/lpdf 0.29.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/dist/browser.js CHANGED
@@ -11,10 +11,17 @@ var LpdfEngine = class {
11
11
  wasm.__wbg_lpdfengine_free(ptr, 0);
12
12
  }
13
13
  /**
14
- * Remove any previously configured encryption.
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
- clear_encryption() {
17
- wasm.lpdfengine_clear_encryption(this.__wbg_ptr);
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.
@@ -45,6 +52,20 @@ var LpdfEngine = class {
45
52
  const len1 = WASM_VECTOR_LEN;
46
53
  wasm.lpdfengine_load_image(this.__wbg_ptr, ptr0, len0, ptr1, len1);
47
54
  }
55
+ /**
56
+ * Register the text of a file of Markdown rules, the root of which is a `<markdown-styles>`, for the
57
+ * `src` that names it. The engine reads no files: call this once for every `<markdown-styles src="…">`
58
+ * of the document before `render_pdf`, as `load_font` is called for a font.
59
+ * @param {string} src
60
+ * @param {string} xml
61
+ */
62
+ load_markdown_styles(src, xml) {
63
+ const ptr0 = passStringToWasm0(src, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
64
+ const len0 = WASM_VECTOR_LEN;
65
+ const ptr1 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
+ const len1 = WASM_VECTOR_LEN;
67
+ wasm.lpdfengine_load_markdown_styles(this.__wbg_ptr, ptr0, len0, ptr1, len1);
68
+ }
48
69
  /**
49
70
  * @param {string} license_key
50
71
  */
@@ -83,22 +104,38 @@ var LpdfEngine = class {
83
104
  * `json_data` is an optional JSON string used to resolve `data-*`
84
105
  * attributes in the template. Pass `None` (or `null` / `undefined` from
85
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`.
86
113
  * @param {string} xml
87
- * @param {string | null} [json_data]
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
88
119
  * @returns {Uint8Array}
89
120
  */
90
- render_pdf(xml, json_data) {
121
+ render_pdf(xml, json_data, user_password, owner_password, skip_encryption, entropy) {
91
122
  const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
123
  const len0 = WASM_VECTOR_LEN;
93
124
  var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
94
125
  var len1 = WASM_VECTOR_LEN;
95
- const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1);
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);
96
133
  if (ret[3]) {
97
134
  throw takeFromExternrefTable0(ret[2]);
98
135
  }
99
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
136
+ var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
100
137
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
101
- return v3;
138
+ return v6;
102
139
  }
103
140
  /**
104
141
  * @param {string} json
@@ -125,23 +162,37 @@ var LpdfEngine = class {
125
162
  * when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
126
163
  * intermediate XML serialisation step. PHP, Python, and .NET adapters also
127
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.
128
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
129
173
  * @returns {Uint8Array}
130
174
  */
131
- render_tree_pdf(json) {
175
+ render_tree_pdf(json, user_password, owner_password, skip_encryption, entropy) {
132
176
  const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
133
177
  const len0 = WASM_VECTOR_LEN;
134
- const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0);
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);
135
185
  if (ret[3]) {
136
186
  throw takeFromExternrefTable0(ret[2]);
137
187
  }
138
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
188
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
139
189
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
140
- return v2;
190
+ return v5;
141
191
  }
142
192
  /**
143
- * Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
144
- * 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.
145
196
  * Omitting this keeps builds reproducible (no embedded timestamp).
146
197
  * @param {string} iso
147
198
  */
@@ -150,28 +201,6 @@ var LpdfEngine = class {
150
201
  const len0 = WASM_VECTOR_LEN;
151
202
  wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
152
203
  }
153
- /**
154
- * Configure RC4-128 encryption applied to every subsequent `render_pdf` call.
155
- *
156
- * `permissions_json` is a JSON object with boolean fields matching the
157
- * `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
158
- * `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
159
- *
160
- * To apply permissions without an open password, pass an empty `user_password`
161
- * and a non-empty `owner_password`.
162
- * @param {string} user_password
163
- * @param {string} owner_password
164
- * @param {string} permissions_json
165
- */
166
- set_encryption(user_password, owner_password, permissions_json) {
167
- const ptr0 = passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
168
- const len0 = WASM_VECTOR_LEN;
169
- const ptr1 = passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
170
- const len1 = WASM_VECTOR_LEN;
171
- const ptr2 = passStringToWasm0(permissions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
172
- const len2 = WASM_VECTOR_LEN;
173
- wasm.lpdfengine_set_encryption(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
174
- }
175
204
  /**
176
205
  * Inject glyph advance-width tables for custom fonts.
177
206
  *
@@ -392,6 +421,18 @@ async function __wbg_init(module_or_path) {
392
421
  return __wbg_finalize_init(instance, module);
393
422
  }
394
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
+
395
436
  // src/constants.ts
396
437
  var FieldType = {
397
438
  Text: "text",
@@ -418,6 +459,27 @@ var FootnoteCounter = {
418
459
  Section: "section",
419
460
  Document: "document"
420
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
+ };
421
483
  var BuiltinFont = {
422
484
  Courier: "Courier",
423
485
  CourierBold: "Courier-Bold",
@@ -447,10 +509,15 @@ var NoAttr = null;
447
509
  function nowUnix() {
448
510
  return BigInt(Math.floor(Date.now() / 1e3));
449
511
  }
512
+ function secureRandomBytes(count) {
513
+ return crypto.getRandomValues(new Uint8Array(count));
514
+ }
450
515
  async function initLpdf(wasmSource, licenseKey = "") {
451
516
  await __wbg_init(wasmSource);
452
517
  const fontMap = /* @__PURE__ */ new Map();
453
518
  const imageMap = /* @__PURE__ */ new Map();
519
+ const fileMap = /* @__PURE__ */ new Map();
520
+ const markdownStyles = /* @__PURE__ */ new Map();
454
521
  return {
455
522
  loadFont(name, bytes) {
456
523
  fontMap.set(name, bytes);
@@ -458,6 +525,12 @@ async function initLpdf(wasmSource, licenseKey = "") {
458
525
  loadImage(name, bytes) {
459
526
  imageMap.set(name, bytes);
460
527
  },
528
+ loadFile(name, bytes) {
529
+ fileMap.set(name, bytes);
530
+ },
531
+ loadMarkdownStyles(src, text) {
532
+ markdownStyles.set(src, text);
533
+ },
461
534
  checkLicenseKey(key) {
462
535
  return JSON.parse(check_license(key ?? licenseKey, nowUnix()));
463
536
  },
@@ -470,35 +543,41 @@ async function initLpdf(wasmSource, licenseKey = "") {
470
543
  for (const [name, bytes] of imageMap) {
471
544
  engine.load_image(name, bytes);
472
545
  }
546
+ for (const [name, bytes] of fileMap) {
547
+ engine.load_file(name, bytes);
548
+ }
549
+ for (const [src, text] of markdownStyles) {
550
+ engine.load_markdown_styles(src, text);
551
+ }
473
552
  if (callOptions.createdOn) {
474
553
  engine.set_created_on(callOptions.createdOn);
475
554
  }
555
+ const encryption = encryptionArguments(callOptions, secureRandomBytes);
476
556
  let pdf;
477
- if (typeof input === "string") {
478
- const dataJson = callOptions.data != null ? JSON.stringify(callOptions.data) : null;
479
- pdf = engine.render_pdf(input, dataJson);
480
- } else {
481
- const wasmExt = engine;
482
- if (typeof wasmExt.render_tree_pdf === "function") {
483
- 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);
484
561
  } else {
485
- const mod = engine;
486
- const xml = mod.constructor.kit_to_xml?.(JSON.stringify(input)) ?? "";
487
- pdf = engine.render_pdf(xml, null);
562
+ pdf = engine.render_tree_pdf(JSON.stringify(input), ...encryption);
488
563
  }
564
+ } finally {
565
+ engine.free();
489
566
  }
490
- engine.free();
491
567
  return pdf;
492
568
  }
493
569
  };
494
570
  }
495
571
  export {
496
572
  BuiltinFont,
573
+ Cipher,
497
574
  FieldType,
575
+ FileRelationship,
498
576
  FootnoteCounter,
499
577
  NoAttr,
500
578
  Orientation,
501
579
  PageScope,
580
+ Permission,
502
581
  Pin,
503
582
  SectionType,
504
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
- import type { LpdfSpanNode } from './layout';
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, string>;
27
+ attrs: Record<string, AttrValue>;
27
28
  }
28
29
  export interface LpdfCanvasLineNode {
29
30
  type: 'line';
30
- attrs: Record<string, string>;
31
+ attrs: Record<string, AttrValue>;
31
32
  }
32
33
  export interface LpdfCanvasEllipseNode {
33
34
  type: 'ellipse';
34
- attrs: Record<string, string>;
35
+ attrs: Record<string, AttrValue>;
35
36
  }
36
37
  export interface LpdfCanvasCircleNode {
37
38
  type: 'circle';
38
- attrs: Record<string, string>;
39
+ attrs: Record<string, AttrValue>;
39
40
  }
40
41
  export interface LpdfCanvasPathNode {
41
42
  type: 'path';
42
- attrs: Record<string, string>;
43
+ attrs: Record<string, AttrValue>;
43
44
  }
44
45
  export interface LpdfCanvasTextAtNode {
45
46
  type: 'text-at';
46
- attrs: Record<string, string>;
47
- nodes: (string | LpdfSpanNode)[];
47
+ attrs: Record<string, AttrValue>;
48
+ nodes: (string | LpdfSpanNode | LpdfCodeSpanNode)[];
48
49
  }
49
50
  export interface LpdfCanvasImgAtNode {
50
51
  type: 'img-at';
51
- attrs: Record<string, string>;
52
+ attrs: Record<string, AttrValue>;
52
53
  }
53
54
  export interface LpdfCanvasBarcodeAtNode {
54
55
  type: 'barcode-at';
55
- attrs: Record<string, 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, string>;
61
+ attrs: Record<string, AttrValue>;
61
62
  nodes: LpdfCanvasPrimitiveNode[];
62
63
  }
63
64
  declare function rect(attrs: RectAttr): LpdfCanvasRectNode;
@@ -65,7 +66,7 @@ declare function line(attrs: LineAttr): LpdfCanvasLineNode;
65
66
  declare function ellipse(attrs: EllipseAttr): LpdfCanvasEllipseNode;
66
67
  declare function circle(attrs: CircleAttr): LpdfCanvasCircleNode;
67
68
  declare function path(attrs: PathAttr): LpdfCanvasPathNode;
68
- declare function textAt(attrs: TextAtAttr, nodes?: (string | LpdfSpanNode)[]): LpdfCanvasTextAtNode;
69
+ declare function textAt(attrs: TextAtAttr, nodes?: (string | LpdfSpanNode | LpdfCodeSpanNode)[]): LpdfCanvasTextAtNode;
69
70
  declare function imgAt(attrs: ImgAtAttr): LpdfCanvasImgAtNode;
70
71
  declare function barcodeAt(attrs: BarcodeAtAttr): LpdfCanvasBarcodeAtNode;
71
72
  declare function layer(attrs: LayerAttr | null, nodes?: LpdfCanvasPrimitiveNode[]): LpdfCanvasLayerNode;
@@ -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 { RenderOptions } from './_shared';
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,32 +26,13 @@ export interface LicenseCheck {
26
26
  export declare class LpdfRenderError extends Error {
27
27
  constructor(message: string);
28
28
  }
29
- /** PDF permission flags for RC4-128 encryption. 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
- /** RC4-128 encryption options passed to {@link PdfEngine.setEncryption}. */
41
- export interface EncryptOptions {
42
- /** Open password shown to readers. Empty string = no open password required. */
43
- userPassword: string;
44
- /** Owner (permissions) password. Required; must be non-empty. */
45
- ownerPassword: string;
46
- /** Permission flags applied to the document. Omitted flags default to `true`. */
47
- permissions?: EncryptPermissions;
48
- }
49
29
  export declare class PdfEngine {
50
30
  private _licenseKey;
51
31
  private readonly _fonts;
52
32
  private readonly _images;
33
+ private readonly _files;
34
+ private readonly _markdownStyles;
53
35
  private _disposed;
54
- private _encrypt;
55
36
  constructor();
56
37
  /**
57
38
  * Set the license key. Returns `this` for chaining.
@@ -80,21 +61,31 @@ export declare class PdfEngine {
80
61
  */
81
62
  loadImage(name: string, bytes: Uint8Array): this;
82
63
  /**
83
- * Configure RC4-128 encryption for all subsequent `render` calls.
84
- * Returns `this` for chaining.
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.
85
66
  */
86
- setEncryption(options: EncryptOptions): this;
67
+ loadFile(name: string, bytes: Uint8Array): this;
87
68
  /**
88
- * Remove any previously configured encryption.
89
- * Returns `this` for chaining.
69
+ * Register the text of a file of Markdown rules, the root of which is a `<markdown-styles>`, for the `src` that
70
+ * names it, as `<markdown-styles src="…">` does. Call before `render`. Returns `this` for chaining.
90
71
  */
91
- clearEncryption(): this;
72
+ loadMarkdownStyles(src: string, text: string): this;
92
73
  /**
93
74
  * Release held resources. Idempotent. Subsequent `render` / `loadFont`
94
75
  * calls after disposal will throw.
95
76
  */
96
77
  dispose(): void;
97
78
  [Symbol.dispose](): void;
79
+ /**
80
+ * Hand the engine the files of Markdown rules that a document names: the ones loaded here, and the ones read from
81
+ * their `src`. A file that can't be read is left for the engine to report, naming the `src`.
82
+ */
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;
98
89
  private _throwIfDisposed;
99
90
  /**
100
91
  * Render an lpdf XML string to PDF bytes (Node.js).