pdf-oxide-wasm 0.3.38 → 0.3.40

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,59 @@ 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 fully-completed batches waiting for finish().
65
+ */
66
+ batchCount(): number;
67
+ /**
68
+ * Number of columns configured on this streaming table.
69
+ */
70
+ columnCount(): number;
71
+ /**
72
+ * Seal the streaming table — the buffered rows are flushed onto the
73
+ * parent page's op queue, to be replayed against the real Rust
74
+ * `StreamingTable` at `done()` commit time. Calling `finish()` twice
75
+ * throws.
76
+ */
77
+ finish(): void;
78
+ /**
79
+ * Explicitly flush the current batch to `completed_batches`.
80
+ * Called automatically when `batch_size` rows accumulate.
81
+ */
82
+ flush(): void;
83
+ /**
84
+ * Number of rows in the current (not-yet-flushed) batch.
85
+ */
86
+ pendingRowCount(): number;
87
+ /**
88
+ * Push one row as an array of cell strings (all rowspan=1). Returns an
89
+ * error if the table has already been finished or if the row's cell count
90
+ * does not match the column count. Auto-flushes the batch when full.
91
+ */
92
+ pushRow(cells: string[]): void;
93
+ /**
94
+ * Push one row with per-cell rowspan values. `cells` is a JS array of
95
+ * `[text, rowspan]` two-element arrays. `rowspan == 1` is a normal cell.
96
+ * Auto-flushes the batch when full.
97
+ */
98
+ pushRowSpan(cells: any): void;
99
+ }
100
+
28
101
  /**
29
102
  * A header or footer artifact definition.
30
103
  */
