pdf-oxide-wasm 0.3.38 → 0.3.39

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.
@@ -1,6 +1,26 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * Horizontal-alignment enum shared by `textInRect`, buffered `table`, and
6
+ * `streamingTable`. Maps 1:1 onto [`crate::writer::TextAlign`] /
7
+ * [`crate::writer::CellAlign`]. Exported to JS as `Align` via `js_name`.
8
+ */
9
+ export enum Align {
10
+ /**
11
+ * Align to the left edge.
12
+ */
13
+ Left = 0,
14
+ /**
15
+ * Center horizontally.
16
+ */
17
+ Center = 1,
18
+ /**
19
+ * Align to the right edge.
20
+ */
21
+ Right = 2,
22
+ }
23
+
4
24
  /**
5
25
  * Style configuration for header/footer text.
6
26
  */
@@ -25,6 +45,45 @@ export class ArtifactStyle {
25
45
  constructor();
26
46
  }
27
47
 
48
+ /**
49
+ * WASM handle to a streaming-table building session. Created by
50
+ * `FluentPageBuilder.streamingTable()`; rows are pushed via `pushRow`,
51
+ * and the session is sealed with `finish()`.
52
+ *
53
+ * Single-use: `finish()` twice throws, and `pushRow` after `finish()`
54
+ * throws. The rows are buffered and replayed against the real Rust
55
+ * `StreamingTable` at `WasmFluentPageBuilder.done()` commit time —
56
+ * preserving the FluentPageBuilder borrow-lifetime invariant that can't
57
+ * cross the wasm-bindgen boundary.
58
+ */
59
+ export class StreamingTable {
60
+ private constructor();
61
+ free(): void;
62
+ [Symbol.dispose](): void;
63
+ /**
64
+ * Number of columns configured on this streaming table.
65
+ */
66
+ columnCount(): number;
67
+ /**
68
+ * Seal the streaming table — the buffered rows are flushed onto the
69
+ * parent page's op queue, to be replayed against the real Rust
70
+ * `StreamingTable` at `done()` commit time. Calling `finish()` twice
71
+ * throws.
72
+ */
73
+ finish(): void;
74
+ /**
75
+ * Push one row as an array of cell strings (all rowspan=1). Returns an
76
+ * error if the table has already been finished or if the row's cell count
77
+ * does not match the column count.
78
+ */
79
+ pushRow(cells: string[]): void;
80
+ /**
81
+ * Push one row with per-cell rowspan values. `cells` is a JS array of
82
+ * `[text, rowspan]` two-element arrays. `rowspan == 1` is a normal cell.
83
+ */
84
+ pushRowSpan(cells: any): void;
85
+ }
86
+
28
87
  /**
29
88
  * A header or footer artifact definition.
30
89
  */
