@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.
package/dist/pdfium.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SearchTarget, PdfImage, ImageConversionTypes, PdfEngine, Logger, Task, PdfErrorReason, PdfFileUrl, PdfUrlOptions, PdfDocumentObject, PdfFile, PdfFileLoader, PdfSignatureObject, PdfBookmarkObject, PdfPageObject, Rotation, PdfRenderOptions, PdfTask, Rect, PdfAnnotationObject, PdfAnnotationTransformation, PdfTextRectObject, PdfAttachmentObject, PdfWidgetAnnoObject, FormFieldValue, PdfPageFlattenFlag, PdfPageFlattenResult, PageTextSlice, PdfInkListObject, PdfStampAnnoObjectContents, Position, PdfPageGeometry, PdfGlyphObject, MatchFlag, SearchAllPagesResult, PdfEngineMethodName, PdfEngineMethodArgs, TaskReturn, PdfEngineMethodReturnType } from '@embedpdf/models';
1
+ import { SearchTarget, PdfImage, ImageConversionTypes, PdfEngine, Logger, Task, PdfErrorReason, PdfFileUrl, PdfUrlOptions, PdfDocumentObject, PdfFile, PdfFileLoader, PdfSignatureObject, PdfBookmarkObject, PdfPageObject, Rotation, PdfRenderOptions, PdfTask, Rect, PdfAnnotationObject, PdfTextRectObject, PdfAttachmentObject, PdfWidgetAnnoObject, FormFieldValue, PdfPageFlattenFlag, PdfPageFlattenResult, PageTextSlice, PdfInkAnnoObject, PdfHighlightAnnoObject, PdfUnderlineAnnoObject, PdfStrikeOutAnnoObject, PdfSquigglyAnnoObject, PdfStampAnnoObjectContents, Position, PdfPageGeometry, PdfGlyphObject, AppearanceMode, PdfAnnotationObjectBase, WebAlphaColor, MatchFlag, SearchAllPagesResult, PdfEngineMethodName, PdfEngineMethodArgs, TaskReturn, PdfEngineMethodReturnType } from '@embedpdf/models';
2
2
  import { WrappedPdfiumModule, PdfiumRuntimeMethods, PdfiumModule } from '@embedpdf/pdfium';
3
3
 
4
4
  /**
@@ -208,13 +208,17 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
208
208
  *
209
209
  * @public
210
210
  */
211
- createPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
211
+ createPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): PdfTask<number>;
212
212
  /**
213
- * {@inheritDoc @embedpdf/models!PdfEngine.transformPageAnnotation}
213
+ * Update an existing page annotation in-place
214
214
  *
215
- * @public
215
+ * Locates the annot by page-local index (`annotation.id`)
216
+ * • Re-writes its /Rect and type-specific payload
217
+ * • Calls FPDFPage_GenerateContent so the new appearance is rendered
218
+ *
219
+ * @returns PdfTask<boolean> – true on success
216
220
  */
217
- transformPageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject, transformation: PdfAnnotationTransformation): Task<boolean, PdfErrorReason> | Task<any, PdfErrorReason>;
221
+ updatePageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): PdfTask<boolean>;
218
222
  /**
219
223
  * {@inheritDoc @embedpdf/models!PdfEngine.removePageAnnotation}
220
224
  *
@@ -329,7 +333,17 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
329
333
  *
330
334
  * @private
331
335
  */
332
- addInkStroke(page: PdfPageObject, pagePtr: number, annotationPtr: number, inkList: PdfInkListObject[]): boolean;
336
+ addInkStroke(page: PdfPageObject, pagePtr: number, annotationPtr: number, annotation: PdfInkAnnoObject): boolean;
337
+ /**
338
+ * Add highlight content to annotation
339
+ * @param page - page info
340
+ * @param annotationPtr - pointer to highlight annotation
341
+ * @param annotation - highlight annotation
342
+ * @returns whether highlight content is added to annotation
343
+ *
344
+ * @private
345
+ */
346
+ addTextMarkupContent(page: PdfPageObject, pagePtr: number, annotationPtr: number, annotation: PdfHighlightAnnoObject | PdfUnderlineAnnoObject | PdfStrikeOutAnnoObject | PdfSquigglyAnnoObject): boolean;
333
347
  /**
334
348
  * Add contents to stamp annotation
335
349
  * @param docPtr - pointer to pdf document object
@@ -486,62 +500,84 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
486
500
  */
