@pdfluent/sdk-wasm 1.0.0 → 1.2.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/xfa_wasm.d.ts CHANGED
@@ -1,6 +1,85 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /** A stamp with preset text, size, rotation, opacity and colour (red, 60pt, 45°, 25%). */
5
+ export type WatermarkPreset = "draft" | "confidential" | "approved" | "final" | "copy" | "notForDistribution";
6
+
7
+ /** Options for `PdfDoc.addWatermark`. Give `text`, `preset`, or both (then `text` wins). */
8
+ export interface WatermarkOptions {
9
+ text?: string;
10
+ preset?: WatermarkPreset;
11
+ /** Points. Default 48 (60 with a preset). */
12
+ fontSize?: number;
13
+ /** Degrees counter-clockwise. Default 45. */
14
+ rotation?: number;
15
+ /** 0..1. Default 0.3 (0.25 with a preset). */
16
+ opacity?: number;
17
+ /** `"#rrggbb"`. Default mid grey (red with a preset). */
18
+ color?: string;
19
+ /** `"center"` (default), or a corner / exact point in PDF points. */
20
+ position?: "center" | { anchor: "topLeft" | "topRight" | "bottomLeft" | "bottomRight" | "exact"; x: number; y: number };
21
+ /** Default `"foreground"`. */
22
+ layer?: "foreground" | "background";
23
+ /** Repeat across the page. `true` = 200pt spacing. */
24
+ tile?: boolean | { hSpacing?: number; vSpacing?: number };
25
+ /** `"all"` (default), `"even"`, `"odd"`, 0-based page indices, or an inclusive 0-based range. */
26
+ pages?: "all" | "even" | "odd" | number[] | { from: number; to: number };
27
+ }
28
+
29
+
30
+
31
+ /** An image exported faithfully. `page` is 0-based: the first page it is used on. */
32
+ export interface ExtractedImage {
33
+ page: number;
34
+ width: number;
35
+ height: number;
36
+ mime: "image/png" | "image/jpeg";
37
+ data: Uint8Array;
38
+ }
39
+
40
+ /** An image left out because it could not be exported without changing how it looks. */
41
+ export interface SkippedImage {
42
+ page: number;
43
+ width: number;
44
+ height: number;
45
+ reason: "unsupported_filter" | "transparency" | "decode_array" | "cmyk_jpeg" | "color_space" | "bit_depth" | "image_mask" | "undecodable";
46
+ detail: string;
47
+ }
48
+
49
+ export interface ImageExtraction {
50
+ images: ExtractedImage[];
51
+ skipped: SkippedImage[];
52
+ }
53
+
54
+
55
+
56
+ /** Options for `signPdf`. The signature is a cryptographic (PAdES) signature, not a drawn one. */
57
+ export interface SignPdfOptions {
58
+ reason?: string;
59
+ location?: string;
60
+ contactInfo?: string;
61
+ /** Default "Signature1". */
62
+ fieldName?: string;
63
+ /** Show the signature on a page (0-based) at a rectangle in PDF points. Invisible when absent. */
64
+ visibleRect?: { page: number; x: number; y: number; width: number; height: number };
65
+ }
66
+
67
+
68
+
69
+ /** What a user who opens the file with the user password may do. Every flag defaults to `true`. */
70
+ export interface EncryptPermissions {
71
+ print?: boolean;
72
+ printHighQuality?: boolean;
73
+ modify?: boolean;
74
+ copy?: boolean;
75
+ annotate?: boolean;
76
+ fillForms?: boolean;
77
+ accessibility?: boolean;
78
+ assemble?: boolean;
79
+ }
80
+
81
+
82
+
4
83
  /**
5
84
  * Chroma subsampling format
6
85
  */