@@ -71,6 +130,17 @@ export class WasmCertificate {
71
130
  * the DER doesn't parse.
72
131
  */
73
132
  static load(data: Uint8Array): WasmCertificate;
133
+ /**
134
+ * Load a signer certificate + private key from PEM strings.
135
+ * `certPem` must begin `-----BEGIN CERTIFICATE-----`.
136
+ * `keyPem` must begin `-----BEGIN PRIVATE KEY-----` or `-----BEGIN RSA PRIVATE KEY-----`.
137
+ */
138
+ static loadPem(cert_pem: string, key_pem: string): WasmCertificate;
139
+ /**
140
+ * Load a signer certificate + private key from a PKCS#12 (.p12/.pfx) blob.
141
+ * `password` is the passphrase protecting the key bag.
142
+ */
143
+ static loadPkcs12(data: Uint8Array, password: string): WasmCertificate;
74
144
  /**
75
145
  * Whether the certificate is currently within its validity
76
146
  * window. Does NOT verify chain, trust-root, or revocation.
@@ -141,6 +211,12 @@ export class WasmDocumentBuilder {
141
211
  * Set document keywords (comma-separated per PDF convention).
142
212
  */
143
213
  keywords(keywords: string): void;
214
+ /**
215
+ * Set the document's natural language tag (e.g. `"en-US"`).
216
+ *
217
+ * Emitted as `/Lang` in the catalog when `taggedPdfUa1()` is set.
218
+ */
219
+ language(lang: string): void;
144
220
  /**
145
221
  * Start a new US Letter page.
146
222
  */
@@ -151,6 +227,10 @@ export class WasmDocumentBuilder {
151
227
  * chains off the instance returned here.
152
228
  */
153
229
  constructor();
230
+ /**
231
+ * Run a JavaScript script when the document is opened (`/OpenAction`).
232
+ */
233
+ onOpen(script: string): void;
154
234
  /**
155
235
  * Start a new page with custom dimensions in PDF points
156
236
  * (72 pt = 1 inch).
@@ -161,10 +241,24 @@ export class WasmDocumentBuilder {
161
241
  * **Consumes** `font` — reusing the `WasmEmbeddedFont` throws.
162
242
  */
163
243
  registerEmbeddedFont(name: string, font: WasmEmbeddedFont): void;
244
+ /**
245
+ * Add a role-map entry: custom structure type → standard PDF structure type.
246
+ *
247
+ * Emitted in `/RoleMap` inside the StructTreeRoot when `taggedPdfUa1()`
248
+ * is set. Multiple calls accumulate entries.
249
+ */
250
+ roleMap(custom: string, standard: string): void;
164
251
  /**
165
252
  * Set document subject.
166
253
  */
167
254
  subject(subject: string): void;
255
+ /**
256
+ * Enable PDF/UA-1 tagged PDF mode.
257
+ *
258
+ * When enabled, `build()` emits `/MarkInfo`, `/StructTreeRoot`, `/Lang`,
259
+ * and `/ViewerPreferences` in the catalog. Opt-in — no effect unless called.
260
+ */
261
+ taggedPdfUa1(): void;
168
262
  /**
169
263
  * Set document title.
170
264
  */
@@ -207,7 +301,22 @@ export class WasmFluentPageBuilder {
207
301
  free(): void;
208
302
  [Symbol.dispose](): void;
209
303
  at(x: number, y: number): void;
304
+ /**
305
+ * Place a 1-D barcode image at `(x, y, w, h)` on the page.
306
+ * `barcodeType`: 0=Code128 1=Code39 2=EAN13 3=EAN8 4=UPCA 5=ITF
307
+ * 6=Code93 7=Codabar.
308
+ */
309
+ barcode1d(barcode_type: number, data: string, x: number, y: number, w: number, h: number): void;
310
+ /**
311
+ * Place a QR-code image at `(x, y, size, size)` on the page.
312
+ */
313
+ barcodeQr(data: string, x: number, y: number, size: number): void;
210
314
  checkbox(name: string, x: number, y: number, w: number, h: number, checked: boolean): void;
315
+ /**
316
+ * Lay out `text` as balanced multi-column flow (`columnCount` columns,
317
+ * `gapPt` points between columns). Paragraphs in `text` are separated by `"\n\n"`.
318
+ */
319
+ columns(column_count: number, gap_pt: number, text: string): void;
211
320
  /**
212
321
  * Add a dropdown combo-box.
213
322
  */
@@ -224,22 +333,77 @@ export class WasmFluentPageBuilder {
224
333
  * ```
225
334
  */
226
335
  done(builder: WasmDocumentBuilder): void;
336
+ fieldCalculate(script: string): void;
337
+ fieldFormat(script: string): void;
338
+ fieldKeystroke(script: string): void;
339
+ fieldValidate(script: string): void;
227
340
  /**
228
341
  * Draw a filled rectangle. RGB channels in 0.0-1.0.
229
342
  */
230
343
  filledRect(x: number, y: number, w: number, h: number, r: number, g: number, b: number): void;
231
344
  font(name: string, size: number): void;
345
+ /**
346
+ * Add a footnote: inline `refMark` at the cursor and `noteText` body
347
+ * near the page bottom with a separator artifact line.
348
+ */
349
+ footnote(ref_mark: string, note_text: string): void;
232
350
  freeText(x: number, y: number, w: number, h: number, text: string): void;
233
351
  heading(level: number, text: string): void;
234
352
  highlight(r: number, g: number, b: number): void;
235
353
  horizontalRule(): void;
354
+ /**
355
+ * Embed a decorative image (JPEG/PNG/WebP bytes) as an /Artifact (no alt text).
356
+ */
357
+ imageArtifact(bytes: Uint8Array, x: number, y: number, w: number, h: number): void;
358
+ /**
359
+ * Embed an image (JPEG/PNG/WebP bytes) with an accessibility alt text.
360
+ */
361
+ imageWithAlt(bytes: Uint8Array, x: number, y: number, w: number, h: number, alt_text: string): void;
362
+ /**
363
+ * Emit `text` inline (advances cursorX only, not cursorY).
364
+ */
365
+ inline(text: string): void;
366
+ /**
367
+ * Inline bold run.
368
+ */
369
+ inlineBold(text: string): void;
370
+ /**
371
+ * Inline colored run (RGB 0.0–1.0).
372
+ */
373
+ inlineColor(r: number, g: number, b: number, text: string): void;
374
+ /**
375
+ * Inline italic run.
376
+ */
377
+ inlineItalic(text: string): void;
236
378
  /**
237
379
  * Draw a line from (x1, y1) to (x2, y2) with 1pt black stroke.
238
380
  */
239
381
  line(x1: number, y1: number, x2: number, y2: number): void;
382
+ linkJavascript(script: string): void;
240
383
  linkNamed(destination: string): void;
241
384
  linkPage(page: number): void;
242
385
  linkUrl(url: string): void;
386
+ /**
387
+ * Measure the rendered width of `text` in the builder's current font
388
+ * and size, in PDF points. Pure query — does not mutate state.
389
+ *
390
+ * Thin JS view over [`crate::writer::FluentPageBuilder::measure`]. The
391
+ * WASM class tracks the current font/size independently of the
392
+ * buffered ops so this query is served without a live builder.
393
+ */
394
+ measure(text: string): number;
395
+ /**
396
+ * Finish the current page and start a new one with the same page
397
+ * size. Cursor resets to the top-left margin (72, height-72). The
398
+ * builder's font carries over.
399
+ */
400
+ newPageSameSize(): void;
401
+ /**
402
+ * Advance cursorY by one line-height and reset cursorX to 72 pt.
403
+ */
404
+ newline(): void;
405
+ onClose(script: string): void;
406
+ onOpen(script: string): void;
243
407
  paragraph(text: string): void;
244
408
  /**
245
409
  * Add a clickable push button with a visible caption.
@@ -255,14 +419,67 @@ export class WasmFluentPageBuilder {
255
419
  * Draw a stroked rectangle outline (1pt black).
256
420
  */
257
421
  rect(x: number, y: number, w: number, h: number): void;
422
+ /**
423
+ * Points remaining on the current page below the cursor (down to the
424
+ * 72 pt bottom margin). Mirrors
425
+ * [`crate::writer::FluentPageBuilder::remaining_space`] using the WASM
426
+ * class's independently-tracked cursor — accurate after `at`, `text`,
427
+ * `space`, `newPageSameSize`, `textInRect` and the table helpers.
428
+ */
429
+ remainingSpace(): number;
430
+ /**
431
+ * Add an unsigned signature placeholder field at the given bounds.
432
+ */
433
+ signatureField(name: string, x: number, y: number, w: number, h: number): void;
258
434
  space(points: number): void;
259
435
  squiggly(r: number, g: number, b: number): void;
260
436
  stamp(name: string): void;
261
437
  stickyNote(text: string): void;
262
438
  stickyNoteAt(x: number, y: number, text: string): void;
439
+ /**
440
+ * Open a streaming table. Returns a `StreamingTable` handle the caller
441
+ * pushes rows into; call `finish()` when done. The streamed rows are
442
+ * buffered per-table and replayed against the real Rust
443
+ * `StreamingTable` at `done()` commit time — avoiding the
444
+ * FluentPageBuilder-lifetime problem that otherwise can't cross the
445
+ * wasm-bindgen boundary.
446
+ */
447
+ streamingTable(spec: any): StreamingTable;
263
448
  strikeout(r: number, g: number, b: number): void;
449
+ /**
450
+ * Draw a straight line with explicit stroke width and RGB colour.
451
+ */
452
+ strokeLine(x1: number, y1: number, x2: number, y2: number, width: number, r: number, g: number, b: number): void;
453
+ /**
454
+ * Draw a stroked rectangle with explicit stroke width and RGB colour.
455
+ */
456
+ strokeRect(x: number, y: number, w: number, h: number, width: number, r: number, g: number, b: number): void;
457
+ /**
458
+ * Render a buffered table from a JS object:
459
+ *
460
+ * ```javascript
461
+ * page.table({
462
+ * columns: [
463
+ * { header: "SKU", width: 100, align: Align.Left },
464
+ * { header: "Qty", width: 60, align: Align.Right },
465
+ * ],
466
+ * rows: [["A-1","12"], ["B-2","3"]],
467
+ * hasHeader: true,
468
+ * });
469
+ * ```
470
+ *
471
+ * Uses `serde-wasm-bindgen` for deserialisation. Replays against the
472
+ * Rust `Table` builder at `done()` commit time.
473
+ */
474
+ table(spec: any): void;
264
475
  text(text: string): void;
265
476
  textField(name: string, x: number, y: number, w: number, h: number, default_value?: string | null): void;
477
+ /**
478
+ * Place wrapped text inside a rectangle with horizontal alignment.
479
+ * `align` is the `Align` enum (0 = Left, 1 = Center, 2 = Right) — also
480
+ * accepts a raw integer for JS callers that pre-date the enum import.
481
+ */
482
+ textInRect(x: number, y: number, w: number, h: number, text: string, align: number): void;
266
483
  underline(r: number, g: number, b: number): void;
267
484
  watermark(text: string): void;
268
485
  watermarkConfidential(): void;
@@ -682,6 +899,15 @@ export class WasmPdfDocument {
682
899
  * Flatten annotations on a page into the page content.
683
900
  */
684
901
  flattenPageAnnotations(page_index: number): void;
902
+ /**
903
+ * Return warnings collected during the last form-flattening save.
904
+ *
905
+ * Each entry names a widget field that had no `/AP` appearance stream;
906
+ * flattening such a field produces a blank rectangle.
907
+ *
908
+ * @returns Array of warning strings
909
+ */
910
+ flattenWarnings(): string[];
685
911
  /**
686
912
  * Get annotations from a page.
687
913
  *
@@ -838,6 +1064,16 @@ export class WasmPdfDocument {
838
1064
  * @returns Uint8Array containing the modified PDF
839
1065
  */
840
1066
  saveToBytes(): Uint8Array;
1067
+ /**
1068
+ * Save with options (compress, garbage_collect, linearize) and return bytes.
1069
+ *
1070
+ * @param {Object} [options] - Optional save options.
1071
+ * @param {boolean} [options.compress=true] - Compress raw streams with FlateDecode.
1072
+ * @param {boolean} [options.garbageCollect=true] - Remove unreachable objects.
1073
+ * @param {boolean} [options.linearize=false] - Linearize (reserved, no-op).
1074
+ * @returns Uint8Array containing the modified PDF
1075
+ */
1076
+ saveWithOptions(compress?: boolean | null, garbage_collect?: boolean | null, linearize?: boolean | null): Uint8Array;
841
1077
  /**
842
1078
  * Search for text across all pages.
843
1079
  *
@@ -1153,3 +1389,11 @@ export function disableLogging(): void;
1153
1389
  * ```
1154
1390
  */
1155
1391
  export function setLogLevel(level: string): void;
1392
+
1393
+ /**
1394
+ * Sign raw PDF bytes and return the signed PDF as a `Uint8Array`.
1395
+ *
1396
+ * `cert` must carry a private key (loaded via `Certificate.loadPem` or
1397
+ * `Certificate.loadPkcs12`).
1398
+ */
1399
+ export function signPdfBytes(pdf_data: Uint8Array, cert: WasmCertificate, reason?: string | null, location?: string | null): Uint8Array;
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./pdf_oxide_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
 
7
7
  export {
8
- ArtifactStyle, WasmArtifact, WasmCertificate, WasmDocumentBuilder, WasmEmbeddedFont, WasmFluentPageBuilder, WasmFooter, WasmHeader, WasmOcrConfig, WasmOcrEngine, WasmPageTemplate, WasmPdf, WasmPdfDocument, WasmPdfPageRegion, WasmSignature, WasmTimestamp, disableLogging, setLogLevel
8
+ Align, ArtifactStyle, StreamingTable, WasmArtifact, WasmCertificate, WasmDocumentBuilder, WasmEmbeddedFont, WasmFluentPageBuilder, WasmFooter, WasmHeader, WasmOcrConfig, WasmOcrEngine, WasmPageTemplate, WasmPdf, WasmPdfDocument, WasmPdfPageRegion, WasmSignature, WasmTimestamp, disableLogging, setLogLevel, signPdfBytes
9
9
  } from "./pdf_oxide_bg.js";