487
501
  private readAnnotationColor;
488
502
  /**
489
- * Extract the fill (or, if absent, the stroke) colour from a **path object**
490
- * inside an appearance stream.
503
+ * Resolve the visible fill colour for **Highlight / Underline / StrikeOut /
504
+ * Squiggly** markup annotations.
491
505
  *
492
- * Works for simple highlights produced by Chrome, Preview, etc. that paint a
493
- * single filled rectangle with the desired tint.
506
+ * Resolution order (first non-`undefined` wins):
507
+ * 1. `/C` dictionary entry fast, present in Acrobat / Office PDFs
508
+ * 2. Appearance-stream objects – drills into paths & nested forms
509
+ * 3. Hard-coded fallback (Acrobat-style opaque yellow)
494
510
  *
495
- * @param pathPtr - pointer to a `FPDF_PAGEOBJECT` of type **PATH**
496
- * @returns RGBA tuple or `undefined` when no colour is set on the path
511
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
512
+ * @param fallback - colour to use when the PDF stores no tint at all
513
+ * @returns WebAlphaColor with hex color and opacity (0-1)
497
514
  *
498
515
  * @private
499
516
  */
500
- private getColorFromPath;
517
+ private resolveAnnotationColor;
501
518
  /**
502
- * Recursively walk a page-object tree (PATHs and nested FORM XObjects) until
503
- * a colour can be extracted.
504
- *
505
- * Acrobat often wraps its highlight rectangle in a Form XObject referenced by
506
- * the "Do" operator, so this function drills down unlimited depth.
519
+ * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
507
520
  *
508
- * @param objPtr - pointer to a `FPDF_PAGEOBJECT`
509
- * @returns First RGBA tint found, or `undefined` if none of the descendants
510
- * carry an explicit fill/stroke colour
521
+ * @param annotationPtr - pointer to the annotation whose colour is being set
522
+ * @param webAlphaColor - WebAlphaColor with hex color and opacity (0-1)
523
+ * @param shouldClearAP - whether to clear the /AP entry
524
+ * @param which - which colour to set (0 = fill, 1 = stroke)
525
+ * @returns `true` if the operation was successful
511
526
  *
512
527
  * @private
513
528
  */
514
- private walkPageObjTree;
529
+ private setAnnotationColor;
515
530
  /**
516
- * Iterate over every top-level object in the annotation's **appearance stream**
517
- * and invoke {@link walkPageObjTree} to locate a usable tint.
531
+ * Border‐style + width helper
518
532
  *
519
- * Catches:
520
- * Simple filled path (Preview, Chrome)
521
- * • Form XObject containing the path (Acrobat)
533
+ * Tries the new PDFium helper `EPDFAnnot_GetBorderStyle()` (patch series
534
+ * 9 July 2025).
522
535
  *
523
- * @param annotPtr - pointer to an `FPDF_ANNOTATION`
524
- * @returns RGBA tuple or `undefined` when no colour can be resolved from AP
536
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
537
+ * @returns `{ ok, style, width }`
538
+ * • `ok` – `true` when the call succeeded
539
+ * • `style` – `PdfAnnotationBorderStyle` enum
540
+ * • `width` – stroke-width in points (defaults to 0 pt)
541
+ */
542
+ private getBorderStyle;
543
+ private setBorderStyle;
544
+ /**
545
+ * Border-effect (“cloudy”) helper
525
546
  *
526
- * @private
547
+ * Calls the new PDFium function `EPDFAnnot_GetBorderEffect()` (July 2025).
548
+ *
549
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
550
+ * @returns `{ ok, intensity }`
551
+ * • `ok` – `true` when the annotation *does* have a
552
+ * valid cloudy-border effect
553
+ * • `intensity` – radius/intensity value (0 when `ok` is false)
527
554
  */
