@embedpdf/engines 1.0.3 → 1.0.4

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.
Files changed (49) hide show
  1. package/dist/converters.cjs +149 -115
  2. package/dist/converters.cjs.map +1 -1
  3. package/dist/converters.d.ts +2 -1
  4. package/dist/converters.js +143 -86
  5. package/dist/converters.js.map +1 -1
  6. package/dist/index.cjs +5362 -5978
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +1479 -6
  9. package/dist/index.js +5399 -356
  10. package/dist/index.js.map +1 -1
  11. package/dist/pdfium-direct-engine.cjs +4037 -0
  12. package/dist/pdfium-direct-engine.cjs.map +1 -0
  13. package/dist/{pdfium.d.cts → pdfium-direct-engine.d.ts} +4 -96
  14. package/dist/pdfium-direct-engine.js +4035 -0
  15. package/dist/pdfium-direct-engine.js.map +1 -0
  16. package/dist/pdfium-worker-engine.cjs +800 -0
  17. package/dist/pdfium-worker-engine.cjs.map +1 -0
  18. package/dist/{worker.d.cts → pdfium-worker-engine.d.ts} +36 -4
  19. package/dist/pdfium-worker-engine.js +798 -0
  20. package/dist/pdfium-worker-engine.js.map +1 -0
  21. package/dist/pdfium.cjs +4243 -5647
  22. package/dist/pdfium.cjs.map +1 -1
  23. package/dist/pdfium.d.ts +131 -3
  24. package/dist/pdfium.js +4288 -21
  25. package/dist/pdfium.js.map +1 -1
  26. package/dist/preact.cjs +39 -0
  27. package/dist/preact.cjs.map +1 -0
  28. package/dist/preact.d.ts +13 -0
  29. package/dist/preact.js +37 -0
  30. package/dist/preact.js.map +1 -0
  31. package/dist/react.cjs +39 -0
  32. package/dist/react.cjs.map +1 -0
  33. package/dist/react.d.ts +13 -0
  34. package/dist/react.js +37 -0
  35. package/dist/react.js.map +1 -0
  36. package/dist/worker.cjs +771 -1104
  37. package/dist/worker.cjs.map +1 -1
  38. package/dist/worker.d.ts +30 -4
  39. package/dist/worker.js +786 -11
  40. package/dist/worker.js.map +1 -1
  41. package/package.json +42 -8
  42. package/dist/chunk-FXQUMVH5.js +0 -4599
  43. package/dist/chunk-FXQUMVH5.js.map +0 -1
  44. package/dist/chunk-YZLT3A2D.js +0 -1101
  45. package/dist/chunk-YZLT3A2D.js.map +0 -1
  46. package/dist/converters.d.cts +0 -69
  47. package/dist/index.d.cts +0 -32
  48. package/dist/runner-BvRtPCKL.d.cts +0 -131
  49. package/dist/runner-BvRtPCKL.d.ts +0 -131
