@embedpdf/engines 1.0.6 → 1.0.8

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,4 +1,4 @@
1
- import { PdfEngine, Logger, Task, PdfErrorReason, PdfFileUrl, PdfUrlOptions, PdfDocumentObject, PdfFile, PdfFileLoader, PdfSignatureObject, PdfBookmarkObject, PdfPageObject, Rotation, PdfRenderOptions, ImageConversionTypes, PdfTask, Rect, PdfAnnotationObject, PdfAnnotationTransformation, PdfTextRectObject, PdfAttachmentObject, PdfWidgetAnnoObject, FormFieldValue, PdfPageFlattenFlag, PdfPageFlattenResult, PageTextSlice, PdfInkListObject, PdfStampAnnoObjectContents, Position, PdfPageGeometry, PdfGlyphObject, MatchFlag, SearchAllPagesResult, PdfImage } from '@embedpdf/models';
1
+ import { PdfEngine, Logger, Task, PdfErrorReason, PdfFileUrl, PdfUrlOptions, PdfDocumentObject, PdfFile, PdfFileLoader, PdfSignatureObject, PdfBookmarkObject, PdfPageObject, Rotation, PdfRenderOptions, ImageConversionTypes, PdfTask, Rect, PdfAnnotationObject, PdfTextRectObject, PdfAttachmentObject, PdfWidgetAnnoObject, FormFieldValue, PdfPageFlattenFlag, PdfPageFlattenResult, PageTextSlice, PdfInkAnnoObject, PdfHighlightAnnoObject, PdfUnderlineAnnoObject, PdfStrikeOutAnnoObject, PdfSquigglyAnnoObject, PdfStampAnnoObjectContents, Position, PdfPageGeometry, PdfGlyphObject, AppearanceMode, PdfAnnotationObjectBase, WebAlphaColor, MatchFlag, SearchAllPagesResult, PdfImage } from '@embedpdf/models';
2
2
  import { WrappedPdfiumModule } from '@embedpdf/pdfium';
3
3
 
4
4
  /**
@@ -152,13 +152,17 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
152
152
  *
153
153
  * @public
154
154
  */
155
- createPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
155
+ createPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): PdfTask<number>;
156
156
  /**
157
- * {@inheritDoc @embedpdf/models!PdfEngine.transformPageAnnotation}
157
+ * Update an existing page annotation in-place
158
158
  *
159
- * @public
159
+ * Locates the annot by page-local index (`annotation.id`)
160
+ * • Re-writes its /Rect and type-specific payload
161
+ * • Calls FPDFPage_GenerateContent so the new appearance is rendered
162
+ *
163
+ * @returns PdfTask<boolean> – true on success
160
164
  */
161
- transformPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject, transformation: PdfAnnotationTransformation): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
165
+ updatePageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): PdfTask<boolean>;
162
166
  /**
163
167
  * {@inheritDoc @embedpdf/models!PdfEngine.removePageAnnotation}
164
168
  *
@@ -273,7 +277,17 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
273
277
  *
274
278
  * @private
275
279
  */
276
- addInkStroke(page: PdfPageObject, pagePtr: number, annotationPtr: number, inkList: PdfInkListObject[]): boolean;
280
+ addInkStroke(page: PdfPageObject, pagePtr: number, annotationPtr: number, annotation: PdfInkAnnoObject): boolean;
281
+ /**
282
+ * Add highlight content to annotation
283
+ * @param page - page info
284
+ * @param annotationPtr - pointer to highlight annotation
285
+ * @param annotation - highlight annotation
286
+ * @returns whether highlight content is added to annotation
287
+ *
288
+ * @private
289
+ */
290
+ addTextMarkupContent(page: PdfPageObject, pagePtr: number, annotationPtr: number, annotation: PdfHighlightAnnoObject | PdfUnderlineAnnoObject | PdfStrikeOutAnnoObject | PdfSquigglyAnnoObject): boolean;
277
291
  /**
278
292
  * Add contents to stamp annotation
279
293
  * @param docPtr - pointer to pdf document object
@@ -430,62 +444,84 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
430
444
  */
431
445
  private readAnnotationColor;
432
446
  /**
433
- * Extract the fill (or, if absent, the stroke) colour from a **path object**
434
- * inside an appearance stream.
447
+ * Resolve the visible fill colour for **Highlight / Underline / StrikeOut /
448
+ * Squiggly** markup annotations.
435
449
  *
436
- * Works for simple highlights produced by Chrome, Preview, etc. that paint a
437
- * single filled rectangle with the desired tint.
450
+ * Resolution order (first non-`undefined` wins):
451
+ * 1. `/C` dictionary entry fast, present in Acrobat / Office PDFs
452
+ * 2. Appearance-stream objects – drills into paths & nested forms
453
+ * 3. Hard-coded fallback (Acrobat-style opaque yellow)
438
454
  *
439
- * @param pathPtr - pointer to a `FPDF_PAGEOBJECT` of type **PATH**
440
- * @returns RGBA tuple or `undefined` when no colour is set on the path
455
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
456
+ * @param fallback - colour to use when the PDF stores no tint at all
457
+ * @returns WebAlphaColor with hex color and opacity (0-1)
441
458
  *
442
459
  * @private
443
460
  */