@@ -77,8 +156,16 @@ export class PdfDoc {
77
156
  /**
78
157
  * Apply a diagonal text watermark to every page.
79
158
  * `opacity` in 0.0..=1.0. Default rotation 45 deg, default colour gray.
159
+ *
160
+ * Kept for compatibility; `addWatermark` takes the full set of options.
80
161
  */
81
162
  addTextWatermark(text: string, opacity: number): Uint8Array;
163
+ /**
164
+ * Apply a text watermark with full control over text or preset, size,
165
+ * rotation, opacity, colour, position, layer, tiling and pages. Returns
166
+ * the new PDF bytes. Text only: there is no image watermark.
167
+ */
168
+ addWatermark(options: WatermarkOptions): Uint8Array;
82
169
  /**
83
170
  * Re-encode all content streams with deflate compression. Removes
84
171
  * no-op overhead. Returns the optimised PDF as a `Uint8Array`.
@@ -99,6 +186,58 @@ export class PdfDoc {
99
186
  * DSS (Document Security Store) info as JSON, or null if absent.
100
187
  */
101
188
  dssInfo(): string | undefined;
189
+ /**
190
+ * The document's blocks as JSON, in reading order (#573).
191
+ *
192
+ * Preview: output quality is still improving and the API may change in a minor release.
193
+ *
194
+ * `{"blocks": [...]}`, one entry per paragraph, heading, list item, table
195
+ * cell and running head, each with its kind, page, box, text, spans and
196
+ * place in the reading order. `docs/STRUCTURED_EXTRACTION.md` is the key
197
+ * to every field.
198
+ *
199
+ * A JSON string and not a structured value, which is what every other
200
+ * structured reader in this binding hands back: one shape crosses the
201
+ * boundary, `JSON.parse` is what the caller already does for
202
+ * `getTextPositions` and the annotations, and a `serde` mirror of the
203
+ * block model would be a second definition of it to keep in step.
204
+ *
205
+ * An XFA form is read from its flattened form, for the reason
206
+ * `extractMarkdown` above gives.
207
+ */
208
+ extractBlocks(first_page?: number | null, page_count?: number | null): string;
209
+ /**
210
+ * The document as a Docling `DoclingDocument`, as JSON (#629).
211
+ *
212
+ * Preview: output quality is still improving and the API may change in a minor release.
213
+ *
214
+ * The schema version the engine pins, which docling-core's
215
+ * `DoclingDocument.model_validate_json` loads as it is. `name` is
216
+ * `DoclingDocument.name`, which Docling fills with the file's stem;
217
+ * absent means `"document"`. An XFA form is read from its flattened form,
218
+ * for the reason `extractMarkdown` above gives.
219
+ */
220
+ extractDocling(first_page?: number | null, page_count?: number | null, name?: string | null): string;
221
+ /**
222
+ * The document as markdown, in reading order (#573).
223
+ *
224
+ * Preview: output quality is still improving and the API may change in a minor release.
225
+ *
226
+ * Headings become `#` to `###`, list items `-` and `1.`, a table a pipe
227
+ * table or an HTML one where markdown cannot hold its shape, and a change
228
+ * of page an HTML comment. The running heads a document repeats are not in
229
+ * it; they are in `extractBlocks`.
230
+ *
231
+ * `firstPage` and `pageCount` choose a window of pages; leave both out for
232
+ * the whole document. The document is read whole whatever the window is,
233
+ * because what a block IS is decided against the rest of the document.
234
+ *
235
+ * AN XFA FORM IS READ FROM ITS FLATTENED FORM, the way `text` and
236
+ * `getTextPositions` read one: a dynamic XFA document draws its fields
237
+ * from a template rather than from page content, so the blocks of the
238
+ * unflattened file are the blocks of an empty page.
239
+ */
240
+ extractMarkdown(first_page?: number | null, page_count?: number | null): string;
102
241
  /**
103
242
  * Extract the listed pages (0-based) into a new document.
104
243
  * Used to implement "split" workflows in the browser.
@@ -191,6 +330,10 @@ export class PdfDoc {
191
330
  /**
192
331
  * Search-and-redact: every match of `query` (literal text, case-sensitive)
193
332
  * is permanently removed from every page.
333
+ *
334
+ * Throws `E-PARSE-INVALID-PDF` when a page's text could not be read:
335
+ * that page was not searched, so returning bytes would read as "no
336
+ * matches there" (#698).
194
337
  */
195
338
  redactSearch(query: string): Uint8Array;
196
339
  /**
@@ -287,6 +430,16 @@ export class PdfDoc {
287
430
  * extraction fails.
288
431
  */
289
432
  text(page_index: number): string;
433
+ /**
434
+ * Every text block of the document with its page and enclosing box, as
435
+ * JSON (#416): `[{"text": "...", "bbox": [xMin, yMin, xMax, yMax], "page": 0}]`.
436
+ *
437
+ * `page` is 0-based like every page index in this binding; `bbox` is in PDF
438
+ * points with the origin at the bottom left (PDF space, not the y-down CSS
439
+ * space `getTextPositions` returns). An XFA form is read from its flattened
440
+ * form, as `text` and `getTextPositions` do.
441
+ */
442
+ textWithLayout(): string;
290
443
  /**
291
444
  * Convert this PDF to a Word `.docx` package.
292
445
  *
@@ -393,6 +546,15 @@ export class PdfDocMut {
393
546
  * `formatted = false`, `bytesChanged = 0`, no error.
394
547
  */
395
548
  formatTextSpan(page_num: number, run_index: number, font_size?: number | null, color?: string | null): string;
549
+ /**
550
+ * The images drawn on a page (0-based `pageIndex`) as JSON, in drawing
551
+ * order, form-nested and inline images included:
552
+ * `[{"formPath":[…],"opIndex":n,"kind":"xobject"|"inline","resourceName":…,
553
+ * "formNames":[…],"ctm":[6],"bbox":[x0,y0,x1,y1],"pixelWidth":…,
554
+ * "pixelHeight":…,"hasSmask":…}]`. `bbox` is in page space, origin at the
555
+ * bottom left. An entry is the handle the three edit methods take.
556
+ */
557
+ imagePlacements(page_index: number): string;
396
558
  /**
397
559
  * Open a PDF for editing.
398
560
  */
@@ -408,12 +570,26 @@ export class PdfDocMut {
408
570
  /**
409
571
  * Search-and-redact: every literal match of `query` is permanently
410
572
  * removed from every page.
573
+ *
574
+ * Throws `E-PARSE-INVALID-PDF` when a page's text could not be read:
575
+ * that page was not searched, so success would read as "no matches
576
+ * there" (#698). The document is then left as it was.
411
577
  */
412
578
  redactSearch(query: string): void;
579
+ /**
580
+ * Remove one placed image. The image data leaves the file when nothing
581
+ * else uses it.
582
+ */
583
+ removeImage(page_index: number, handle_json: string): void;
413
584
  /**
414
585
  * Re-order pages. `new_order` is a permutation of `0..page_count`.
415
586
  */
416
587
  reorderPages(new_order: Uint32Array): void;
588
+ /**
589
+ * Swap the picture of one placed image for JPEG or PNG `data`, fitted
590
+ * inside the old placement and centred. Returns the new handle as JSON.
591
+ */
592
+ replaceImage(page_index: number, handle_json: string, data: Uint8Array): string;
417
593
  /**
418
594
  * G3 — Replace a text span on a page.
419
595
  *
@@ -483,6 +659,13 @@ export class PdfDocMut {
483
659
  * `{"field.path": "value", ...}`.
484
660
  */
485
661
  setFormFields(fields_json: string): void;
662
+ /**
663
+ * Move or resize one placed image so its bounding box becomes
664
+ * `[x0, y0, x1, y1]` in page space. `handleJson` is an entry of
665
+ * `imagePlacements`. Returns the new handle as JSON. An edit inside a Form
666
+ * XObject copies the form for this page, so other pages keep the original.
667
+ */
668
+ setImageRect(page_index: number, handle_json: string, x0: number, y0: number, x1: number, y1: number): string;
486
669
  /**
487
670
  * Select multiple options on a multi-select list box.
488
671
  *
@@ -661,6 +844,52 @@ export class XfaEngine {
661
844
  static version(): string;
662
845
  }
663
846
 
847
+ /**
848
+ * Remove the password from a PDF whose password you know, and return the
849
+ * unprotected bytes; open them with `PdfDoc.open`.
850
+ *
851
+ * The owner password always works. The user password works only when the
852
+ * file has no permission restrictions. Throws `PdfluentError` with
853
+ * `E-SECURITY-DECRYPTION-FAILED` for a password that does not entitle the
854
+ * caller, and `E-WASM-INVALID-ARGUMENT` for a PDF without a password.
855
+ */
856
+ export function decryptPdf(bytes: Uint8Array, password: string): Uint8Array;
857
+
858
+ /**
859
+ * Encrypt a PDF with AES-256 and return the encrypted bytes.
860
+ *
861
+ * `userPassword` is needed to open the file (may be empty: then anyone can
862
+ * open it, and the permissions apply); `ownerPassword` lifts the permissions
863
+ * (empty: the user password serves as both). Refuses a PDF that is already
864
+ * encrypted. Throws `PdfluentError` with `E-WASM-INVALID-ARGUMENT` or
865
+ * `E-PARSE-INVALID-PDF`.
866
+ */
867
+ export function encryptPdf(bytes: Uint8Array, user_password: string, owner_password: string, permissions?: EncryptPermissions | null): Uint8Array;
868
+
869
+ /**
870
+ * Extract the images of a PDF as PNG or JPEG files.
871
+ *
872
+ * Returns `{ images, skipped }`. An image that could not be exported exactly
873
+ * as it looks -- JPEG 2000, JBIG2 or fax compression, a transparency mask, a
874
+ * Decode array, CMYK, an ICC profile other than sRGB -- is listed in `skipped`
875
+ * with the reason, never emitted wrong. Each image is listed once, on the
876
+ * first page (0-based) that uses it.
877
+ */
878
+ export function extractImages(bytes: Uint8Array): ImageExtraction;
879
+
880
+ /**
881
+ * Sign a PDF with your own certificate (a .p12/.pfx file and its password)
882
+ * and return the signed bytes. The private key never leaves the page.
883
+ *
884
+ * This is a cryptographic PAdES signature (ETSI.CAdES.detached), appended as
885
+ * an incremental update so earlier signatures stay valid. Without a
886
+ * timestamp authority: no TSA or LTV in the browser. A self-signed
887
+ * certificate verifies, but readers such as Acrobat show its validity as
888
+ * unknown because they do not trust the issuer. Throws `PdfluentError` with
889
+ * `E-SECURITY-DECRYPTION-FAILED` for a wrong certificate password.
890
+ */
891
+ export function signPdf(bytes: Uint8Array, pkcs12: Uint8Array, password: string, options?: SignPdfOptions | null): Uint8Array;
892
+
664
893
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
665
894
 
666
895
  export interface InitOutput {
@@ -669,14 +898,21 @@ export interface InitOutput {
669
898
  readonly __wbg_pdfdocmut_free: (a: number, b: number) => void;
670
899
  readonly __wbg_texteditor_free: (a: number, b: number) => void;
671
900
  readonly __wbg_xfaengine_free: (a: number, b: number) => void;
901
+ readonly decryptPdf: (a: number, b: number, c: number, d: number, e: number) => void;
902
+ readonly encryptPdf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
903
+ readonly extractImages: (a: number, b: number, c: number) => void;
672
904
  readonly pdfdoc_addFreeText: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
673
905
  readonly pdfdoc_addHighlight: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
674
906
  readonly pdfdoc_addStickyNote: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
675
907
  readonly pdfdoc_addTextWatermark: (a: number, b: number, c: number, d: number, e: number) => void;
908
+ readonly pdfdoc_addWatermark: (a: number, b: number, c: number) => void;
676
909
  readonly pdfdoc_compress: (a: number, b: number) => void;
677
910
  readonly pdfdoc_convertToPdfa: (a: number, b: number, c: number, d: number) => void;
678
911
  readonly pdfdoc_deletePages: (a: number, b: number, c: number, d: number) => void;
679
912
  readonly pdfdoc_dssInfo: (a: number, b: number) => void;
913
+ readonly pdfdoc_extractBlocks: (a: number, b: number, c: number, d: number) => void;
914
+ readonly pdfdoc_extractDocling: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
915
+ readonly pdfdoc_extractMarkdown: (a: number, b: number, c: number, d: number) => void;
680
916
  readonly pdfdoc_extractPages: (a: number, b: number, c: number, d: number) => void;
681
917
  readonly pdfdoc_flattenXfa: (a: number, b: number) => void;
682
918
  readonly pdfdoc_getAnnotations: (a: number, b: number, c: number) => void;
@@ -701,6 +937,7 @@ export interface InitOutput {
701
937
  readonly pdfdoc_setFormFields: (a: number, b: number, c: number, d: number) => void;
702
938
  readonly pdfdoc_signatures: (a: number, b: number) => void;
703
939
  readonly pdfdoc_text: (a: number, b: number, c: number) => void;
940
+ readonly pdfdoc_textWithLayout: (a: number, b: number) => void;
704
941
  readonly pdfdoc_toDocx: (a: number, b: number) => void;
705
942
  readonly pdfdoc_toPptx: (a: number, b: number) => void;
706
943
  readonly pdfdoc_toXlsx: (a: number, b: number) => void;
@@ -716,18 +953,23 @@ export interface InitOutput {
716
953
  readonly pdfdocmut_deletePages: (a: number, b: number, c: number, d: number) => void;
717
954
  readonly pdfdocmut_extractPages: (a: number, b: number, c: number, d: number) => void;
718
955
  readonly pdfdocmut_formatTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
956
+ readonly pdfdocmut_imagePlacements: (a: number, b: number, c: number) => void;
719
957
  readonly pdfdocmut_open: (a: number, b: number, c: number) => void;
720
958
  readonly pdfdocmut_pageCount: (a: number) => number;
721
959
  readonly pdfdocmut_redactRegion: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
722
960
  readonly pdfdocmut_redactSearch: (a: number, b: number, c: number, d: number) => void;
961
+ readonly pdfdocmut_removeImage: (a: number, b: number, c: number, d: number, e: number) => void;
723
962
  readonly pdfdocmut_reorderPages: (a: number, b: number, c: number, d: number) => void;
963
+ readonly pdfdocmut_replaceImage: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
724
964
  readonly pdfdocmut_replaceTextSpan: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
725
965
  readonly pdfdocmut_rotatePage: (a: number, b: number, c: number, d: number) => void;
726
966
  readonly pdfdocmut_save: (a: number, b: number) => void;
727
967
  readonly pdfdocmut_setFormField: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
728
968
  readonly pdfdocmut_setFormFields: (a: number, b: number, c: number, d: number) => void;
969
+ readonly pdfdocmut_setImageRect: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
729
970
  readonly pdfdocmut_setMultiSelect: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
730
971
  readonly pdfdocmut_setTextRunStyle: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
972
+ readonly signPdf: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
731
973
  readonly texteditor_findText: (a: number, b: number, c: number, d: number) => void;
732
974
  readonly texteditor_open: (a: number, b: number, c: number) => void;
733
975
  readonly texteditor_pageCount: (a: number) => number;