package/dist/index.d.ts CHANGED
@@ -1,8 +1,1480 @@
1
- export { BitmapFormat, ImageDataConverter, PdfiumEngine, PdfiumEngineRunner, PdfiumErrorCode, RenderFlag, SearchContext, browserImageDataToBlobConverter, readArrayBuffer, readString } from './pdfium.js';
2
- export { WebWorkerEngine, WorkerTask } from './worker.js';
3
- export { A as AbortRequest, e as EngineRunner, E as ExecuteRequest, b as ExecuteResponse, P as PdfEngineMethodRequestBody, a as PdfEngineMethodResponseBody, R as ReadyResponse, c as Request, d as Response } from './runner-BvRtPCKL.js';
4
- import { PdfEngine, PdfDocumentObject, PdfFile } from '@embedpdf/models';
5
- import '@embedpdf/pdfium';
1
+ import { SearchTarget, PdfImage, PdfEngine, Logger, Task, PdfErrorReason, PdfFileUrl, PdfUrlOptions, PdfDocumentObject, PdfFile, PdfFileLoader, PdfSignatureObject, PdfBookmarkObject, PdfPageObject, Rotation, PdfRenderOptions, PdfTask, Rect, PdfAnnotationObject, PdfAnnotationTransformation, PdfTextRectObject, PdfAttachmentObject, PdfWidgetAnnoObject, FormFieldValue, PdfPageFlattenFlag, PdfPageFlattenResult, PdfInkListObject, PdfStampAnnoObjectContents, Position, PdfPageGeometry, PdfGlyphObject, MatchFlag, SearchAllPagesResult, PdfEngineMethodName, PdfEngineMethodArgs, TaskReturn, PdfEngineMethodReturnType, PdfMetadataObject, PdfBookmarksObject } from '@embedpdf/models';
2
+ import { WrappedPdfiumModule, PdfiumRuntimeMethods, PdfiumModule } from '@embedpdf/pdfium';
3
+
4
+ /**
5
+ * Format of bitmap
6
+ */
7
+ declare enum BitmapFormat {
8
+ Bitmap_Gray = 1,
9
+ Bitmap_BGR = 2,
10
+ Bitmap_BGRx = 3,
11
+ Bitmap_BGRA = 4
12
+ }
13
+ /**
14
+ * Pdf rendering flag
15
+ */
16
+ declare enum RenderFlag {
17
+ ANNOT = 1,// Set if annotations are to be rendered.
18
+ LCD_TEXT = 2,// Set if using text rendering optimized for LCD display.
19
+ NO_NATIVETEXT = 4,// Don't use the native text output available on some platforms
20
+ GRAYSCALE = 8,// Grayscale output.
21
+ DEBUG_INFO = 128,// Set if you want to get some debug info. Please discuss with Foxit first if you need to collect debug info.
22
+ NO_CATCH = 256,// Set if you don't want to catch exception.
23
+ RENDER_LIMITEDIMAGECACHE = 512,// Limit image cache size.
24
+ RENDER_FORCEHALFTONE = 1024,// Always use halftone for image stretching.
25
+ PRINTING = 2048,// Render for printing.
26
+ REVERSE_BYTE_ORDER = 16
27
+ }
28
+ /**
29
+ * Context used for searching
30
+ */
31
+ interface SearchContext {
32
+ /**
33
+ * search target
34
+ */
35
+ target: SearchTarget;
36
+ /**
37
+ * current page index
38
+ */
39
+ currPageIndex: number;
40
+ /**
41
+ * index of text in the current pdf page, -1 means reach the end
42
+ */
43
+ startIndex: number;
44
+ }
45
+ /**
46
+ * Error code of pdfium library
47
+ */
48
+ declare enum PdfiumErrorCode {
49
+ Success = 0,
50
+ Unknown = 1,
51
+ File = 2,
52
+ Format = 3,
53
+ Password = 4,
54
+ Security = 5,
55
+ Page = 6,
56
+ XFALoad = 7,
57
+ XFALayout = 8
58
+ }
59
+ /**
60
+ * Function type for converting ImageData to Blob
61
+ * In browser: uses OffscreenCanvas
62
+ * In Node.js: can use Sharp or other image processing libraries
63
+ */
64
+ type ImageDataConverter<T = Blob> = (imageData: PdfImage) => Promise<T>;
65
+ declare const browserImageDataToBlobConverter: ImageDataConverter<Blob>;
66
+ /**
67
+ * Pdf engine that based on pdfium wasm
68
+ */
69
+ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
70
+ private pdfiumModule;
71
+ private logger;
72
+ private imageDataConverter;
73
+ /**
74
+ * pdf documents that opened
75
+ */
76
+ private readonly cache;
77
+ /**
78
+ * Create an instance of PdfiumEngine
79
+ * @param wasmModule - pdfium wasm module
80
+ * @param logger - logger instance
81
+ * @param imageDataToBlobConverter - function to convert ImageData to Blob
82
+ */
83
+ constructor(pdfiumModule: WrappedPdfiumModule, logger?: Logger, imageDataConverter?: ImageDataConverter<T>);
84
+ /**
85
+ * {@inheritDoc @embedpdf/models!PdfEngine.initialize}
86
+ *
87
+ * @public
88
+ */
89
+ initialize(): Task<boolean, PdfErrorReason>;
90
+ /**
91
+ * {@inheritDoc @embedpdf/models!PdfEngine.destroy}
92
+ *
93
+ * @public
94
+ */
95
+ destroy(): Task<boolean, PdfErrorReason>;
96
+ /**
97
+ * {@inheritDoc @embedpdf/models!PdfEngine.openDocumentUrl}
98
+ *
99
+ * @public
100
+ */
101
+ openDocumentUrl(file: PdfFileUrl, options?: PdfUrlOptions): Task<PdfDocumentObject, PdfErrorReason>;
102
+ /**
103
+ * Check if the server supports range requests:
104
+ * Sends a HEAD request and sees if 'Accept-Ranges: bytes'.
105
+ */
106
+ private checkRangeSupport;
107
+ /**
108
+ * Fully fetch the file (using fetch) into an ArrayBuffer,
109
+ * then call openDocumentFromBuffer.
110
+ */
111
+ private fetchFullAndOpen;
112
+ /**
113
+ * Use your synchronous partial-loading approach:
114
+ * - In your snippet, it's done via `openDocumentFromLoader`.
115
+ * - We'll do a synchronous XHR read callback that pulls
116
+ * the desired byte ranges.
117
+ */
118
+ private openDocumentWithRangeRequest;
119
+ /**
120
+ * Helper to do a HEAD request or partial GET to find file length.
121
+ */
122
+ private retrieveFileLength;
123
+ /**
124
+ * Convert response text (x-user-defined) to a Uint8Array
125
+ * for partial data.
126
+ */
127
+ private convertResponseToUint8Array;
128
+ /**
129
+ * {@inheritDoc @embedpdf/models!PdfEngine.openDocument}
130
+ *
131
+ * @public
132
+ */
133
+ openDocumentFromBuffer(file: PdfFile, password?: string): Task<PdfDocumentObject, PdfErrorReason>;
134
+ /**
135
+ * {@inheritDoc @embedpdf/models!PdfEngine.openDocumentFromLoader}
136
+ *
137
+ * @public
138
+ */
139
+ openDocumentFromLoader(fileLoader: PdfFileLoader, password?: string): Task<PdfDocumentObject, PdfErrorReason>;
140
+ /**
141
+ * {@inheritDoc @embedpdf/models!PdfEngine.getMetadata}
142
+ *
143
+ * @public
144
+ */
145
+ getMetadata(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<{
146
+ title: string;
147
+ author: string;
148
+ subject: string;
149
+ keywords: string;
150
+ producer: string;
151
+ creator: string;
152
+ creationDate: string;
153
+ modificationDate: string;
154
+ }, PdfErrorReason>;
155
+ /**
156
+ * {@inheritDoc @embedpdf/models!PdfEngine.getDocPermissions}
157
+ *
158
+ * @public
159
+ */
160
+ getDocPermissions(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<number, PdfErrorReason>;
161
+ /**
162
+ * {@inheritDoc @embedpdf/models!PdfEngine.getDocUserPermissions}
163
+ *
164
+ * @public
165
+ */
166
+ getDocUserPermissions(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<number, PdfErrorReason>;
167
+ /**
168
+ * {@inheritDoc @embedpdf/models!PdfEngine.getSignatures}
169
+ *
170
+ * @public
171
+ */
172
+ getSignatures(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<PdfSignatureObject[], PdfErrorReason>;
173
+ /**
174
+ * {@inheritDoc @embedpdf/models!PdfEngine.getBookmarks}
175
+ *
176
+ * @public
177
+ */
178
+ getBookmarks(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<{
179
+ bookmarks: PdfBookmarkObject[];
180
+ }, PdfErrorReason>;
181
+ /**
182
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderPage}
183
+ *
184
+ * @public
185
+ */
186
+ renderPage(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor?: number, rotation?: Rotation, dpr?: number, options?: PdfRenderOptions): PdfTask<T>;
187
+ /**
188
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderPageRect}
189
+ *
190
+ * @public
191
+ */
192
+ renderPageRect(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation, dpr: number, rect: Rect, options: PdfRenderOptions): PdfTask<T>;
193
+ /**
194
+ * {@inheritDoc @embedpdf/models!PdfEngine.getAllAnnotations}
195
+ *
196
+ * @public
197
+ */
198
+ getAllAnnotations(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<Record<number, PdfAnnotationObject[]>, PdfErrorReason>;
199
+ private readAllAnnotations;
200
+ /**
201
+ * {@inheritDoc @embedpdf/models!PdfEngine.getPageAnnotations}
202
+ *
203
+ * @public
204
+ */
205
+ getPageAnnotations(doc: PdfDocumentObject, page: PdfPageObject): Task<any, PdfErrorReason> | Task<PdfAnnotationObject[], PdfErrorReason>;
206
+ /**
207
+ * {@inheritDoc @embedpdf/models!PdfEngine.createPageAnnotation}
208
+ *
209
+ * @public
210
+ */
211
+ createPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
212
+ /**
213
+ * {@inheritDoc @embedpdf/models!PdfEngine.transformPageAnnotation}
214
+ *
215
+ * @public
216
+ */
217
+ transformPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject, transformation: PdfAnnotationTransformation): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
218
+ /**
219
+ * {@inheritDoc @embedpdf/models!PdfEngine.removePageAnnotation}
220
+ *
221
+ * @public
222
+ */
223
+ removePageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
224
+ /**
225
+ * {@inheritDoc @embedpdf/models!PdfEngine.getPageTextRects}
226
+ *
227
+ * @public
228
+ */
229
+ getPageTextRects(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation): Task<any, PdfErrorReason> | Task<PdfTextRectObject[], PdfErrorReason>;
230
+ /**
231
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderThumbnail}
232
+ *
233
+ * @public
234
+ */
235
+ renderThumbnail(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation, dpr: number): PdfTask<T>;
236
+ /**
237
+ * {@inheritDoc @embedpdf/models!PdfEngine.getAttachments}
238
+ *
239
+ * @public
240
+ */
241
+ getAttachments(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<PdfAttachmentObject[], PdfErrorReason>;
242
+ /**
243
+ * {@inheritDoc @embedpdf/models!PdfEngine.readAttachmentContent}
244
+ *
245
+ * @public
246
+ */
247
+ readAttachmentContent(doc: PdfDocumentObject, attachment: PdfAttachmentObject): Task<any, PdfErrorReason> | Task<ArrayBuffer, PdfErrorReason>;
248
+ /**
249
+ * {@inheritDoc @embedpdf/models!PdfEngine.setFormFieldValue}
250
+ *
251
+ * @public
252
+ */
253
+ setFormFieldValue(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, value: FormFieldValue): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
254
+ /**
255
+ * {@inheritDoc @embedpdf/models!PdfEngine.flattenPage}
256
+ *
257
+ * @public
258
+ */
259
+ flattenPage(doc: PdfDocumentObject, page: PdfPageObject, flag: PdfPageFlattenFlag): PdfTask<PdfPageFlattenResult>;
260
+ /**
261
+ * {@inheritDoc @embedpdf/models!PdfEngine.extractPages}
262
+ *
263
+ * @public
264
+ */
265
+ extractPages(doc: PdfDocumentObject, pageIndexes: number[]): Task<any, PdfErrorReason> | Task<ArrayBuffer, PdfErrorReason>;
266
+ /**
267
+ * {@inheritDoc @embedpdf/models!PdfEngine.extractText}
268
+ *
269
+ * @public
270
+ */
271
+ extractText(doc: PdfDocumentObject, pageIndexes: number[]): Task<any, PdfErrorReason> | Task<string, PdfErrorReason>;
272
+ /**
273
+ * {@inheritDoc @embedpdf/models!PdfEngine.merge}
274
+ *
275
+ * @public
276
+ */
277
+ merge(files: PdfFile[]): Task<any, PdfErrorReason> | Task<PdfFile, PdfErrorReason>;
278
+ /**
279
+ * Merges specific pages from multiple PDF documents in a custom order
280
+ *
281
+ * @param mergeConfigs Array of configurations specifying which pages to merge from which documents
282
+ * @returns A PdfTask that resolves with the merged PDF file
283
+ * @public
284
+ */
285
+ mergePages(mergeConfigs: Array<{
286
+ docId: string;
287
+ pageIndices: number[];
288
+ }>): Task<any, PdfErrorReason> | Task<PdfFile, PdfErrorReason>;
289
+ /**
290
+ * {@inheritDoc @embedpdf/models!PdfEngine.saveAsCopy}
291
+ *
292
+ * @public
293
+ */
294
+ saveAsCopy(doc: PdfDocumentObject): Task<any, PdfErrorReason> | Task<ArrayBuffer, PdfErrorReason>;
295
+ /**
296
+ * {@inheritDoc @embedpdf/models!PdfEngine.closeDocument}
297
+ *
298
+ * @public
299
+ */
300
+ closeDocument(doc: PdfDocumentObject): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
301
+ /**
302
+ * Memory allocation
303
+ * @param size - size of memory space
304
+ * @returns pointer to memory space
305
+ *
306
+ * @public
307
+ */
308
+ malloc(size: number): number;
309
+ /**
310
+ * Free memory space
311
+ * @param ptr pointer to memory space
312
+ *
313
+ * @public
314
+ */
315
+ free(ptr: number): void;
316
+ /**
317
+ * Set the rect of specified annotation
318
+ * @param page - page info that the annotation is belonged to
319
+ * @param pagePtr - pointer of page object
320
+ * @param annotationPtr - pointer to annotation object
321
+ * @param inkList - ink lists that added to the annotation
322
+ * @returns whether the ink lists is setted
323
+ *
324
+ * @private
325
+ */
326
+ addInkStroke(page: PdfPageObject, pagePtr: number, annotationPtr: number, inkList: PdfInkListObject[]): boolean;
327
+ /**
328
+ * Add contents to stamp annotation
329
+ * @param docPtr - pointer to pdf document object
330
+ * @param page - page info
331
+ * @param pagePtr - pointer to page object
332
+ * @param annotationPtr - pointer to stamp annotation
333
+ * @param rect - rect of stamp annotation
334
+ * @param contents - contents of stamp annotation
335
+ * @returns whether contents is added to annotation
336
+ *
337
+ * @private
338
+ */
339
+ addStampContent(docPtr: number, page: PdfPageObject, pagePtr: number, annotationPtr: number, rect: Rect, contents: PdfStampAnnoObjectContents): boolean;
340
+ /**
341
+ * Add image object to annotation
342
+ * @param docPtr - pointer to pdf document object
343
+ * @param page - page info
344
+ * @param pagePtr - pointer to page object
345
+ * @param annotationPtr - pointer to stamp annotation
346
+ * @param position - position of image
347
+ * @param imageData - data of image
348
+ * @returns whether image is added to annotation
349
+ *
350
+ * @private
351
+ */
352
+ addImageObject(docPtr: number, page: PdfPageObject, pagePtr: number, annotationPtr: number, position: Position, imageData: ImageData): boolean;
353
+ /**
354
+ * Save document to array buffer
355
+ * @param docPtr - pointer to pdf document
356
+ * @returns array buffer contains the pdf content
357
+ *
358
+ * @private
359
+ */
360
+ saveDocument(docPtr: number): ArrayBuffer;
361
+ /**
362
+ * Read metadata from pdf document
363
+ * @param docPtr - pointer to pdf document
364
+ * @param key - key of metadata field
365
+ * @returns metadata value
366
+ *
367
+ * @private
368
+ */
369
+ readMetaText(docPtr: number, key: string): string;
370
+ /**
371
+ * Read bookmarks in the pdf document
372
+ * @param docPtr - pointer to pdf document
373
+ * @param rootBookmarkPtr - pointer to root bookmark
374
+ * @returns bookmarks in the pdf document
375
+ *
376
+ * @private
377
+ */
378
+ readPdfBookmarks(docPtr: number, rootBookmarkPtr?: number): PdfBookmarkObject[];
379
+ /**
380
+ * Read bookmark in the pdf document
381
+ * @param docPtr - pointer to pdf document
382
+ * @param bookmarkPtr - pointer to bookmark object
383
+ * @returns pdf bookmark object
384
+ *
385
+ * @private
386
+ */
387
+ private readPdfBookmark;
388
+ /**
389
+ * Read text rects in pdf page
390
+ * @param page - pdf page info
391
+ * @param docPtr - pointer to pdf document
392
+ * @param pagePtr - pointer to pdf page
393
+ * @param textPagePtr - pointer to pdf text page
394
+ * @returns text rects in the pdf page
395
+ *
396
+ * @public
397
+ */
398
+ private readPageTextRects;
399
+ /**
400
+ * Return geometric + logical text layout for one page
401
+ * (glyph-only implementation, no FPDFText_GetRect).
402
+ *
403
+ * @public
404
+ */
405
+ getPageGeometry(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfPageGeometry>;
406
+ /**
407
+ * Group consecutive glyphs that belong to the same CPDF_TextObject
408
+ * using FPDFText_GetTextObject(), and calculate rotation from glyph positions.
409
+ */
410
+ private buildRunsFromGlyphs;
411
+ /**
412
+ * Extract glyph geometry + metadata for `charIndex`
413
+ *
414
+ * Returns device–space coordinates:
415
+ * x,y → **top-left** corner (integer-pixels)
416
+ * w,h → width / height (integer-pixels, ≥ 1)
417
+ *
418
+ * And two flags:
419
+ * isSpace → true if the glyph's Unicode code-point is U+0020
420
+ */
421
+ private readGlyphInfo;
422
+ /**
423
+ * Geometry-only text extraction
424
+ * ------------------------------------------
425
+ * Returns every glyph on the requested page
426
+ * in the logical order delivered by PDFium.
427
+ *
428
+ * The promise resolves to an array of objects:
429
+ * {
430
+ * idx: number; // glyph index on the page (0…n-1)
431
+ * origin: { x: number; y: number };
432
+ * size: { width: number; height: number };
433
+ * angle: number; // degrees, counter-clock-wise
434
+ * isSpace: boolean; // true → U+0020
435
+ * }
436
+ *
437
+ * No Unicode is included; front-end decides whether to hydrate it.
438
+ */
439
+ getPageGlyphs(doc: PdfDocumentObject, page: PdfPageObject): PdfTask<PdfGlyphObject[]>;
440
+ private readCharBox;
441
+ /**
442
+ * Read page annotations
443
+ * @param page - page info
444
+ * @param docPtr - pointer to pdf document
445
+ * @param pagePtr - pointer to pdf page
446
+ * @param textPagePtr - pointe to pdf text page
447
+ * @param scaleFactor - scale factor
448
+ * @param rotation - rotation angle
449
+ * @returns annotations on the pdf page
450
+ *
451
+ * @private
452
+ */
453
+ private readPageAnnotations;
454
+ /**
455
+ * Read pdf annotation from pdf document
456
+ * @param page - pdf page infor
457
+ * @param docPtr - pointer to pdf document object
458
+ * @param pagePtr - pointer to pdf page object
459
+ * @param textPagePtr - pointer to pdf text page object
460
+ * @param formHandle - form handle
461
+ * @param index - index of annotation in the pdf page
462
+ * @param scaleFactor - factor of scalling
463
+ * @param rotation - rotation angle
464
+ * @returns pdf annotation
465
+ *
466
+ * @private
467
+ */
468
+ private readPageAnnotation;
469
+ /**
470
+ * Return the colour stored directly in the annotation dictionary's `/C` entry.
471
+ *
472
+ * Most PDFs created by Acrobat, Microsoft Office, LaTeX, etc. include this entry.
473
+ * When the key is absent (common in macOS Preview, Chrome, Drawboard) the call
474
+ * fails and the function returns `undefined`.
475
+ *
476
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
477
+ * @returns An RGBA tuple (0-255 channels) or `undefined` if no `/C` entry exists
478
+ *
479
+ * @private
480
+ */
481
+ private readAnnotationColor;
482
+ /**
483
+ * Extract the fill (or, if absent, the stroke) colour from a **path object**
484
+ * inside an appearance stream.
485
+ *
486
+ * Works for simple highlights produced by Chrome, Preview, etc. that paint a
487
+ * single filled rectangle with the desired tint.
488
+ *
489
+ * @param pathPtr - pointer to a `FPDF_PAGEOBJECT` of type **PATH**
490
+ * @returns RGBA tuple or `undefined` when no colour is set on the path
491
+ *
492
+ * @private
493
+ */
494
+ private getColorFromPath;
495
+ /**
496
+ * Recursively walk a page-object tree (PATHs and nested FORM XObjects) until
497
+ * a colour can be extracted.
498
+ *
499
+ * Acrobat often wraps its highlight rectangle in a Form XObject referenced by
500
+ * the "Do" operator, so this function drills down unlimited depth.
501
+ *
502
+ * @param objPtr - pointer to a `FPDF_PAGEOBJECT`
503
+ * @returns First RGBA tint found, or `undefined` if none of the descendants
504
+ * carry an explicit fill/stroke colour
505
+ *
506
+ * @private
507
+ */
508
+ private walkPageObjTree;
509
+ /**
510
+ * Iterate over every top-level object in the annotation's **appearance stream**
511
+ * and invoke {@link walkPageObjTree} to locate a usable tint.
512
+ *
513
+ * Catches:
514
+ * • Simple filled path (Preview, Chrome)
515
+ * • Form XObject containing the path (Acrobat)
516
+ *
517
+ * @param annotPtr - pointer to an `FPDF_ANNOTATION`
518
+ * @returns RGBA tuple or `undefined` when no colour can be resolved from AP
519
+ *
520
+ * @private
521
+ */
522
+ private colorFromAppearance;
523
+ /**
524
+ * Resolve the visible fill colour for **Highlight / Underline / StrikeOut /
525
+ * Squiggly** markup annotations.
526
+ *
527
+ * Resolution order (first non-`undefined` wins):
528
+ * 1. `/C` dictionary entry – fast, present in Acrobat / Office PDFs
529
+ * 2. Appearance-stream objects – drills into paths & nested forms
530
+ * 3. Hard-coded fallback (Acrobat-style opaque yellow)
531
+ *
532
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
533
+ * @param fallback - colour to use when the PDF stores no tint at all
534
+ * @returns Guaranteed RGBA tuple (never `undefined`)
535
+ *
536
+ * @private
537
+ */
538
+ private resolveAnnotationColor;
539
+ /**
540
+ * Read `/QuadPoints` from any annotation and convert each quadrilateral to
541
+ * device-space coordinates.
542
+ *
543
+ * The four points are returned in natural reading order:
544
+ * `p1 → p2` (top edge) and `p4 → p3` (bottom edge).
545
+ * This preserves the true shape for rotated / skewed text, whereas callers
546
+ * that only need axis-aligned boxes can collapse each quad themselves.
547
+ *
548
+ * @param page - logical page info object (`PdfPageObject`)
549
+ * @param annotationPtr - pointer to the annotation whose quads are needed
550
+ * @returns Array of `Quad` objects (`[]` if the annotation has no quads)
551
+ *
552
+ * @private
553
+ */
554
+ private readAnnotationQuads;
555
+ /**
556
+ * Read pdf text annotation
557
+ * @param page - pdf page infor
558
+ * @param pagePtr - pointer to pdf page object
559
+ * @param annotationPtr - pointer to pdf annotation
560
+ * @param index - index of annotation in the pdf page
561
+ * @returns pdf text annotation
562
+ *
563
+ * @private
564
+ */
565
+ private readPdfTextAnno;
566
+ /**
567
+ * Read pdf freetext annotation
568
+ * @param page - pdf page infor
569
+ * @param pagePtr - pointer to pdf page object
570
+ * @param annotationPtr - pointer to pdf annotation
571
+ * @param index - index of annotation in the pdf page
572
+ * @returns pdf freetext annotation
573
+ *
574
+ * @private
575
+ */
576
+ private readPdfFreeTextAnno;
577
+ /**
578
+ * Read pdf link annotation from pdf document
579
+ * @param page - pdf page infor
580
+ * @param docPtr - pointer to pdf document object
581
+ * @param pagePtr - pointer to pdf page object
582
+ * @param textPagePtr - pointer to pdf text page object
583
+ * @param annotationPtr - pointer to pdf annotation
584
+ * @param index - index of annotation in the pdf page
585
+ * @returns pdf link annotation
586
+ *
587
+ * @private
588
+ */
589
+ private readPdfLinkAnno;
590
+ /**
591
+ * Read pdf widget annotation
592
+ * @param page - pdf page infor
593
+ * @param pagePtr - pointer to pdf page object
594
+ * @param annotationPtr - pointer to pdf annotation
595
+ * @param formHandle - form handle
596
+ * @param index - index of annotation in the pdf page
597
+ * @returns pdf widget annotation
598
+ *
599
+ * @private
600
+ */
601
+ private readPdfWidgetAnno;
602
+ /**
603
+ * Read pdf file attachment annotation
604
+ * @param page - pdf page infor
605
+ * @param pagePtr - pointer to pdf page object
606
+ * @param annotationPtr - pointer to pdf annotation
607
+ * @param index - index of annotation in the pdf page
608
+ * @returns pdf file attachment annotation
609
+ *
610
+ * @private
611
+ */
612
+ private readPdfFileAttachmentAnno;
613
+ /**
614
+ * Read pdf ink annotation
615
+ * @param page - pdf page infor
616
+ * @param pagePtr - pointer to pdf page object
617
+ * @param annotationPtr - pointer to pdf annotation
618
+ * @param index - index of annotation in the pdf page
619
+ * @returns pdf ink annotation
620
+ *
621
+ * @private
622
+ */
623
+ private readPdfInkAnno;
624
+ /**
625
+ * Read pdf polygon annotation
626
+ * @param page - pdf page infor
627
+ * @param pagePtr - pointer to pdf page object
628
+ * @param annotationPtr - pointer to pdf annotation
629
+ * @param index - index of annotation in the pdf page
630
+ * @returns pdf polygon annotation
631
+ *
632
+ * @private
633
+ */
634
+ private readPdfPolygonAnno;
635
+ /**
636
+ * Read pdf polyline annotation
637
+ * @param page - pdf page infor
638
+ * @param pagePtr - pointer to pdf page object
639
+ * @param annotationPtr - pointer to pdf annotation
640
+ * @param index - index of annotation in the pdf page
641
+ * @returns pdf polyline annotation
642
+ *
643
+ * @private
644
+ */
645
+ private readPdfPolylineAnno;
646
+ /**
647
+ * Read pdf line annotation
648
+ * @param page - pdf page infor
649
+ * @param pagePtr - pointer to pdf page object
650
+ * @param annotationPtr - pointer to pdf annotation
651
+ * @param index - index of annotation in the pdf page
652
+ * @returns pdf line annotation
653
+ *
654
+ * @private
655
+ */
656
+ private readPdfLineAnno;
657
+ /**
658
+ * Read pdf highlight annotation
659
+ * @param page - pdf page infor
660
+ * @param pagePtr - pointer to pdf page object
661
+ * @param annotationPtr - pointer to pdf annotation
662
+ * @param index - index of annotation in the pdf page
663
+ * @returns pdf highlight annotation
664
+ *
665
+ * @private
666
+ */
667
+ private readPdfHighlightAnno;
668
+ /**
669
+ * Read pdf underline annotation
670
+ * @param page - pdf page infor
671
+ * @param pagePtr - pointer to pdf page object
672
+ * @param annotationPtr - pointer to pdf annotation
673
+ * @param index - index of annotation in the pdf page
674
+ * @returns pdf underline annotation
675
+ *
676
+ * @private
677
+ */
678
+ private readPdfUnderlineAnno;
679
+ /**
680
+ * Read strikeout annotation
681
+ * @param page - pdf page infor
682
+ * @param pagePtr - pointer to pdf page object
683
+ * @param annotationPtr - pointer to pdf annotation
684
+ * @param index - index of annotation in the pdf page
685
+ * @returns pdf strikeout annotation
686
+ *
687
+ * @private
688
+ */
689
+ private readPdfStrikeOutAnno;
690
+ /**
691
+ * Read pdf squiggly annotation
692
+ * @param page - pdf page infor
693
+ * @param pagePtr - pointer to pdf page object
694
+ * @param annotationPtr - pointer to pdf annotation
695
+ * @param index - index of annotation in the pdf page
696
+ * @returns pdf squiggly annotation
697
+ *
698
+ * @private
699
+ */
700
+ private readPdfSquigglyAnno;
701
+ /**
702
+ * Read pdf caret annotation
703
+ * @param page - pdf page infor
704
+ * @param pagePtr - pointer to pdf page object
705
+ * @param annotationPtr - pointer to pdf annotation
706
+ * @param index - index of annotation in the pdf page
707
+ * @returns pdf caret annotation
708
+ *
709
+ * @private
710
+ */
711
+ private readPdfCaretAnno;
712
+ /**
713
+ * Read pdf stamp annotation
714
+ * @param docPtr - pointer to pdf document object
715
+ * @param page - pdf page infor
716
+ * @param pagePtr - pointer to pdf page object
717
+ * @param annotationPtr - pointer to pdf annotation
718
+ * @param index - index of annotation in the pdf page
719
+ * @returns pdf stamp annotation
720
+ *
721
+ * @private
722
+ */
723
+ private readPdfStampAnno;
724
+ /**
725
+ * Read pdf object in pdf page
726
+ * @param pageObjectPtr - pointer to pdf object in page
727
+ * @returns pdf object in page
728
+ *
729
+ * @private
730
+ */
731
+ private readPdfPageObject;
732
+ /**
733
+ * Read pdf path object
734
+ * @param pathObjectPtr - pointer to pdf path object in page
735
+ * @returns pdf path object
736
+ *
737
+ * @private
738
+ */
739
+ private readPathObject;
740
+ /**
741
+ * Read segment of pdf path object
742
+ * @param annotationObjectPtr - pointer to pdf path object
743
+ * @param segmentIndex - index of segment
744
+ * @returns pdf segment in pdf path
745
+ *
746
+ * @private
747
+ */
748
+ private readPdfSegment;
749
+ /**
750
+ * Read pdf image object from pdf document
751
+ * @param pageObjectPtr - pointer to pdf image object in page
752
+ * @returns pdf image object
753
+ *
754
+ * @private
755
+ */
756
+ private readImageObject;
757
+ /**
758
+ * Read form object from pdf document
759
+ * @param formObjectPtr - pointer to pdf form object in page
760
+ * @returns pdf form object
761
+ *
762
+ * @private
763
+ */
764
+ private readFormObject;
765
+ /**
766
+ * Read pdf object in pdf page
767
+ * @param pageObjectPtr - pointer to pdf object in page
768
+ * @returns pdf object in page
769
+ *
770
+ * @private
771
+ */
772
+ private readPdfPageObjectTransformMatrix;
773
+ /**
774
+ * Read circle annotation
775
+ * @param page - pdf page infor
776
+ * @param pagePtr - pointer to pdf page object
777
+ * @param annotationPtr - pointer to pdf annotation
778
+ * @param index - index of annotation in the pdf page
779
+ * @returns pdf circle annotation
780
+ *
781
+ * @private
782
+ */
783
+ private readPdfCircleAnno;
784
+ /**
785
+ * Read square annotation
786
+ * @param page - pdf page infor
787
+ * @param pagePtr - pointer to pdf page object
788
+ * @param annotationPtr - pointer to pdf annotation
789
+ * @param index - index of annotation in the pdf page
790
+ * @returns pdf square annotation
791
+ *
792
+ * @private
793
+ */
794
+ private readPdfSquareAnno;
795
+ /**
796
+ * Read basic info of unsupported pdf annotation
797
+ * @param page - pdf page infor
798
+ * @param pagePtr - pointer to pdf page object
799
+ * @param type - type of annotation
800
+ * @param annotationPtr - pointer to pdf annotation
801
+ * @param index - index of annotation in the pdf page
802
+ * @returns pdf annotation
803
+ *
804
+ * @private
805
+ */
806
+ private readPdfAnno;
807
+ /**
808
+ * Resolve `/IRT` → parent-annotation index on the same page.
809
+ *
810
+ * @param pagePtr - pointer to FPDF_PAGE
811
+ * @param annotationPtr - pointer to FPDF_ANNOTATION
812
+ * @returns index (`0…count-1`) or `undefined` when the annotation is *not* a reply
813
+ *
814
+ * @private
815
+ */
816
+ private getInReplyToId;
817
+ /**
818
+ * Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
819
+ *
820
+ * Returns `undefined` if the input is malformed.
821
+ *
822
+ * @private
823
+ */
824
+ private toIsoDate;
825
+ /**
826
+ * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
827
+ *
828
+ * @returns decoded UTF-8 string or `undefined` when the key is absent
829
+ *
830
+ * @private
831
+ */
832
+ private getAnnotString;
833
+ /**
834
+ * Read linked popup of pdf annotation
835
+ * @param page - pdf page infor
836
+ * @param pagePtr - pointer to pdf page object
837
+ * @param annotationPtr - pointer to pdf annotation
838
+ * @param index - index of annotation in the pdf page
839
+ * @returns pdf popup linked to annotation
840
+ *
841
+ * @private
842
+ */
843
+ private readPdfAnnoLinkedPopup;
844
+ /**
845
+ * Read vertices of pdf annotation
846
+ * @param page - pdf page infor
847
+ * @param pagePtr - pointer to pdf page object
848
+ * @param annotationPtr - pointer to pdf annotation
849
+ * @returns vertices of pdf annotation
850
+ *
851
+ * @private
852
+ */
853
+ private readPdfAnnoVertices;
854
+ /**
855
+ * Read the target of pdf bookmark
856
+ * @param docPtr - pointer to pdf document object
857
+ * @param getActionPtr - callback function to retrive the pointer of action
858
+ * @param getDestinationPtr - callback function to retrive the pointer of destination
859
+ * @returns target of pdf bookmark
860
+ *
861
+ * @private
862
+ */
863
+ private readPdfBookmarkTarget;
864
+ /**
865
+ * Read field of pdf widget annotation
866
+ * @param formHandle - form handle
867
+ * @param annotationPtr - pointer to pdf annotation
868
+ * @returns field of pdf widget annotation
869
+ *
870
+ * @private
871
+ */
872
+ private readPdfWidgetAnnoField;
873
+ /**
874
+ * render rectangle of pdf page to image
875
+ * @param docPtr - pointer to pdf document object
876
+ * @param page - pdf page infor
877
+ * @param rect - rectangle info
878
+ * @param scaleFactor - factor of scalling
879
+ * @param rotation - rotation angle
880
+ * @param options - render options
881
+ * @returns image data
882
+ *
883
+ * @private
884
+ */
885
+ private renderPageRectToImageData;
886
+ /**
887
+ * Read the target of pdf link annotation
888
+ * @param docPtr - pointer to pdf document object
889
+ * @param getActionPtr - callback function to retrive the pointer of action
890
+ * @param getDestinationPtr - callback function to retrive the pointer of destination
891
+ * @returns target of link
892
+ *
893
+ * @private
894
+ */
895
+ private readPdfLinkAnnoTarget;
896
+ /**
897
+ * Read pdf action from pdf document
898
+ * @param docPtr - pointer to pdf document object
899
+ * @param actionPtr - pointer to pdf action object
900
+ * @returns pdf action object
901
+ *
902
+ * @private
903
+ */
904
+ private readPdfAction;
905
+ /**
906
+ * Read pdf destination object
907
+ * @param docPtr - pointer to pdf document object
908
+ * @param destinationPtr - pointer to pdf destination
909
+ * @returns pdf destination object
910
+ *
911
+ * @private
912
+ */
913
+ private readPdfDestination;
914
+ /**
915
+ * Read attachmet from pdf document
916
+ * @param docPtr - pointer to pdf document object
917
+ * @param index - index of attachment
918
+ * @returns attachment content
919
+ *
920
+ * @private
921
+ */
922
+ private readPdfAttachment;
923
+ /**
924
+ * Convert coordinate of point from device coordinate to page coordinate
925
+ * @param page - pdf page infor
926
+ * @param position - position of point
927
+ * @returns converted position
928
+ *
929
+ * @private
930
+ */
931
+ private convertDevicePointToPagePoint;
932
+ /**
933
+ * Convert coordinate of point from page coordinate to device coordinate
934
+ * @param page - pdf page infor
935
+ * @param position - position of point
936
+ * @returns converted position
937
+ *
938
+ * @private
939
+ */
940
+ private convertPagePointToDevicePoint;
941
+ /**
942
+ * Convert coordinate of rectangle from page coordinate to device coordinate
943
+ * @param page - pdf page infor
944
+ * @param pagePtr - pointer to pdf page object
945
+ * @param pageRect - rectangle that needs to be converted
946
+ * @returns converted rectangle
947
+ *
948
+ * @private
949
+ */
950
+ private convertPageRectToDeviceRect;
951
+ /**
952
+ * Read the appearance stream of annotation
953
+ * @param annotationPtr - pointer to pdf annotation
954
+ * @param mode - appearance mode
955
+ * @returns appearance stream
956
+ *
957
+ * @private
958
+ */
959
+ private readPageAnnoAppearanceStreams;
960
+ /**
961
+ * Read the appearance stream of annotation
962
+ * @param annotationPtr - pointer to pdf annotation
963
+ * @param mode - appearance mode
964
+ * @returns appearance stream
965
+ *
966
+ * @private
967
+ */
968
+ private readPageAnnoAppearanceStream;
969
+ /**
970
+ * Set the rect of specified annotation
971
+ * @param page - page info that the annotation is belonged to
972
+ * @param pagePtr - pointer of page object
973
+ * @param annotationPtr - pointer to annotation object
974
+ * @param rect - target rectangle
975
+ * @returns whether the rect is setted
976
+ *
977
+ * @private
978
+ */
979
+ setPageAnnoRect(page: PdfPageObject, pagePtr: number, annotationPtr: number, rect: Rect): boolean;
980
+ /**
981
+ * Read the rectangle of annotation
982
+ * @param annotationPtr - pointer to pdf annotation
983
+ * @returns rectangle of annotation
984
+ *
985
+ * @private
986
+ */
987
+ private readPageAnnoRect;
988
+ /**
989
+ * Get highlight rects for a specific character range (for search highlighting)
990
+ * @param page - pdf page info
991
+ * @param pagePtr - pointer to pdf page
992
+ * @param textPagePtr - pointer to pdf text page
993
+ * @param startIndex - starting character index
994
+ * @param charCount - number of characters in the range
995
+ * @returns array of rectangles for highlighting the specified character range
996
+ *
997
+ * @private
998
+ */
999
+ private getHighlightRects;
1000
+ /**
1001
+ * Search for a keyword across all pages in the document
1002
+ * Returns all search results throughout the entire document
1003
+ *
1004
+ * @param doc - Pdf document object
1005
+ * @param keyword - Search keyword
1006
+ * @param flags - Match flags for search
1007
+ * @returns Promise of all search results in the document
1008
+ *
1009
+ * @public
1010
+ */
1011
+ searchAllPages(doc: PdfDocumentObject, keyword: string, flags?: MatchFlag[]): Task<SearchAllPagesResult, PdfErrorReason>;
1012
+ /**
1013
+ * Extract word-aligned context for a search hit.
1014
+ *
1015
+ * @param fullText full UTF-16 page text (fetch this once per page!)
1016
+ * @param start index of 1st char that matched
1017
+ * @param count number of chars in the match
1018
+ * @param windowChars minimum context chars to keep left & right
1019
+ */
1020
+ private buildContext;
1021
+ /**
1022
+ * Tidy the text to remove any non-printable characters and whitespace
1023
+ * @param s - text to tidy
1024
+ * @returns tidied text
1025
+ *
1026
+ * @private
1027
+ */
1028
+ private tidy;
1029
+ /**
1030
+ * Search for all occurrences of a keyword on a single page
1031
+ * This method efficiently loads the page only once and finds all matches
1032
+ *
1033
+ * @param docPtr - pointer to pdf document
1034
+ * @param page - pdf page object
1035
+ * @param pageIndex - index of the page
1036
+ * @param keywordPtr - pointer to the search keyword
1037
+ * @param flag - search flags
1038
+ * @returns array of search results on this page
1039
+ *
1040
+ * @private
1041
+ */
1042
+ private searchAllInPage;
1043
+ }
1044
+
1045
+ /**
1046
+ * Read string from WASM heap
1047
+ * @param wasmModule - pdfium wasm module instance
1048
+ * @param readChars - function to read chars
1049
+ * @param parseChars - function to parse chars
1050
+ * @param defaultLength - default length of chars that needs to read
1051
+ * @returns string from the heap
1052
+ *
1053
+ * @public
1054
+ */
1055
+ declare function readString(wasmModule: PdfiumRuntimeMethods & PdfiumModule, readChars: (buffer: number, bufferLength: number) => number, parseChars: (buffer: number) => string, defaultLength?: number): string;
1056
+ /**
1057
+ * Read arraybyffer from WASM heap
1058
+ * @param wasmModule - pdfium wasm module instance
1059
+ * @param readChars - function to read chars
1060
+ * @returns arraybuffer from the heap
1061
+ *
1062
+ * @public
1063
+ */
1064
+ declare function readArrayBuffer(wasmModule: PdfiumRuntimeMethods & PdfiumModule, readChars: (buffer: number, bufferLength: number) => number): ArrayBuffer;
1065
+
1066
+ /**
1067
+ * Request body that represent method calls of PdfEngine, it contains the
1068
+ * method name and arguments
1069
+ */
1070
+ type PdfEngineMethodRequestBody = {
1071
+ [P in PdfEngineMethodName]: {
1072
+ name: P;
1073
+ args: PdfEngineMethodArgs<P>;
1074
+ };
1075
+ }[PdfEngineMethodName];
1076
+ /**
1077
+ * Response body that represent return value of PdfEngine
1078
+ */
1079
+ type PdfEngineMethodResponseBody = {
1080
+ [P in PdfEngineMethodName]: TaskReturn<PdfEngineMethodReturnType<P>>;
1081
+ }[PdfEngineMethodName];
1082
+ /**
1083
+ * Request that abort the specified task
1084
+ */
1085
+ interface AbortRequest {
1086
+ /**
1087
+ * message id
1088
+ */
1089
+ id: string;
1090
+ /**
1091
+ * request type
1092
+ */
1093
+ type: 'AbortRequest';
1094
+ }
1095
+ /**
1096
+ * Request that execute pdf engine method
1097
+ */
1098
+ interface ExecuteRequest {
1099
+ /**
1100
+ * message id
1101
+ */
1102
+ id: string;
1103
+ /**
1104
+ * request type
1105
+ */
1106
+ type: 'ExecuteRequest';
1107
+ /**
1108
+ * request body
1109
+ */
1110
+ data: PdfEngineMethodRequestBody;
1111
+ }
1112
+ /**
1113
+ * Response that execute pdf engine method
1114
+ */
1115
+ interface ExecuteResponse {
1116
+ /**
1117
+ * message id
1118
+ */
1119
+ id: string;
1120
+ /**
1121
+ * response type
1122
+ */
1123
+ type: 'ExecuteResponse';
1124
+ /**
1125
+ * response body
1126
+ */
1127
+ data: PdfEngineMethodResponseBody;
1128
+ }
1129
+ /**
1130
+ * Response that indicate engine is ready
1131
+ */
1132
+ interface ReadyResponse {
1133
+ /**
1134
+ * message id
1135
+ */
1136
+ id: string;
1137
+ /**
1138
+ * response type
1139
+ */
1140
+ type: 'ReadyResponse';
1141
+ }
1142
+ /**
1143
+ * Request type
1144
+ */
1145
+ type Request = ExecuteRequest | AbortRequest;
1146
+ /**
1147
+ * Response type
1148
+ */
1149
+ type Response = ExecuteResponse | ReadyResponse;
1150
+ /**
1151
+ * Pdf engine runner, it will execute pdf engine based on the request it received and
1152
+ * send back the response with post message
1153
+ */
1154
+ declare class EngineRunner {
1155
+ logger: Logger;
1156
+ engine: PdfEngine | undefined;
1157
+ /**
1158
+ * Create instance of EngineRunnder
1159
+ * @param logger - logger instance
1160
+ */
1161
+ constructor(logger?: Logger);
1162
+ /**
1163
+ * Listening on post message
1164
+ */
1165
+ listen(): void;
1166
+ /**
1167
+ * Handle post message
1168
+ */
1169
+ handle(evt: MessageEvent<Request>): void;
1170
+ /**
1171
+ * Send the ready response when pdf engine is ready
1172
+ * @returns
1173
+ *
1174
+ * @protected
1175
+ */
1176
+ ready(): void;
1177
+ /**
1178
+ * Execute the request
1179
+ * @param request - request that represent the pdf engine call
1180
+ * @returns
1181
+ *
1182
+ * @protected
1183
+ */
1184
+ execute: (request: ExecuteRequest) => void;
1185
+ /**
1186
+ * Send back the response
1187
+ * @param response - response that needs sent back
1188
+ *
1189
+ * @protected
1190
+ */
1191
+ respond(response: Response): void;
1192
+ }
1193
+
1194
+ /**
1195
+ * EngineRunner for pdfium-based wasm engine
1196
+ */
1197
+ declare class PdfiumEngineRunner extends EngineRunner {
1198
+ private wasmBinary;
1199
+ /**
1200
+ * Create an instance of PdfiumEngineRunner
1201
+ * @param wasmBinary - wasm binary that contains the pdfium wasm file
1202
+ */
1203
+ constructor(wasmBinary: ArrayBuffer);
1204
+ /**
1205
+ * Initialize runner
1206
+ */
1207
+ prepare(): Promise<void>;
1208
+ }
1209
+
1210
+ /**
1211
+ * Task that executed by webworker
1212
+ */
1213
+ declare class WorkerTask<R> extends Task<R, PdfErrorReason> {
1214
+ worker: Worker;
1215
+ private messageId;
1216
+ /**
1217
+ * Create a task that bind to web worker with specified message id
1218
+ * @param worker - web worker instance
1219
+ * @param messageId - id of message
1220
+ *
1221
+ * @public
1222
+ */
1223
+ constructor(worker: Worker, messageId: string);
1224
+ /**
1225
+ * {@inheritDoc @embedpdf/models!Task.abort}
1226
+ *
1227
+ * @override
1228
+ */
1229
+ abort(e: PdfErrorReason): void;
1230
+ }
1231
+ /**
1232
+ * PDF engine that runs within webworker
1233
+ */
1234
+ declare class WebWorkerEngine implements PdfEngine {
1235
+ private worker;
1236
+ private logger;
1237
+ static readyTaskId: string;
1238
+ /**
1239
+ * Task that represent the state of preparation
1240
+ */
1241
+ readyTask: WorkerTask<boolean>;
1242
+ /**
1243
+ * All the tasks that is executing
1244
+ */
1245
+ tasks: Map<string, WorkerTask<any>>;
1246
+ /**
1247
+ * Create an instance of WebWorkerEngine, it will create a worker with
1248
+ * specified url.
1249
+ * @param worker - webworker instance, this worker needs to contains the running instance of {@link EngineRunner}
1250
+ * @param logger - logger instance
1251
+ *
1252
+ * @public
1253
+ */
1254
+ constructor(worker: Worker, logger?: Logger);
1255
+ /**
1256
+ * Handle event from web worker. There are 2 kinds of event
1257
+ * 1. ReadyResponse: web worker is ready
1258
+ * 2. ExecuteResponse: result of execution
1259
+ * @param evt - message event from web worker
1260
+ * @returns
1261
+ *
1262
+ * @private
1263
+ */
1264
+ handle: (evt: MessageEvent<any>) => void;
1265
+ /**
1266
+ * Generate a unique message id
1267
+ * @returns message id
1268
+ *
1269
+ * @private
1270
+ */
1271
+ generateRequestId(id: string): string;
1272
+ /**
1273
+ * {@inheritDoc @embedpdf/models!PdfEngine.initialize}
1274
+ *
1275
+ * @public
1276
+ */
1277
+ initialize(): WorkerTask<boolean>;
1278
+ /**
1279
+ * {@inheritDoc @embedpdf/models!PdfEngine.destroy}
1280
+ *
1281
+ * @public
1282
+ */
1283
+ destroy(): WorkerTask<boolean>;
1284
+ /**
1285
+ * {@inheritDoc @embedpdf/models!PdfEngine.openDocumentUrl}
1286
+ *
1287
+ * @public
1288
+ */
1289
+ openDocumentUrl(file: PdfFileUrl, options?: PdfUrlOptions): WorkerTask<PdfDocumentObject>;
1290
+ /**
1291
+ * {@inheritDoc @embedpdf/models!PdfEngine.openDocument}
1292
+ *
1293
+ * @public
1294
+ */
1295
+ openDocumentFromBuffer(file: PdfFile, password: string): WorkerTask<PdfDocumentObject>;
1296
+ /**
1297
+ * {@inheritDoc @embedpdf/models!PdfEngine.openDocumentFromLoader}
1298
+ *
1299
+ * @public
1300
+ */
1301
+ openDocumentFromLoader(file: PdfFileLoader, password: string): WorkerTask<PdfDocumentObject>;
1302
+ /**
1303
+ * {@inheritDoc @embedpdf/models!PdfEngine.getMetadata}
1304
+ *
1305
+ * @public
1306
+ */
1307
+ getMetadata(doc: PdfDocumentObject): WorkerTask<PdfMetadataObject>;
1308
+ /**
1309
+ * {@inheritDoc @embedpdf/models!PdfEngine.getDocPermissions}
1310
+ *
1311
+ * @public
1312
+ */
1313
+ getDocPermissions(doc: PdfDocumentObject): WorkerTask<number>;
1314
+ /**
1315
+ * {@inheritDoc @embedpdf/models!PdfEngine.getDocUserPermissions}
1316
+ *
1317
+ * @public
1318
+ */
1319
+ getDocUserPermissions(doc: PdfDocumentObject): WorkerTask<number>;
1320
+ /**
1321
+ * {@inheritDoc @embedpdf/models!PdfEngine.getBookmarks}
1322
+ *
1323
+ * @public
1324
+ */
1325
+ getBookmarks(doc: PdfDocumentObject): WorkerTask<PdfBookmarksObject>;
1326
+ /**
1327
+ * {@inheritDoc @embedpdf/models!PdfEngine.getSignatures}
1328
+ *
1329
+ * @public
1330
+ */
1331
+ getSignatures(doc: PdfDocumentObject): WorkerTask<PdfSignatureObject[]>;
1332
+ /**
1333
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderPage}
1334
+ *
1335
+ * @public
1336
+ */
1337
+ renderPage(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation, dpr: number, options: PdfRenderOptions): WorkerTask<Blob>;
1338
+ /**
1339
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderPageRect}
1340
+ *
1341
+ * @public
1342
+ */
1343
+ renderPageRect(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation, dpr: number, rect: Rect, options: PdfRenderOptions): WorkerTask<Blob>;
1344
+ /**
1345
+ * {@inheritDoc @embedpdf/models!PdfEngine.getAllAnnotations}
1346
+ *
1347
+ * @public
1348
+ */
1349
+ getAllAnnotations(doc: PdfDocumentObject): WorkerTask<Record<number, PdfAnnotationObject[]>>;
1350
+ /**
1351
+ * {@inheritDoc @embedpdf/models!PdfEngine.getPageAnnotations}
1352
+ *
1353
+ * @public
1354
+ */
1355
+ getPageAnnotations(doc: PdfDocumentObject, page: PdfPageObject): WorkerTask<PdfAnnotationObject[]>;
1356
+ /**
1357
+ * {@inheritDoc @embedpdf/models!PdfEngine.createPageAnnotation}
1358
+ *
1359
+ * @public
1360
+ */
1361
+ createPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): WorkerTask<boolean>;
1362
+ /**
1363
+ * {@inheritDoc @embedpdf/models!PdfEngine.transformPageAnnotation}
1364
+ *
1365
+ * @public
1366
+ */
1367
+ transformPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject, transformation: PdfAnnotationTransformation): WorkerTask<boolean>;
1368
+ /**
1369
+ * {@inheritDoc @embedpdf/models!PdfEngine.removePageAnnotation}
1370
+ *
1371
+ * @public
1372
+ */
1373
+ removePageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): WorkerTask<boolean>;
1374
+ /**
1375
+ * {@inheritDoc @embedpdf/models!PdfEngine.getPageTextRects}
1376
+ *
1377
+ * @public
1378
+ */
1379
+ getPageTextRects(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation): WorkerTask<PdfTextRectObject[]>;
1380
+ /**
1381
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderThumbnail}
1382
+ *
1383
+ * @public
1384
+ */
1385
+ renderThumbnail(doc: PdfDocumentObject, page: PdfPageObject, scaleFactor: number, rotation: Rotation, dpr: number): WorkerTask<Blob>;
1386
+ /**
1387
+ * {@inheritDoc @embedpdf/models!PdfEngine.searchAllPages}
1388
+ *
1389
+ * @public
1390
+ */
1391
+ searchAllPages(doc: PdfDocumentObject, keyword: string, flags?: MatchFlag[]): WorkerTask<SearchAllPagesResult>;
1392
+ /**
1393
+ * {@inheritDoc @embedpdf/models!PdfEngine.saveAsCopy}
1394
+ *
1395
+ * @public
1396
+ */
1397
+ saveAsCopy(doc: PdfDocumentObject): WorkerTask<ArrayBuffer>;
1398
+ /**
1399
+ * {@inheritDoc @embedpdf/models!PdfEngine.getAttachments}
1400
+ *
1401
+ * @public
1402
+ */
1403
+ getAttachments(doc: PdfDocumentObject): WorkerTask<PdfAttachmentObject[]>;
1404
+ /**
1405
+ * {@inheritDoc @embedpdf/models!PdfEngine.readAttachmentContent}
1406
+ *
1407
+ * @public
1408
+ */
1409
+ readAttachmentContent(doc: PdfDocumentObject, attachment: PdfAttachmentObject): WorkerTask<ArrayBuffer>;
1410
+ /**
1411
+ * {@inheritDoc @embedpdf/models!PdfEngine.setFormFieldValue}
1412
+ *
1413
+ * @public
1414
+ */
1415
+ setFormFieldValue(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfWidgetAnnoObject, value: FormFieldValue): WorkerTask<boolean>;
1416
+ /**
1417
+ * {@inheritDoc @embedpdf/models!PdfEngine.flattenPage}
1418
+ *
1419
+ * @public
1420
+ */
1421
+ flattenPage(doc: PdfDocumentObject, page: PdfPageObject, flag: PdfPageFlattenFlag): WorkerTask<PdfPageFlattenResult>;
1422
+ /**
1423
+ * {@inheritDoc @embedpdf/models!PdfEngine.extractPages}
1424
+ *
1425
+ * @public
1426
+ */
1427
+ extractPages(doc: PdfDocumentObject, pageIndexes: number[]): WorkerTask<ArrayBuffer>;
1428
+ /**
1429
+ * {@inheritDoc @embedpdf/models!PdfEngine.extractText}
1430
+ *
1431
+ * @public
1432
+ */
1433
+ extractText(doc: PdfDocumentObject, pageIndexes: number[]): WorkerTask<string>;
1434
+ /**
1435
+ * {@inheritDoc @embedpdf/models!PdfEngine.getPageGlyphs}
1436
+ *
1437
+ * @public
1438
+ */
1439
+ getPageGlyphs(doc: PdfDocumentObject, page: PdfPageObject): WorkerTask<PdfGlyphObject[]>;
1440
+ /**
1441
+ * {@inheritDoc @embedpdf/models!PdfEngine.getPageGeometry}
1442
+ *
1443
+ * @public
1444
+ */
1445
+ getPageGeometry(doc: PdfDocumentObject, page: PdfPageObject): WorkerTask<PdfPageGeometry>;
1446
+ /**
1447
+ * {@inheritDoc @embedpdf/models!PdfEngine.merge}
1448
+ *
1449
+ * @public
1450
+ */
1451
+ merge(files: PdfFile[]): WorkerTask<PdfFile>;
1452
+ /**
1453
+ * {@inheritDoc @embedpdf/models!PdfEngine.mergePages}
1454
+ *
1455
+ * @public
1456
+ */
1457
+ mergePages(mergeConfigs: Array<{
1458
+ docId: string;
1459
+ pageIndices: number[];
1460
+ }>): WorkerTask<PdfFile>;
1461
+ /**
1462
+ * {@inheritDoc @embedpdf/models!PdfEngine.closeDocument}
1463
+ *
1464
+ * @public
1465
+ */
1466
+ closeDocument(doc: PdfDocumentObject): WorkerTask<boolean>;
1467
+ /**
1468
+ * Send the request to webworker inside and register the task
1469
+ * @param task - task that waiting for the response
1470
+ * @param request - request that needs send to web worker
1471
+ * @param transferables - transferables that need to transfer to webworker
1472
+ * @returns
1473
+ *
1474
+ * @internal
1475
+ */
1476
+ proxy<R>(task: WorkerTask<R>, request: ExecuteRequest, transferables?: any[]): void;
1477
+ }
6
1478
 
7
1479
  /**
8
1480
  * Create mock of pdf engine
@@ -29,4 +1501,5 @@ declare function createMockPdfDocument(doc?: Partial<PdfDocumentObject>): PdfDoc
29
1501
  */
30
1502
  declare function createMockPdfFile(file?: Partial<PdfFile>): PdfFile;
31
1503
 
32
- export { createMockPdfDocument, createMockPdfEngine, createMockPdfFile };
1504
+ export { BitmapFormat, EngineRunner, PdfiumEngine, PdfiumEngineRunner, PdfiumErrorCode, RenderFlag, WebWorkerEngine, WorkerTask, browserImageDataToBlobConverter, createMockPdfDocument, createMockPdfEngine, createMockPdfFile, readArrayBuffer, readString };
1505
+ export type { AbortRequest, ExecuteRequest, ExecuteResponse, ImageDataConverter, PdfEngineMethodRequestBody, PdfEngineMethodResponseBody, ReadyResponse, Request, Response, SearchContext };