444
- private getColorFromPath;
461
+ private resolveAnnotationColor;
445
462
  /**
446
- * Recursively walk a page-object tree (PATHs and nested FORM XObjects) until
447
- * a colour can be extracted.
448
- *
449
- * Acrobat often wraps its highlight rectangle in a Form XObject referenced by
450
- * the "Do" operator, so this function drills down unlimited depth.
463
+ * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
451
464
  *
452
- * @param objPtr - pointer to a `FPDF_PAGEOBJECT`
453
- * @returns First RGBA tint found, or `undefined` if none of the descendants
454
- * carry an explicit fill/stroke colour
465
+ * @param annotationPtr - pointer to the annotation whose colour is being set
466
+ * @param webAlphaColor - WebAlphaColor with hex color and opacity (0-1)
467
+ * @param shouldClearAP - whether to clear the /AP entry
468
+ * @param which - which colour to set (0 = fill, 1 = stroke)
469
+ * @returns `true` if the operation was successful
455
470
  *
456
471
  * @private
457
472
  */
458
- private walkPageObjTree;
473
+ private setAnnotationColor;
459
474
  /**
460
- * Iterate over every top-level object in the annotation's **appearance stream**
461
- * and invoke {@link walkPageObjTree} to locate a usable tint.
475
+ * Border‐style + width helper
462
476
  *
463
- * Catches:
464
- * Simple filled path (Preview, Chrome)
465
- * • Form XObject containing the path (Acrobat)
477
+ * Tries the new PDFium helper `EPDFAnnot_GetBorderStyle()` (patch series
478
+ * 9 July 2025).
466
479
  *
467
- * @param annotPtr - pointer to an `FPDF_ANNOTATION`
468
- * @returns RGBA tuple or `undefined` when no colour can be resolved from AP
480
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
481
+ * @returns `{ ok, style, width }`
482
+ * • `ok` – `true` when the call succeeded
483
+ * • `style` – `PdfAnnotationBorderStyle` enum
484
+ * • `width` – stroke-width in points (defaults to 0 pt)
485
+ */
486
+ private getBorderStyle;
487
+ private setBorderStyle;
488
+ /**
489
+ * Border-effect (“cloudy”) helper
469
490
  *
470
- * @private
491
+ * Calls the new PDFium function `EPDFAnnot_GetBorderEffect()` (July 2025).
492
+ *
493
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
494
+ * @returns `{ ok, intensity }`
495
+ * • `ok` – `true` when the annotation *does* have a
496
+ * valid cloudy-border effect
497
+ * • `intensity` – radius/intensity value (0 when `ok` is false)
471
498
  */
472
- private colorFromAppearance;
499
+ private getBorderEffect;
473
500
  /**
474
- * Resolve the visible fill colour for **Highlight / Underline / StrikeOut /
475
- * Squiggly** markup annotations.
501
+ * Rectangle-differences helper ( /RD array on Square / Circle annots )
476
502
  *
477
- * Resolution order (first non-`undefined` wins):
478
- * 1. `/C` dictionary entry – fast, present in Acrobat / Office PDFs
479
- * 2. Appearance-stream objects – drills into paths & nested forms
480
- * 3. Hard-coded fallback (Acrobat-style opaque yellow)
503
+ * Calls `EPDFAnnot_GetRectangleDifferences()` introduced in July 2025.
481
504
  *
482
- * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
483
- * @param fallback - colour to use when the PDF stores no tint at all
484
- * @returns Guaranteed RGBA tuple (never `undefined`)
505
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
506
+ * @returns `{ ok, left, top, right, bottom }`
507
+ * `ok` – `true` when the annotation *has* an /RD entry
508
+ * • the four floats are 0 when `ok` is false
509
+ */
510
+ private getRectangleDifferences;
511
+ /**
512
+ * Dash-pattern helper ( /BS → /D array, dashed borders only )
485
513
  *
486
- * @private
514
+ * Uses the two new PDFium helpers:
515
+ * • `EPDFAnnot_GetBorderDashPatternCount`
516
+ * • `EPDFAnnot_GetBorderDashPattern`
517
+ *
518
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
519
+ * @returns `{ ok, pattern }`
520
+ * • `ok` – `true` when the annot is dashed *and* the array
521
+ * was retrieved successfully
522
+ * • `pattern` – numeric array of dash/space lengths (empty when `ok` is false)
487
523
  */
488
- private resolveAnnotationColor;
524
+ private getBorderDashPattern;
489
525
  /**
490
526
  * Read `/QuadPoints` from any annotation and convert each quadrilateral to
491
527
  * device-space coordinates.
@@ -497,11 +533,37 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
497
533
  *
498
534
  * @param page - logical page info object (`PdfPageObject`)
499
535
  * @param annotationPtr - pointer to the annotation whose quads are needed
500
- * @returns Array of `Quad` objects (`[]` if the annotation has no quads)
536
+ * @returns Array of `Rect` objects (`[]` if the annotation has no quads)
501
537
  *
502
538
  * @private
503
539
  */
