@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.
@@ -12,10 +12,17 @@ export class LpdfEngine {
12
12
  wasm.__wbg_lpdfengine_free(ptr, 0);
13
13
  }
14
14
  /**
15
- * Remove any previously configured encryption.
15
+ * Register the bytes of a file a document carries, for the `<file>` of its `<attachments>` whose `ref`, or with
16
+ * no ref whose name, is `name`. The PDF carries them as they are.
17
+ * @param {string} name
18
+ * @param {Uint8Array} bytes
16
19
  */
17
- clear_encryption() {
18
- wasm.lpdfengine_clear_encryption(this.__wbg_ptr);
20
+ load_file(name, bytes) {
21
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
22
+ const len0 = WASM_VECTOR_LEN;
23
+ const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
24
+ const len1 = WASM_VECTOR_LEN;
25
+ wasm.lpdfengine_load_file(this.__wbg_ptr, ptr0, len0, ptr1, len1);
19
26
  }
20
27
  /**
21
28
  * Register raw font bytes (TTF/OTF) for a custom font name.
@@ -98,22 +105,38 @@ export class LpdfEngine {
98
105
  * `json_data` is an optional JSON string used to resolve `data-*`
99
106
  * attributes in the template. Pass `None` (or `null` / `undefined` from
100
107
  * JavaScript) to render the template with its inline fallback content.
108
+ *
109
+ * The rest is for a document that asks for encryption in its `<output>`, which sets the cipher and
110
+ * the permissions: the passwords, which the template never holds, and `entropy`, at least 32 random
111
+ * bytes from the host's secure generator for AES-256. A document that asks for encryption needs an
112
+ * owner password, or `skip_encryption` to render it unencrypted, as a preview does; passwords for a
113
+ * document that doesn't ask for it are an error, and so are passwords with `skip_encryption`.
101
114
  * @param {string} xml
102
- * @param {string | null} [json_data]
115
+ * @param {string | null | undefined} json_data
116
+ * @param {string | null | undefined} user_password
117
+ * @param {string | null | undefined} owner_password
118
+ * @param {boolean} skip_encryption
119
+ * @param {Uint8Array} entropy
103
120
  * @returns {Uint8Array}
104
121
  */
105
- render_pdf(xml, json_data) {
122
+ render_pdf(xml, json_data, user_password, owner_password, skip_encryption, entropy) {
106
123
  const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
107
124
  const len0 = WASM_VECTOR_LEN;
108
125
  var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
109
126
  var len1 = WASM_VECTOR_LEN;
110
- const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1);
127
+ var ptr2 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
128
+ var len2 = WASM_VECTOR_LEN;
129
+ var ptr3 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
130
+ var len3 = WASM_VECTOR_LEN;
131
+ const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
132
+ const len4 = WASM_VECTOR_LEN;
133
+ const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, skip_encryption, ptr4, len4);
111
134
  if (ret[3]) {
112
135
  throw takeFromExternrefTable0(ret[2]);
113
136
  }
114
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
137
+ var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
115
138
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
116
- return v3;
139
+ return v6;
117
140
  }
118
141
  /**
119
142
  * @param {string} json
@@ -140,23 +163,37 @@ export class LpdfEngine {
140
163
  * when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
141
164
  * intermediate XML serialisation step. PHP, Python, and .NET adapters also
142
165
  * use this entry point.
166
+ *
167
+ * The passwords, `skip_encryption` and `entropy` are those of `render_pdf`, for a document whose
168
+ * `output` asks for encryption.
143
169
  * @param {string} json
170
+ * @param {string | null | undefined} user_password
171
+ * @param {string | null | undefined} owner_password
172
+ * @param {boolean} skip_encryption
173
+ * @param {Uint8Array} entropy
144
174
  * @returns {Uint8Array}
145
175
  */
146
- render_tree_pdf(json) {
176
+ render_tree_pdf(json, user_password, owner_password, skip_encryption, entropy) {
147
177
  const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
148
178
  const len0 = WASM_VECTOR_LEN;
149
- const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0);
179
+ var ptr1 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ var len1 = WASM_VECTOR_LEN;
181
+ var ptr2 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
182
+ var len2 = WASM_VECTOR_LEN;
183
+ const ptr3 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
184
+ const len3 = WASM_VECTOR_LEN;
185
+ const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, skip_encryption, ptr3, len3);
150
186
  if (ret[3]) {
151
187
  throw takeFromExternrefTable0(ret[2]);
152
188
  }
153
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
189
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
154
190
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
155
- return v2;
191
+ return v5;
156
192
  }
157
193
  /**
158
- * Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
159
- * When provided, written as `/CreationDate` in the PDF info dictionary.
194
+ * Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`, `"2024-06-01T12:00:00.000Z"` or
195
+ * `"2024-06-01T12:00:00+01:00"`). When provided, written as `/CreationDate` in the PDF info dictionary, with
196
+ * the precision and the time zone it was given in; a value that is not a date makes the render an error.
160
197
  * Omitting this keeps builds reproducible (no embedded timestamp).
161
198
  * @param {string} iso
162
199
  */