528
- private colorFromAppearance;
555
+ private getBorderEffect;
529
556
  /**
530
- * Resolve the visible fill colour for **Highlight / Underline / StrikeOut /
531
- * Squiggly** markup annotations.
557
+ * Rectangle-differences helper ( /RD array on Square / Circle annots )
532
558
  *
533
- * Resolution order (first non-`undefined` wins):
534
- * 1. `/C` dictionary entry – fast, present in Acrobat / Office PDFs
535
- * 2. Appearance-stream objects – drills into paths & nested forms
536
- * 3. Hard-coded fallback (Acrobat-style opaque yellow)
559
+ * Calls `EPDFAnnot_GetRectangleDifferences()` introduced in July 2025.
537
560
  *
538
- * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
539
- * @param fallback - colour to use when the PDF stores no tint at all
540
- * @returns Guaranteed RGBA tuple (never `undefined`)
561
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
562
+ * @returns `{ ok, left, top, right, bottom }`
563
+ * `ok` – `true` when the annotation *has* an /RD entry
564
+ * • the four floats are 0 when `ok` is false
565
+ */
566
+ private getRectangleDifferences;
567
+ /**
568
+ * Dash-pattern helper ( /BS → /D array, dashed borders only )
541
569
  *
542
- * @private
570
+ * Uses the two new PDFium helpers:
571
+ * • `EPDFAnnot_GetBorderDashPatternCount`
572
+ * • `EPDFAnnot_GetBorderDashPattern`
573
+ *
574
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
575
+ * @returns `{ ok, pattern }`
576
+ * • `ok` – `true` when the annot is dashed *and* the array
577
+ * was retrieved successfully
578
+ * • `pattern` – numeric array of dash/space lengths (empty when `ok` is false)
543
579
  */
544
- private resolveAnnotationColor;
580
+ private getBorderDashPattern;
545
581
  /**
546
582
  * Read `/QuadPoints` from any annotation and convert each quadrilateral to
547
583
  * device-space coordinates.
@@ -553,11 +589,37 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
553
589
  *
554
590
  * @param page - logical page info object (`PdfPageObject`)
555
591
  * @param annotationPtr - pointer to the annotation whose quads are needed
556
- * @returns Array of `Quad` objects (`[]` if the annotation has no quads)
592
+ * @returns Array of `Rect` objects (`[]` if the annotation has no quads)
557
593
  *
558
594
  * @private
559
595
  */
560
- private readAnnotationQuads;
596
+ private getQuadPointsAnno;
597
+ /**
598
+ * Set the quadrilaterals for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
599
+ *
600
+ * @param page - logical page info object (`PdfPageObject`)
601
+ * @param annotationPtr - pointer to the annotation whose quads are needed
602
+ * @param rects - array of `Rect` objects (`[]` if the annotation has no quads)
603
+ * @returns `true` if the operation was successful
604
+ *
605
+ * @private
606
+ */
607
+ private syncQuadPointsAnno;
608
+ /**
609
+ * Read ink list from annotation
610
+ * @param page - logical page info object (`PdfPageObject`)
611
+ * @param annotationPtr - pointer to the annotation whose ink list is needed
612
+ * @returns ink list
613
+ */
614
+ private getInkList;
615
+ /**
616
+ * Add ink list to annotation
617
+ * @param page - logical page info object (`PdfPageObject`)
618
+ * @param annotationPtr - pointer to the annotation whose ink list is needed
619
+ * @param annotation - annotation object (`PdfInkAnnoObject`)
620
+ * @returns `true` if the operation was successful
621
+ */
622
+ private setInkList;
561
623
  /**
562
624
  * Read pdf text annotation
563
625
  * @param page - pdf page infor
@@ -776,6 +838,25 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
776
838
  * @private
777
839
  */