504
- private readAnnotationQuads;
540
+ private getQuadPointsAnno;
541
+ /**
542
+ * Set the quadrilaterals for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
543
+ *
544
+ * @param page - logical page info object (`PdfPageObject`)
545
+ * @param annotationPtr - pointer to the annotation whose quads are needed
546
+ * @param rects - array of `Rect` objects (`[]` if the annotation has no quads)
547
+ * @returns `true` if the operation was successful
548
+ *
549
+ * @private
550
+ */
551
+ private syncQuadPointsAnno;
552
+ /**
553
+ * Read ink list from annotation
554
+ * @param page - logical page info object (`PdfPageObject`)
555
+ * @param annotationPtr - pointer to the annotation whose ink list is needed
556
+ * @returns ink list
557
+ */
558
+ private getInkList;
559
+ /**
560
+ * Add ink list to annotation
561
+ * @param page - logical page info object (`PdfPageObject`)
562
+ * @param annotationPtr - pointer to the annotation whose ink list is needed
563
+ * @param annotation - annotation object (`PdfInkAnnoObject`)
564
+ * @returns `true` if the operation was successful
565
+ */
566
+ private setInkList;
505
567
  /**
506
568
  * Read pdf text annotation
507
569
  * @param page - pdf page infor
@@ -720,6 +782,25 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
720
782
  * @private
721
783
  */
722
784
  private readPdfPageObjectTransformMatrix;
785
+ /**
786
+ * Return the stroke-width declared in the annotation’s /Border or /BS entry.
787
+ * Falls back to 1 pt when nothing is defined.
788
+ *
789
+ * @param annotationPtr - pointer to pdf annotation
790
+ * @returns stroke-width
791
+ *
792
+ * @private
793
+ */
794
+ private getStrokeWidth;
795
+ /**
796
+ * Fetches the `/F` flag bit-field from an annotation.
797
+ *
798
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
799
+ * @returns `{ raw, flags }`
800
+ * • `raw` – the 32-bit integer returned by PDFium
801
+ * • `flags` – object with individual booleans
802
+ */
803
+ private getAnnotationFlags;
723
804
  /**
724
805
  * Read circle annotation
725
806
  * @param page - pdf page infor
@@ -764,14 +845,6 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
764
845
  * @private
765
846
  */
766
847
  private getInReplyToId;
767
- /**
768
- * Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
769
- *
770
- * Returns `undefined` if the input is malformed.
771
- *
772
- * @private
773
- */
774
- private toIsoDate;
775
848
  /**
776
849
  * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
777
850
  *
@@ -781,16 +854,13 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
781
854
  */
782
855
  private getAnnotString;
783
856
  /**
784
- * Read linked popup of pdf annotation
785
- * @param page - pdf page infor
786
- * @param pagePtr - pointer to pdf page object
787
- * @param annotationPtr - pointer to pdf annotation
788
- * @param index - index of annotation in the pdf page
789
- * @returns pdf popup linked to annotation
857
+ * Set a string value (`/T`, `/M`, `/State`, …) to an annotation.
858
+ *
859
+ * @returns `true` if the operation was successful
790
860
  *
791
861
  * @private
792
862
  */
793
- private readPdfAnnoLinkedPopup;
863
+ private setAnnotString;
794
864
  /**
795
865
  * Read vertices of pdf annotation
796
866
  * @param page - pdf page infor
@@ -820,6 +890,13 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
820
890
  * @private
821
891
  */
822
892
  private readPdfWidgetAnnoField;
893
+ /**
894
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderAnnotation}
895
+ *
896
+ * @public
897
+ */
898
+ renderAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject, scaleFactor: number, rotation: Rotation, dpr?: number, // device-pixel-ratio (canvas)
899
+ mode?: AppearanceMode, imageType?: ImageConversionTypes): PdfTask<T>;
823
900
  /**
824
901
  * render rectangle of pdf page to image
825
902
  * @param docPtr - pointer to pdf document object
@@ -916,6 +993,23 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
916
993
  * @private
917
994
  */
918
995
  private readPageAnnoAppearanceStream;
996
+ /**
997
+ * Change the visible colour (and opacity) of an existing annotation.
998
+ *
999
+ * For markup annotations (highlight / underline / strikeout / squiggly) we
1000
+ * first clear the AP dictionary entry, otherwise the stored appearance stream
1001
+ * will override the new tint. For all other sub-types we keep the existing
1002
+ * AP so custom artwork isn't lost.
1003
+ *
1004
+ * @param doc logical document object
1005
+ * @param page logical page object
1006
+ * @param annotation the annotation we want to recolour
1007
+ * @param colour RGBA tuple (0-255 per channel)
1008
+ * @param which 0 = stroke/fill colour (PDFium's "colourType" param)
1009
+ *
1010
+ * @returns `true` when the operation succeeded
1011
+ */
1012
+ updateAnnotationColor(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObjectBase, color: WebAlphaColor, which?: number): PdfTask<boolean>;
919
1013
  /**
920
1014
  * Set the rect of specified annotation
921
1015
  * @param page - page info that the annotation is belonged to