@@ -71,6 +144,17 @@ export class WasmCertificate {
71
144
  * the DER doesn't parse.
72
145
  */
73
146
  static load(data: Uint8Array): WasmCertificate;
147
+ /**
148
+ * Load a signer certificate + private key from PEM strings.
149
+ * `certPem` must begin `-----BEGIN CERTIFICATE-----`.
150
+ * `keyPem` must begin `-----BEGIN PRIVATE KEY-----` or `-----BEGIN RSA PRIVATE KEY-----`.
151
+ */
152
+ static loadPem(cert_pem: string, key_pem: string): WasmCertificate;
153
+ /**
154
+ * Load a signer certificate + private key from a PKCS#12 (.p12/.pfx) blob.
155
+ * `password` is the passphrase protecting the key bag.
156
+ */
157
+ static loadPkcs12(data: Uint8Array, password: string): WasmCertificate;
74
158
  /**
75
159
  * Whether the certificate is currently within its validity
76
160
  * window. Does NOT verify chain, trust-root, or revocation.
@@ -141,6 +225,12 @@ export class WasmDocumentBuilder {
141
225
  * Set document keywords (comma-separated per PDF convention).
142
226
  */
143
227
  keywords(keywords: string): void;
228
+ /**
229
+ * Set the document's natural language tag (e.g. `"en-US"`).
230
+ *
231
+ * Emitted as `/Lang` in the catalog when `taggedPdfUa1()` is set.
232
+ */
233
+ language(lang: string): void;
144
234
  /**
145
235
  * Start a new US Letter page.
146
236
  */
@@ -151,6 +241,10 @@ export class WasmDocumentBuilder {
151
241
  * chains off the instance returned here.
152
242
  */
153
243
  constructor();
244
+ /**
245
+ * Run a JavaScript script when the document is opened (`/OpenAction`).
246
+ */
247
+ onOpen(script: string): void;
154
248
  /**
155
249
  * Start a new page with custom dimensions in PDF points
156
250
  * (72 pt = 1 inch).
@@ -161,10 +255,24 @@ export class WasmDocumentBuilder {
161
255
  * **Consumes** `font` — reusing the `WasmEmbeddedFont` throws.
162
256
  */
163
257
  registerEmbeddedFont(name: string, font: WasmEmbeddedFont): void;
258
+ /**
259
+ * Add a role-map entry: custom structure type → standard PDF structure type.
260
+ *
261
+ * Emitted in `/RoleMap` inside the StructTreeRoot when `taggedPdfUa1()`
262
+ * is set. Multiple calls accumulate entries.
263
+ */
264
+ roleMap(custom: string, standard: string): void;
164
265
  /**
165
266
  * Set document subject.
166
267
  */
167
268
  subject(subject: string): void;
269
+ /**
270
+ * Enable PDF/UA-1 tagged PDF mode.
271
+ *
272
+ * When enabled, `build()` emits `/MarkInfo`, `/StructTreeRoot`, `/Lang`,
273
+ * and `/ViewerPreferences` in the catalog. Opt-in — no effect unless called.
274
+ */
275
+ taggedPdfUa1(): void;
168
276
  /**
169
277
  * Set document title.
170
278
  */
@@ -207,7 +315,22 @@ export class WasmFluentPageBuilder {
207
315
  free(): void;
208
316
  [Symbol.dispose](): void;
209
317
  at(x: number, y: number): void;
318
+ /**
319
+ * Place a 1-D barcode image at `(x, y, w, h)` on the page.
320
+ * `barcodeType`: 0=Code128 1=Code39 2=EAN13 3=EAN8 4=UPCA 5=ITF
321
+ * 6=Code93 7=Codabar.
322
+ */
323
+ barcode1d(barcode_type: number, data: string, x: number, y: number, w: number, h: number): void;
324
+ /**
325
+ * Place a QR-code image at `(x, y, size, size)` on the page.
326
+ */
327
+ barcodeQr(data: string, x: number, y: number, size: number): void;
210
328
  checkbox(name: string, x: number, y: number, w: number, h: number, checked: boolean): void;
329
+ /**
330
+ * Lay out `text` as balanced multi-column flow (`columnCount` columns,
331
+ * `gapPt` points between columns). Paragraphs in `text` are separated by `"\n\n"`.
332
+ */
333
+ columns(column_count: number, gap_pt: number, text: string): void;
211
334
  /**
212
335
  * Add a dropdown combo-box.
213
336
  */
@@ -224,22 +347,77 @@ export class WasmFluentPageBuilder {
224
347
  * ```
225
348
  */
226
349
  done(builder: WasmDocumentBuilder): void;
350
+ fieldCalculate(script: string): void;
351
+ fieldFormat(script: string): void;
352
+ fieldKeystroke(script: string): void;
353
+ fieldValidate(script: string): void;
227
354
  /**
228
355
  * Draw a filled rectangle. RGB channels in 0.0-1.0.
229
356
  */
230
357
  filledRect(x: number, y: number, w: number, h: number, r: number, g: number, b: number): void;
231
358
  font(name: string, size: number): void;
359
+ /**
360
+ * Add a footnote: inline `refMark` at the cursor and `noteText` body
361
+ * near the page bottom with a separator artifact line.
362
+ */
363
+ footnote(ref_mark: string, note_text: string): void;
232
364
  freeText(x: number, y: number, w: number, h: number, text: string): void;
233
365
  heading(level: number, text: string): void;
234
366
  highlight(r: number, g: number, b: number): void;
235
367
  horizontalRule(): void;
368
+ /**
369
+ * Embed a decorative image (JPEG/PNG/WebP bytes) as an /Artifact (no alt text).
370
+ */
371
+ imageArtifact(bytes: Uint8Array, x: number, y: number, w: number, h: number): void;
372
+ /**
373
+ * Embed an image (JPEG/PNG/WebP bytes) with an accessibility alt text.
374
+ */
375
+ imageWithAlt(bytes: Uint8Array, x: number, y: number, w: number, h: number, alt_text: string): void;
376
+ /**
377
+ * Emit `text` inline (advances cursorX only, not cursorY).
378
+ */
379
+ inline(text: string): void;
380
+ /**
381
+ * Inline bold run.
382
+ */
383
+ inlineBold(text: string): void;
384
+ /**
385
+ * Inline colored run (RGB 0.0–1.0).
386
+ */
387
+ inlineColor(r: number, g: number, b: number, text: string): void;
388
+ /**
389
+ * Inline italic run.
390
+ */
391
+ inlineItalic(text: string): void;
236
392
  /**
237
393
  * Draw a line from (x1, y1) to (x2, y2) with 1pt black stroke.
238
394
  */
239
395
  line(x1: number, y1: number, x2: number, y2: number): void;
396
+ linkJavascript(script: string): void;
240
397
  linkNamed(destination: string): void;
241
398
  linkPage(page: number): void;
242
399
  linkUrl(url: string): void;
400
+ /**
401
+ * Measure the rendered width of `text` in the builder's current font
402
+ * and size, in PDF points. Pure query — does not mutate state.
403
+ *
404
+ * Thin JS view over [`crate::writer::FluentPageBuilder::measure`]. The
405
+ * WASM class tracks the current font/size independently of the
406
+ * buffered ops so this query is served without a live builder.
407
+ */
408
+ measure(text: string): number;
409
+ /**
410
+ * Finish the current page and start a new one with the same page
411
+ * size. Cursor resets to the top-left margin (72, height-72). The
412
+ * builder's font carries over.
413
+ */
414
+ newPageSameSize(): void;
415
+ /**
416
+ * Advance cursorY by one line-height and reset cursorX to 72 pt.
417
+ */
418
+ newline(): void;
419
+ onClose(script: string): void;
420
+ onOpen(script: string): void;
243
421
  paragraph(text: string): void;
244
422
  /**
245
423
  * Add a clickable push button with a visible caption.
@@ -255,14 +433,75 @@ export class WasmFluentPageBuilder {
255
433
  * Draw a stroked rectangle outline (1pt black).
256
434
  */
257
435
  rect(x: number, y: number, w: number, h: number): void;
436
+ /**
437
+ * Points remaining on the current page below the cursor (down to the
438
+ * 72 pt bottom margin). Mirrors
439
+ * [`crate::writer::FluentPageBuilder::remaining_space`] using the WASM
440
+ * class's independently-tracked cursor — accurate after `at`, `text`,
441
+ * `space`, `newPageSameSize`, `textInRect` and the table helpers.
442
+ */
443
+ remainingSpace(): number;
444
+ /**
445
+ * Add an unsigned signature placeholder field at the given bounds.
446
+ */
447
+ signatureField(name: string, x: number, y: number, w: number, h: number): void;
258
448
  space(points: number): void;
259
449
  squiggly(r: number, g: number, b: number): void;
260
450
  stamp(name: string): void;
261
451
  stickyNote(text: string): void;
262
452
  stickyNoteAt(x: number, y: number, text: string): void;
453
+ /**
454
+ * Open a streaming table. Returns a `StreamingTable` handle the caller
455
+ * pushes rows into; call `finish()` when done. The streamed rows are
456
+ * buffered per-table and replayed against the real Rust
457
+ * `StreamingTable` at `done()` commit time — avoiding the
458
+ * FluentPageBuilder-lifetime problem that otherwise can't cross the
459
+ * wasm-bindgen boundary.
460
+ */
461
+ streamingTable(spec: any): StreamingTable;
263
462
  strikeout(r: number, g: number, b: number): void;
463
+ /**
464
+ * Draw a straight line with explicit stroke width and RGB colour.
465
+ */
466
+ strokeLine(x1: number, y1: number, x2: number, y2: number, width: number, r: number, g: number, b: number): void;
467
+ /**
468
+ * Draw a dashed line. `dash` is alternating on/off lengths in points; `phase` is the starting offset.
469
+ */
470
+ strokeLineDashed(x1: number, y1: number, x2: number, y2: number, width: number, r: number, g: number, b: number, dash: Float32Array, phase: number): void;
471
+ /**
472
+ * Draw a stroked rectangle with explicit stroke width and RGB colour.
473
+ */
474
+ strokeRect(x: number, y: number, w: number, h: number, width: number, r: number, g: number, b: number): void;
475
+ /**
476
+ * Draw a dashed rectangle border. `dash` is alternating on/off lengths in points; `phase` is the starting offset.
477
+ */
478
+ strokeRectDashed(x: number, y: number, w: number, h: number, width: number, r: number, g: number, b: number, dash: Float32Array, phase: number): void;
479
+ /**
480
+ * Render a buffered table from a JS object:
481
+ *
482
+ * ```javascript
483
+ * page.table({
484
+ * columns: [
485
+ * { header: "SKU", width: 100, align: Align.Left },
486
+ * { header: "Qty", width: 60, align: Align.Right },
487
+ * ],
488
+ * rows: [["A-1","12"], ["B-2","3"]],
489
+ * hasHeader: true,
490
+ * });
491
+ * ```
492
+ *
493
+ * Uses `serde-wasm-bindgen` for deserialisation. Replays against the
494
+ * Rust `Table` builder at `done()` commit time.
495
+ */
496
+ table(spec: any): void;
264
497
  text(text: string): void;
265
498
  textField(name: string, x: number, y: number, w: number, h: number, default_value?: string | null): void;
499
+ /**
500
+ * Place wrapped text inside a rectangle with horizontal alignment.
501
+ * `align` is the `Align` enum (0 = Left, 1 = Center, 2 = Right) — also
502
+ * accepts a raw integer for JS callers that pre-date the enum import.
503
+ */
504
+ textInRect(x: number, y: number, w: number, h: number, text: string, align: number): void;
266
505
  underline(r: number, g: number, b: number): void;
267
506
  watermark(text: string): void;
268
507
  watermarkConfidential(): void;
@@ -682,6 +921,21 @@ export class WasmPdfDocument {
682
921
  * Flatten annotations on a page into the page content.
683
922
  */
684
923
  flattenPageAnnotations(page_index: number): void;
924
+ /**
925
+ * Create a flattened PDF where each page is rendered as an image.
926
+ * Burns in all annotations, form fields, and overlays.
927
+ * Returns the flattened PDF as bytes.
928
+ */
929
+ flattenToImages(dpi?: number | null): Uint8Array;
930
+ /**
931
+ * Return warnings collected during the last form-flattening save.
932
+ *
933
+ * Each entry names a widget field that had no `/AP` appearance stream;
934
+ * flattening such a field produces a blank rectangle.
935
+ *
936
+ * @returns Array of warning strings
937
+ */
938
+ flattenWarnings(): string[];
685
939
  /**
686
940
  * Get annotations from a page.
687
941
  *
@@ -805,6 +1059,16 @@ export class WasmPdfDocument {
805
1059
  * @param threshold - Fraction of pages (0.0-1.0) where text must repeat (heuristic mode)
806
1060
  */
807
1061
  removeHeaders(threshold: number): number;
1062
+ /**
1063
+ * Render a page to an image (PNG).
1064
+ *
1065
+ * Requires the `rendering` feature.
1066
+ *
1067
+ * @param page_index - Zero-based page number
1068
+ * @param dpi - Dots per inch (default: 150)
1069
+ * @returns Uint8Array containing the PNG image data
1070
+ */
1071
+ renderPage(page_index: number, dpi?: number | null): Uint8Array;
808
1072
  /**
809
1073
  * Reposition an image on a page.
810
1074
  */
@@ -838,6 +1102,16 @@ export class WasmPdfDocument {
838
1102
  * @returns Uint8Array containing the modified PDF
839
1103
  */
840
1104
  saveToBytes(): Uint8Array;
1105
+ /**
1106
+ * Save with options (compress, garbage_collect, linearize) and return bytes.
1107
+ *
1108
+ * @param {Object} [options] - Optional save options.
1109
+ * @param {boolean} [options.compress=true] - Compress raw streams with FlateDecode.
1110
+ * @param {boolean} [options.garbageCollect=true] - Remove unreachable objects.
1111
+ * @param {boolean} [options.linearize=false] - Linearize (reserved, no-op).
1112
+ * @returns Uint8Array containing the modified PDF
1113
+ */
1114
+ saveWithOptions(compress?: boolean | null, garbage_collect?: boolean | null, linearize?: boolean | null): Uint8Array;
841
1115
  /**
842
1116
  * Search for text across all pages.
843
1117
  *
@@ -1018,10 +1292,9 @@ export class WasmPdfPageRegion {
1018
1292
 
1019
1293
  /**
1020
1294
  * A single existing PDF signature surfaced by
1021
- * `WasmPdfDocument.signatures()`. `verify()` runs the RSA-PKCS#1 v1.5
1022
- * signer-attributes check; `verifyDetached()` adds the
1023
- * `messageDigest` content-hash check. RSA-PSS / ECDSA signers still
1024
- * throw an `UnsupportedFeature`-mapped JS error.
1295
+ * `WasmPdfDocument.signatures()`. `verify()` runs the signer-attributes
1296
+ * check; `verifyDetached()` adds the `messageDigest` content-hash check.
1297
+ * Supported: RSA-PKCS#1 v1.5, RSA-PSS, ECDSA P-256/P-384.
1025
1298
  */
1026
1299
  export class WasmSignature {
1027
1300
  private constructor();
@@ -1099,7 +1372,11 @@ export class WasmTimestamp {
1099
1372
  */
1100
1373
  static parse(data: Uint8Array): WasmTimestamp;
1101
1374
  /**
1102
- * Cryptographic verify not yet implemented.
1375
+ * Cryptographically verify this TimeStampToken.
1376
+ *
1377
+ * Returns `true` when the TSA's signature and `messageDigest` both pass.
1378
+ * Returns `false` when a crypto check fails (tampered token or wrong key).
1379
+ * Throws when the token is not CMS-wrapped or uses an unsupported algorithm.
1103
1380
  */
1104
1381
  verify(): boolean;
1105
1382
  /**
@@ -1153,3 +1430,11 @@ export function disableLogging(): void;
1153
1430
  * ```
1154
1431
  */
1155
1432
  export function setLogLevel(level: string): void;
1433
+
1434
+ /**
1435
+ * Sign raw PDF bytes and return the signed PDF as a `Uint8Array`.
1436
+ *
1437
+ * `cert` must carry a private key (loaded via `Certificate.loadPem` or
1438
+ * `Certificate.loadPkcs12`).
1439
+ */
1440
+ 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";