@@ -165,42 +202,6 @@ export class LpdfEngine {
165
202
  const len0 = WASM_VECTOR_LEN;
166
203
  wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
167
204
  }
168
- /**
169
- * Configure encryption applied to every subsequent `render_pdf` call.
170
- *
171
- * `permissions_json` is a JSON object with boolean fields matching the
172
- * `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
173
- * `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
174
- *
175
- * `algorithm` is `"aes-256"` or `"rc4-128"`. AES-256 needs `entropy`: at least 32
176
- * random bytes from the host's secure generator, from which the core cuts the file
177
- * key, salts and IVs. RC4-128 ignores it. Fails when the algorithm is unknown or
178
- * AES-256 gets too little entropy.
179
- *
180
- * To apply permissions without an open password, pass an empty `user_password`
181
- * and a non-empty `owner_password`.
182
- * @param {string} user_password
183
- * @param {string} owner_password
184
- * @param {string} permissions_json
185
- * @param {string} algorithm
186
- * @param {Uint8Array} entropy
187
- */
188
- set_encryption(user_password, owner_password, permissions_json, algorithm, entropy) {
189
- const ptr0 = passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
190
- const len0 = WASM_VECTOR_LEN;
191
- const ptr1 = passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
192
- const len1 = WASM_VECTOR_LEN;
193
- const ptr2 = passStringToWasm0(permissions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
194
- const len2 = WASM_VECTOR_LEN;
195
- const ptr3 = passStringToWasm0(algorithm, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
196
- const len3 = WASM_VECTOR_LEN;
197
- const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
198
- const len4 = WASM_VECTOR_LEN;
199
- const ret = wasm.lpdfengine_set_encryption(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
200
- if (ret[1]) {
201
- throw takeFromExternrefTable0(ret[0]);
202
- }
203
- }
204
205
  /**
205
206
  * Inject glyph advance-width tables for custom fonts.
206
207
  *
package/dist/wasm/lpdf.js CHANGED
@@ -12,10 +12,17 @@ class LpdfEngine {
12
12
  wasm.__wbg_lpdfengine_free(ptr, 0);
13
13
  }
14
14
  /**
15
- * Remove any previously configured encryption.
15
+ * Register the bytes of a file a document carries, for the `<file>` of its `<attachments>` whose `ref`, or with
16
+ * no ref whose name, is `name`. The PDF carries them as they are.
17
+ * @param {string} name
18
+ * @param {Uint8Array} bytes
16
19
  */
17
- clear_encryption() {
18
- wasm.lpdfengine_clear_encryption(this.__wbg_ptr);
20
+ load_file(name, bytes) {
21
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
22
+ const len0 = WASM_VECTOR_LEN;
23
+ const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
24
+ const len1 = WASM_VECTOR_LEN;
25
+ wasm.lpdfengine_load_file(this.__wbg_ptr, ptr0, len0, ptr1, len1);
19
26
  }
20
27
  /**
21
28
  * Register raw font bytes (TTF/OTF) for a custom font name.
@@ -98,22 +105,38 @@ class LpdfEngine {
98
105
  * `json_data` is an optional JSON string used to resolve `data-*`
99
106
  * attributes in the template. Pass `None` (or `null` / `undefined` from
100
107
  * JavaScript) to render the template with its inline fallback content.
108
+ *
109
+ * The rest is for a document that asks for encryption in its `<output>`, which sets the cipher and
110
+ * the permissions: the passwords, which the template never holds, and `entropy`, at least 32 random
111
+ * bytes from the host's secure generator for AES-256. A document that asks for encryption needs an
112
+ * owner password, or `skip_encryption` to render it unencrypted, as a preview does; passwords for a
113
+ * document that doesn't ask for it are an error, and so are passwords with `skip_encryption`.
101
114
  * @param {string} xml
102
- * @param {string | null} [json_data]
115
+ * @param {string | null | undefined} json_data
116
+ * @param {string | null | undefined} user_password
117
+ * @param {string | null | undefined} owner_password
118
+ * @param {boolean} skip_encryption
119
+ * @param {Uint8Array} entropy
103
120
  * @returns {Uint8Array}
104
121
  */
105
- render_pdf(xml, json_data) {
122
+ render_pdf(xml, json_data, user_password, owner_password, skip_encryption, entropy) {
106
123
  const ptr0 = passStringToWasm0(xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
107
124
  const len0 = WASM_VECTOR_LEN;
108
125
  var ptr1 = isLikeNone(json_data) ? 0 : passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
109
126
  var len1 = WASM_VECTOR_LEN;
110
- const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1);
127
+ var ptr2 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
128
+ var len2 = WASM_VECTOR_LEN;
129
+ var ptr3 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
130
+ var len3 = WASM_VECTOR_LEN;
131
+ const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
132
+ const len4 = WASM_VECTOR_LEN;
133
+ const ret = wasm.lpdfengine_render_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, skip_encryption, ptr4, len4);
111
134
  if (ret[3]) {
112
135
  throw takeFromExternrefTable0(ret[2]);
113
136
  }
114
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
137
+ var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
115
138
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
116
- return v3;
139
+ return v6;
117
140
  }
118
141
  /**
119
142
  * @param {string} json
@@ -140,23 +163,37 @@ class LpdfEngine {
140
163
  * when an `LpdfDocument` Kit tree is passed to `renderPdf()`, avoiding an
141
164
  * intermediate XML serialisation step. PHP, Python, and .NET adapters also
142
165
  * use this entry point.
166
+ *
167
+ * The passwords, `skip_encryption` and `entropy` are those of `render_pdf`, for a document whose
168
+ * `output` asks for encryption.
143
169
  * @param {string} json
170
+ * @param {string | null | undefined} user_password
171
+ * @param {string | null | undefined} owner_password
172
+ * @param {boolean} skip_encryption
173
+ * @param {Uint8Array} entropy
144
174
  * @returns {Uint8Array}
145
175
  */
146
- render_tree_pdf(json) {
176
+ render_tree_pdf(json, user_password, owner_password, skip_encryption, entropy) {
147
177
  const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
148
178
  const len0 = WASM_VECTOR_LEN;
149
- const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0);
179
+ var ptr1 = isLikeNone(user_password) ? 0 : passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ var len1 = WASM_VECTOR_LEN;
181
+ var ptr2 = isLikeNone(owner_password) ? 0 : passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
182
+ var len2 = WASM_VECTOR_LEN;
183
+ const ptr3 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
184
+ const len3 = WASM_VECTOR_LEN;
185
+ const ret = wasm.lpdfengine_render_tree_pdf(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, skip_encryption, ptr3, len3);
150
186
  if (ret[3]) {
151
187
  throw takeFromExternrefTable0(ret[2]);
152
188
  }
153
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
189
+ var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
154
190
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
155
- return v2;
191
+ return v5;
156
192
  }
157
193
  /**
158
- * Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`).
159
- * When provided, written as `/CreationDate` in the PDF info dictionary.
194
+ * Set an optional ISO 8601 creation timestamp (e.g. `"2024-06-01T12:00:00"`, `"2024-06-01T12:00:00.000Z"` or
195
+ * `"2024-06-01T12:00:00+01:00"`). When provided, written as `/CreationDate` in the PDF info dictionary, with
196
+ * the precision and the time zone it was given in; a value that is not a date makes the render an error.
160
197
  * Omitting this keeps builds reproducible (no embedded timestamp).
161
198
  * @param {string} iso
162
199
  */
@@ -165,42 +202,6 @@ class LpdfEngine {
165
202
  const len0 = WASM_VECTOR_LEN;
166
203
  wasm.lpdfengine_set_created_on(this.__wbg_ptr, ptr0, len0);
167
204
  }
168
- /**
169
- * Configure encryption applied to every subsequent `render_pdf` call.
170
- *
171
- * `permissions_json` is a JSON object with boolean fields matching the
172
- * `Permissions` struct (`print`, `modify`, `copy`, `annotate`, `fill_forms`,
173
- * `accessibility`, `assemble`, `print_hq`). Omitted fields default to `true`.
174
- *
175
- * `algorithm` is `"aes-256"` or `"rc4-128"`. AES-256 needs `entropy`: at least 32
176
- * random bytes from the host's secure generator, from which the core cuts the file
177
- * key, salts and IVs. RC4-128 ignores it. Fails when the algorithm is unknown or
178
- * AES-256 gets too little entropy.
179
- *
180
- * To apply permissions without an open password, pass an empty `user_password`
181
- * and a non-empty `owner_password`.
182
- * @param {string} user_password
183
- * @param {string} owner_password
184
- * @param {string} permissions_json
185
- * @param {string} algorithm
186
- * @param {Uint8Array} entropy
187
- */
188
- set_encryption(user_password, owner_password, permissions_json, algorithm, entropy) {
189
- const ptr0 = passStringToWasm0(user_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
190
- const len0 = WASM_VECTOR_LEN;
191
- const ptr1 = passStringToWasm0(owner_password, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
192
- const len1 = WASM_VECTOR_LEN;
193
- const ptr2 = passStringToWasm0(permissions_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
194
- const len2 = WASM_VECTOR_LEN;
195
- const ptr3 = passStringToWasm0(algorithm, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
196
- const len3 = WASM_VECTOR_LEN;
197
- const ptr4 = passArray8ToWasm0(entropy, wasm.__wbindgen_malloc);
198
- const len4 = WASM_VECTOR_LEN;
199
- const ret = wasm.lpdfengine_set_encryption(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
200
- if (ret[1]) {
201
- throw takeFromExternrefTable0(ret[0]);
202
- }
203
- }
204
205
  /**
205
206
  * Inject glyph advance-width tables for custom fonts.
206
207
  *
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lpdfio/lpdf",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Node.js SDK for Lpdf — PDF as Code on every platform. You describe a document as code or XML. Lpdf renders a compact, pixel-perfect PDF — identical across platforms.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",