778
840
  private readPdfPageObjectTransformMatrix;
841
+ /**
842
+ * Return the stroke-width declared in the annotation’s /Border or /BS entry.
843
+ * Falls back to 1 pt when nothing is defined.
844
+ *
845
+ * @param annotationPtr - pointer to pdf annotation
846
+ * @returns stroke-width
847
+ *
848
+ * @private
849
+ */
850
+ private getStrokeWidth;
851
+ /**
852
+ * Fetches the `/F` flag bit-field from an annotation.
853
+ *
854
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
855
+ * @returns `{ raw, flags }`
856
+ * • `raw` – the 32-bit integer returned by PDFium
857
+ * • `flags` – object with individual booleans
858
+ */
859
+ private getAnnotationFlags;
779
860
  /**
780
861
  * Read circle annotation
781
862
  * @param page - pdf page infor
@@ -820,14 +901,6 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
820
901
  * @private
821
902
  */
822
903
  private getInReplyToId;
823
- /**
824
- * Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
825
- *
826
- * Returns `undefined` if the input is malformed.
827
- *
828
- * @private
829
- */
830
- private toIsoDate;
831
904
  /**
832
905
  * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
833
906
  *
@@ -837,16 +910,13 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
837
910
  */
838
911
  private getAnnotString;
839
912
  /**
840
- * Read linked popup of pdf annotation
841
- * @param page - pdf page infor
842
- * @param pagePtr - pointer to pdf page object
843
- * @param annotationPtr - pointer to pdf annotation
844
- * @param index - index of annotation in the pdf page
845
- * @returns pdf popup linked to annotation
913
+ * Set a string value (`/T`, `/M`, `/State`, …) to an annotation.
914
+ *
915
+ * @returns `true` if the operation was successful
846
916
  *
847
917
  * @private
848
918
  */
849
- private readPdfAnnoLinkedPopup;
919
+ private setAnnotString;
850
920
  /**
851
921
  * Read vertices of pdf annotation
852
922
  * @param page - pdf page infor
@@ -876,6 +946,13 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
876
946
  * @private
877
947
  */
878
948
  private readPdfWidgetAnnoField;
949
+ /**
950
+ * {@inheritDoc @embedpdf/models!PdfEngine.renderAnnotation}
951
+ *
952
+ * @public
953
+ */
954
+ renderAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject, scaleFactor: number, rotation: Rotation, dpr?: number, // device-pixel-ratio (canvas)
955
+ mode?: AppearanceMode, imageType?: ImageConversionTypes): PdfTask<T>;
879
956
  /**
880
957
  * render rectangle of pdf page to image
881
958
  * @param docPtr - pointer to pdf document object
@@ -972,6 +1049,23 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
972
1049
  * @private
973
1050
  */
974
1051
  private readPageAnnoAppearanceStream;
1052
+ /**
1053
+ * Change the visible colour (and opacity) of an existing annotation.
1054
+ *
1055
+ * For markup annotations (highlight / underline / strikeout / squiggly) we
1056
+ * first clear the AP dictionary entry, otherwise the stored appearance stream
1057
+ * will override the new tint. For all other sub-types we keep the existing
1058
+ * AP so custom artwork isn't lost.
1059
+ *
1060
+ * @param doc logical document object
1061
+ * @param page logical page object
1062
+ * @param annotation the annotation we want to recolour
1063
+ * @param colour RGBA tuple (0-255 per channel)
1064
+ * @param which 0 = stroke/fill colour (PDFium's "colourType" param)
1065
+ *
1066
+ * @returns `true` when the operation succeeded
1067
+ */
1068
+ updateAnnotationColor(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObjectBase, color: WebAlphaColor, which?: number): PdfTask<boolean>;
975
1069
  /**
976
1070
  * Set the rect of specified annotation
977
1071
  * @param page - page info that the annotation is belonged to