pdf-oxide-wasm 0.3.37 → 0.3.38

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/README.md CHANGED
@@ -167,7 +167,7 @@ const pngBytes = doc.extractImageBytes(0);
167
167
 
168
168
  ```javascript
169
169
  doc.setTitle("Quarterly Report");
170
- doc.setAuthor("Finance Team");
170
+ doc.setAuthor("Example Author");
171
171
  doc.setPageRotation(0, 90);
172
172
  doc.cropMargins(36, 36, 36, 36);
173
173
  doc.eraseRegion(0, 50, 50, 200, 100);
@@ -0,0 +1 @@
1
+ {"type":"module","sideEffects":false}
@@ -25,28 +25,6 @@ export class ArtifactStyle {
25
25
  constructor();
26
26
  }
27
27
 
28
- /**
29
- * Chroma subsampling format
30
- */
31
- export enum ChromaSampling {
32
- /**
33
- * Both vertically and horizontally subsampled.
34
- */
35
- Cs420 = 0,
36
- /**
37
- * Horizontally subsampled.
38
- */
39
- Cs422 = 1,
40
- /**
41
- * Not subsampled.
42
- */
43
- Cs444 = 2,
44
- /**
45
- * Monochrome.
46
- */
47
- Cs400 = 3,
48
- }
49
-
50
28
  /**
51
29
  * A header or footer artifact definition.
52
30
  */
@@ -79,6 +57,218 @@ export class WasmArtifact {
79
57
  withStyle(style: ArtifactStyle): WasmArtifact;
80
58
  }
81
59
 
60
+ /**
61
+ * X.509 certificate parsed from a raw DER blob. Mirrors the C#,
62
+ * Node, Python, and Go `Certificate` surfaces — `subject` / `issuer`
63
+ * / `serial` / `validity` / `isValid` getters only.
64
+ */
65
+ export class WasmCertificate {
66
+ private constructor();
67
+ free(): void;
68
+ [Symbol.dispose](): void;
69
+ /**
70
+ * Load a certificate from a DER-encoded X.509 blob. Throws if
71
+ * the DER doesn't parse.
72
+ */
73
+ static load(data: Uint8Array): WasmCertificate;
74
+ /**
75
+ * Whether the certificate is currently within its validity
76
+ * window. Does NOT verify chain, trust-root, or revocation.
77
+ */
78
+ readonly isValid: boolean;
79
+ /**
80
+ * Issuer distinguished name.
81
+ */
82
+ readonly issuer: string;
83
+ /**
84
+ * Serial number as a hex string (no `0x` prefix).
85
+ */
86
+ readonly serial: string;
87
+ /**
88
+ * Subject distinguished name.
89
+ */
90
+ readonly subject: string;
91
+ /**
92
+ * Validity window as `[notBefore, notAfter]` Unix epoch seconds.
93
+ * JavaScript: `new Date(notBefore * 1000)` for a Date.
94
+ */
95
+ readonly validity: BigInt64Array;
96
+ }
97
+
98
+ /**
99
+ * WASM wrapper for [`crate::writer::DocumentBuilder`]. Fluent API for
100
+ * programmatic multi-page PDF construction with embedded fonts and
101
+ * annotations.
102
+ *
103
+ * The terminal methods (`build`, `toBytesEncrypted`) **consume** the
104
+ * builder; subsequent calls throw `Error: DocumentBuilder already
105
+ * consumed`.
106
+ */
107
+ export class WasmDocumentBuilder {
108
+ free(): void;
109
+ [Symbol.dispose](): void;
110
+ /**
111
+ * Start a new A4 page. Returns a `FluentPageBuilder` that must be
112
+ * committed with `.done()` before calling another page method or a
113
+ * terminal (`build`, etc.).
114
+ */
115
+ a4Page(): WasmFluentPageBuilder;
116
+ /**
117
+ * Set document author.
118
+ */
119
+ author(author: string): void;
120
+ /**
121
+ * Build the PDF and return it as a `Uint8Array`. **Consumes** the
122
+ * builder.
123
+ */
124
+ build(): Uint8Array;
125
+ /**
126
+ * Commit a completed `FluentPageBuilder` back to this builder.
127
+ * Takes the place of the Rust `page.done()` re-parenting.
128
+ *
129
+ * JS users typically don't call this directly — the ergonomic
130
+ * pattern is `builder.a4Page();` for each page, then
131
+ * `builder.commitPage(page)` once ops are queued. For more fluent
132
+ * code, see the `FluentPageBuilder.done(builder)` helper which
133
+ * delegates to this method.
134
+ */
135
+ commitPage(page: WasmFluentPageBuilder): void;
136
+ /**
137
+ * Set the creator application name recorded in the PDF.
138
+ */
139
+ creator(creator: string): void;
140
+ /**
141
+ * Set document keywords (comma-separated per PDF convention).
142
+ */
143
+ keywords(keywords: string): void;
144
+ /**
145
+ * Start a new US Letter page.
146
+ */
147
+ letterPage(): WasmFluentPageBuilder;
148
+ /**
149
+ * Create a new empty document builder. Equivalent to the Rust
150
+ * [`crate::writer::DocumentBuilder::new`] — every other method
151
+ * chains off the instance returned here.
152
+ */
153
+ constructor();
154
+ /**
155
+ * Start a new page with custom dimensions in PDF points
156
+ * (72 pt = 1 inch).
157
+ */
158
+ page(width: number, height: number): WasmFluentPageBuilder;
159
+ /**
160
+ * Register a TTF / OTF font the pages can reference by name.
161
+ * **Consumes** `font` — reusing the `WasmEmbeddedFont` throws.
162
+ */
163
+ registerEmbeddedFont(name: string, font: WasmEmbeddedFont): void;
164
+ /**
165
+ * Set document subject.
166
+ */
167
+ subject(subject: string): void;
168
+ /**
169
+ * Set document title.
170
+ */
171
+ title(title: string): void;
172
+ /**
173
+ * Build the PDF with AES-256 encryption and return it as a
174
+ * `Uint8Array`. Granted permissions default to all. **Consumes**
175
+ * the builder.
176
+ */
177
+ toBytesEncrypted(user_password: string, owner_password: string): Uint8Array;
178
+ }
179
+
180
+ /**
181
+ * Embedded TTF/OTF font usable by `WasmDocumentBuilder`. Single-use: once
182
+ * passed to `registerEmbeddedFont`, the underlying Rust `EmbeddedFont` is
183
+ * moved into the builder and this handle becomes empty.
184
+ */
185
+ export class WasmEmbeddedFont {
186
+ private constructor();
187
+ free(): void;
188
+ [Symbol.dispose](): void;
189
+ /**
190
+ * Load an embedded font from raw TTF/OTF bytes. Pass `name` to
191
+ * override the PostScript name baked into the font file.
192
+ */
193
+ static fromBytes(data: Uint8Array, name?: string | null): WasmEmbeddedFont;
194
+ /**
195
+ * The font's PostScript name (or the override). Empty once consumed.
196
+ */
197
+ readonly name: string;
198
+ }
199
+
200
+ /**
201
+ * Per-page fluent builder. Buffers operations until `done(builder)` is
202
+ * called, which commits them to the parent `WasmDocumentBuilder`. Each
203
+ * instance is single-use — `done()` twice throws.
204
+ */
205
+ export class WasmFluentPageBuilder {
206
+ private constructor();
207
+ free(): void;
208
+ [Symbol.dispose](): void;
209
+ at(x: number, y: number): void;
210
+ checkbox(name: string, x: number, y: number, w: number, h: number, checked: boolean): void;
211
+ /**
212
+ * Add a dropdown combo-box.
213
+ */
214
+ comboBox(name: string, x: number, y: number, w: number, h: number, options: string[], selected?: string | null): void;
215
+ /**
216
+ * Convenience: commit this page's buffered ops to `builder`. Same
217
+ * as `builder.commitPage(this)` but lets JS users keep the
218
+ * chain-like flow:
219
+ *
220
+ * ```javascript
221
+ * const page = builder.a4Page();
222
+ * page.at(72, 720); page.text("Hi");
223
+ * page.done(builder);
224
+ * ```
225
+ */
226
+ done(builder: WasmDocumentBuilder): void;
227
+ /**
228
+ * Draw a filled rectangle. RGB channels in 0.0-1.0.
229
+ */
230
+ filledRect(x: number, y: number, w: number, h: number, r: number, g: number, b: number): void;
231
+ font(name: string, size: number): void;
232
+ freeText(x: number, y: number, w: number, h: number, text: string): void;
233
+ heading(level: number, text: string): void;
234
+ highlight(r: number, g: number, b: number): void;
235
+ horizontalRule(): void;
236
+ /**
237
+ * Draw a line from (x1, y1) to (x2, y2) with 1pt black stroke.
238
+ */
239
+ line(x1: number, y1: number, x2: number, y2: number): void;
240
+ linkNamed(destination: string): void;
241
+ linkPage(page: number): void;
242
+ linkUrl(url: string): void;
243
+ paragraph(text: string): void;
244
+ /**
245
+ * Add a clickable push button with a visible caption.
246
+ */
247
+ pushButton(name: string, x: number, y: number, w: number, h: number, caption: string): void;
248
+ /**
249
+ * Add a radio-button group. `values`, `xs`, `ys`, `ws`, `hs` are
250
+ * parallel arrays of length N describing each option's export
251
+ * value and rectangle. `selected` picks the initial value.
252
+ */
253
+ radioGroup(name: string, values: string[], xs: Float32Array, ys: Float32Array, ws: Float32Array, hs: Float32Array, selected?: string | null): void;
254
+ /**
255
+ * Draw a stroked rectangle outline (1pt black).
256
+ */
257
+ rect(x: number, y: number, w: number, h: number): void;
258
+ space(points: number): void;
259
+ squiggly(r: number, g: number, b: number): void;
260
+ stamp(name: string): void;
261
+ stickyNote(text: string): void;
262
+ stickyNoteAt(x: number, y: number, text: string): void;
263
+ strikeout(r: number, g: number, b: number): void;
264
+ text(text: string): void;
265
+ textField(name: string, x: number, y: number, w: number, h: number, default_value?: string | null): void;
266
+ underline(r: number, g: number, b: number): void;
267
+ watermark(text: string): void;
268
+ watermarkConfidential(): void;
269
+ watermarkDraft(): void;
270
+ }
271
+
82
272
  /**
83
273
  * A footer definition.
84
274
  */
@@ -203,6 +393,21 @@ export class WasmPdf {
203
393
  * @param author - Optional document author
204
394
  */
205
395
  static fromHtml(content: string, title?: string | null, author?: string | null): WasmPdf;
396
+ /**
397
+ * Render `html` with `css` applied, embedding `font_bytes` for the
398
+ * body text. The font must cover every codepoint used by `html` or
399
+ * unknown glyphs fall back to `.notdef`. See
400
+ * [`Self::from_html_css_with_fonts`] for a multi-font cascade.
401
+ */
402
+ static fromHtmlCss(html: string, css: string, font_bytes: Uint8Array): WasmPdf;
403
+ /**
404
+ * Render `html` + `css` with a multi-font cascade. `families` and
405
+ * `fonts` are parallel arrays: `families[i]` names the CSS
406
+ * `font-family` that resolves to `fonts[i]` bytes. The first entry
407
+ * is the default used whenever a CSS `font-family` doesn't match a
408
+ * registered family.
409
+ */
410
+ static fromHtmlCssWithFonts(html: string, css: string, families: string[], fonts: Uint8Array[]): WasmPdf;
206
411
  /**
207
412
  * Create a PDF from image bytes (PNG, JPEG, etc.).
208
413
  *
@@ -530,6 +735,13 @@ export class WasmPdfDocument {
530
735
  * @returns Number of pages merged
531
736
  */
532
737
  mergeFrom(data: Uint8Array): number;
738
+ /**
739
+ * Move a page within the document. Zero-based; `from_index` and
740
+ * `to_index` refer to positions **before** the move, matching the
741
+ * Python (`PyPdfDocument.move_page`) / Go (`DocumentEditor.MovePage`) /
742
+ * C# contracts.
743
+ */
744
+ movePage(from_index: number, to_index: number): void;
533
745
  /**
534
746
  * Load a PDF document from raw bytes.
535
747
  *
@@ -681,6 +893,17 @@ export class WasmPdfDocument {
681
893
  * Set the document title.
682
894
  */
683
895
  setTitle(title: string): void;
896
+ /**
897
+ * Count existing PDF signatures. Returns 0 when the document has
898
+ * no AcroForm or no signed signature fields.
899
+ */
900
+ signatureCount(): number;
901
+ /**
902
+ * Enumerate existing PDF signatures. Each entry is a
903
+ * `WasmSignature` (inspection-only) mirroring the C# and Python
904
+ * Signature surfaces.
905
+ */
906
+ signatures(): WasmSignature[];
684
907
  /**
685
908
  * Convert a single page to HTML.
686
909
  *
@@ -793,6 +1016,119 @@ export class WasmPdfPageRegion {
793
1016
  extractWords(): any;
794
1017
  }
795
1018
 
1019
+ /**
1020
+ * 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.
1025
+ */
1026
+ export class WasmSignature {
1027
+ private constructor();
1028
+ free(): void;
1029
+ [Symbol.dispose](): void;
1030
+ /**
1031
+ * Run the RFC 5652 §5.4 signer-attributes crypto check. Today
1032
+ * this covers RSA-PKCS#1 v1.5 over SHA-1/256/384/512 — the
1033
+ * padding used by essentially every PDF signature.
1034
+ *
1035
+ * A `true` return proves the signer held the private key matching
1036
+ * the embedded certificate and that the signed-attribute bundle
1037
+ * is authentic. It does **not** verify the `messageDigest`
1038
+ * attribute against the document's byte-range content hash —
1039
+ * call `verifyDetached()` for that end-to-end check.
1040
+ *
1041
+ * Throws for RSA-PSS, ECDSA, unknown digest OIDs, or signatures
1042
+ * without signed_attrs.
1043
+ */
1044
+ verify(): boolean;
1045
+ /**
1046
+ * End-to-end detached-signature verification. Runs both the
1047
+ * signer-attributes RSA-PKCS#1 v1.5 crypto check AND the RFC 5652
1048
+ * §11.2 `messageDigest` check against the segment of `pdfData`
1049
+ * this signature covers (extracted via `/ByteRange`).
1050
+ *
1051
+ * `pdfData` must be the full PDF file. A `true` result proves
1052
+ * both the signer is authentic and that the document's byte-range
1053
+ * content has not been altered since signing. `false` means one
1054
+ * of the two checks failed (wrong key or tampered content).
1055
+ *
1056
+ * Throws for RSA-PSS, ECDSA, unknown digest OIDs, or CMS blobs
1057
+ * missing `signed_attrs` / `messageDigest`.
1058
+ */
1059
+ verifyDetached(pdf_data: Uint8Array): boolean;
1060
+ /**
1061
+ * `/ContactInfo` entry from the signature dictionary, if present.
1062
+ */
1063
+ readonly contactInfo: string | undefined;
1064
+ /**
1065
+ * True iff `/ByteRange` is a 4-element array covering the whole
1066
+ * document (i.e. the signature protects every byte of the file).
1067
+ */
1068
+ readonly coversWholeDocument: boolean;
1069
+ /**
1070
+ * `/Location` entry from the signature dictionary, if present.
1071
+ */
1072
+ readonly location: string | undefined;
1073
+ /**
1074
+ * `/Reason` entry from the signature dictionary, if present.
1075
+ */
1076
+ readonly reason: string | undefined;
1077
+ /**
1078
+ * `/Name` entry from the signature dictionary, if present.
1079
+ */
1080
+ readonly signerName: string | undefined;
1081
+ /**
1082
+ * Unix epoch (seconds). `None` if the `/M` entry is missing or
1083
+ * unparseable.
1084
+ */
1085
+ readonly signingTime: bigint | undefined;
1086
+ }
1087
+
1088
+ /**
1089
+ * RFC 3161 timestamp parsed from a DER TimeStampToken or bare
1090
+ * TSTInfo. Mirrors the C#, Go, and Python `Timestamp` surfaces.
1091
+ */
1092
+ export class WasmTimestamp {
1093
+ private constructor();
1094
+ free(): void;
1095
+ [Symbol.dispose](): void;
1096
+ /**
1097
+ * Parse a DER blob that may be either a full TimeStampToken or
1098
+ * the bare TSTInfo SEQUENCE.
1099
+ */
1100
+ static parse(data: Uint8Array): WasmTimestamp;
1101
+ /**
1102
+ * Cryptographic verify — not yet implemented.
1103
+ */
1104
+ verify(): boolean;
1105
+ /**
1106
+ * Hash algorithm enum value (1=SHA1, 2=SHA256, 3=SHA384,
1107
+ * 4=SHA512, 0=unknown).
1108
+ */
1109
+ readonly hashAlgorithm: number;
1110
+ /**
1111
+ * Raw message-imprint hash bytes.
1112
+ */
1113
+ readonly messageImprint: Uint8Array;
1114
+ /**
1115
+ * TSA policy OID in dotted-decimal form.
1116
+ */
1117
+ readonly policyOid: string;
1118
+ /**
1119
+ * Serial number as a hex string (no `0x` prefix).
1120
+ */
1121
+ readonly serial: string;
1122
+ /**
1123
+ * Generation time as Unix epoch seconds.
1124
+ */
1125
+ readonly time: bigint;
1126
+ /**
1127
+ * TSA name from the token (may be empty).
1128
+ */
1129
+ readonly tsaName: string;
1130
+ }
1131
+
796
1132
  /**
797
1133
  * Disable all pdf_oxide log output — convenience wrapper for
798
1134
  * `setLogLevel("off")`.
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./pdf_oxide.d.ts" */
2
+ import * as wasm from "./pdf_oxide_bg.wasm";
3
+ import { __wbg_set_wasm } from "./pdf_oxide_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+
7
+ export {
8
+ ArtifactStyle, WasmArtifact, WasmCertificate, WasmDocumentBuilder, WasmEmbeddedFont, WasmFluentPageBuilder, WasmFooter, WasmHeader, WasmOcrConfig, WasmOcrEngine, WasmPageTemplate, WasmPdf, WasmPdfDocument, WasmPdfPageRegion, WasmSignature, WasmTimestamp, disableLogging, setLogLevel
9
+ } from "./pdf_oxide_bg.js";