@embedpdf/engines 1.0.5 → 1.0.7

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, 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, PdfAnnotationTransformation, PdfTextRectObject, PdfAttachmentObject, PdfWidgetAnnoObject, FormFieldValue, PdfPageFlattenFlag, PdfPageFlattenResult, PageTextSlice, PdfInkListObject, PdfHighlightAnnoObject, PdfUnderlineAnnoObject, PdfStrikeOutAnnoObject, PdfSquigglyAnnoObject, PdfStampAnnoObjectContents, Position, PdfPageGeometry, PdfGlyphObject, PdfAnnotationObjectBase, WebAlphaColor, MatchFlag, SearchAllPagesResult, PdfImage } from '@embedpdf/models';
2
2
  import { WrappedPdfiumModule } from '@embedpdf/pdfium';
3
3
 
4
4
  /**
@@ -152,7 +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
+ /**
157
+ * Update an existing page annotation in-place
158
+ *
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
164
+ */
165
+ updatePageAnnotation(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObject): PdfTask<boolean>;
156
166
  /**
157
167
  * {@inheritDoc @embedpdf/models!PdfEngine.transformPageAnnotation}
158
168
  *
@@ -213,6 +223,12 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
213
223
  * @public
214
224
  */
215
225
  extractText(doc: PdfDocumentObject, pageIndexes: number[]): Task<any, PdfErrorReason> | Task<string, PdfErrorReason>;
226
+ /**
227
+ * {@inheritDoc @embedpdf/models!PdfEngine.getTextSlices}
228
+ *
229
+ * @public
230
+ */
231
+ getTextSlices(doc: PdfDocumentObject, slices: PageTextSlice[]): PdfTask<string[]>;
216
232
  /**
217
233
  * {@inheritDoc @embedpdf/models!PdfEngine.merge}
218
234
  *
@@ -268,6 +284,16 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
268
284
  * @private
269
285
  */
270
286
  addInkStroke(page: PdfPageObject, pagePtr: number, annotationPtr: number, inkList: PdfInkListObject[]): boolean;
287
+ /**
288
+ * Add highlight content to annotation
289
+ * @param page - page info
290
+ * @param annotationPtr - pointer to highlight annotation
291
+ * @param annotation - highlight annotation
292
+ * @returns whether highlight content is added to annotation
293
+ *
294
+ * @private
295
+ */
296
+ addTextMarkupContent(page: PdfPageObject, annotationPtr: number, annotation: PdfHighlightAnnoObject | PdfUnderlineAnnoObject | PdfStrikeOutAnnoObject | PdfSquigglyAnnoObject, shouldClearAP?: boolean): boolean;
271
297
  /**
272
298
  * Add contents to stamp annotation
273
299
  * @param docPtr - pointer to pdf document object
@@ -475,11 +501,23 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
475
501
  *
476
502
  * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
477
503
  * @param fallback - colour to use when the PDF stores no tint at all
478
- * @returns Guaranteed RGBA tuple (never `undefined`)
504
+ * @returns WebAlphaColor with hex color and opacity (0-1)
479
505
  *
480
506
  * @private
481
507
  */
482
508
  private resolveAnnotationColor;
509
+ /**
510
+ * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
511
+ *
512
+ * @param annotationPtr - pointer to the annotation whose colour is being set
513
+ * @param webAlphaColor - WebAlphaColor with hex color and opacity (0-1)
514
+ * @param shouldClearAP - whether to clear the /AP entry
515
+ * @param which - which colour to set (0 = fill, 1 = stroke)
516
+ * @returns `true` if the operation was successful
517
+ *
518
+ * @private
519
+ */
520
+ private setAnnotationColor;
483
521
  /**
484
522
  * Read `/QuadPoints` from any annotation and convert each quadrilateral to
485
523
  * device-space coordinates.
@@ -491,11 +529,22 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
491
529
  *
492
530
  * @param page - logical page info object (`PdfPageObject`)
493
531
  * @param annotationPtr - pointer to the annotation whose quads are needed
494
- * @returns Array of `Quad` objects (`[]` if the annotation has no quads)
532
+ * @returns Array of `Rect` objects (`[]` if the annotation has no quads)
533
+ *
534
+ * @private
535
+ */
536
+ private getQuadPointsAnno;
537
+ /**
538
+ * Set the quadrilaterals for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
539
+ *
540
+ * @param page - logical page info object (`PdfPageObject`)
541
+ * @param annotationPtr - pointer to the annotation whose quads are needed
542
+ * @param rects - array of `Rect` objects (`[]` if the annotation has no quads)
543
+ * @returns `true` if the operation was successful
495
544
  *
496
545
  * @private
497
546
  */
498
- private readAnnotationQuads;
547
+ private syncQuadPointsAnno;
499
548
  /**
500
549
  * Read pdf text annotation
501
550
  * @param page - pdf page infor
@@ -758,14 +807,6 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
758
807
  * @private
759
808
  */
760
809
  private getInReplyToId;
761
- /**
762
- * Parse a PDF date string **D:YYYYMMDDHHmmSSOHH'mm'** to ISO-8601.
763
- *
764
- * Returns `undefined` if the input is malformed.
765
- *
766
- * @private
767
- */
768
- private toIsoDate;
769
810
  /**
770
811
  * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
771
812
  *
@@ -775,16 +816,13 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
775
816
  */
776
817
  private getAnnotString;
777
818
  /**
778
- * Read linked popup of pdf annotation
779
- * @param page - pdf page infor
780
- * @param pagePtr - pointer to pdf page object
781
- * @param annotationPtr - pointer to pdf annotation
782
- * @param index - index of annotation in the pdf page
783
- * @returns pdf popup linked to annotation
819
+ * Set a string value (`/T`, `/M`, `/State`, …) to an annotation.
820
+ *
821
+ * @returns `true` if the operation was successful
784
822
  *
785
823
  * @private
786
824
  */
787
- private readPdfAnnoLinkedPopup;
825
+ private setAnnotString;
788
826
  /**
789
827
  * Read vertices of pdf annotation
790
828
  * @param page - pdf page infor
@@ -910,6 +948,23 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
910
948
  * @private
911
949
  */
912
950
  private readPageAnnoAppearanceStream;
951
+ /**
952
+ * Change the visible colour (and opacity) of an existing annotation.
953
+ *
954
+ * For markup annotations (highlight / underline / strikeout / squiggly) we
955
+ * first clear the AP dictionary entry, otherwise the stored appearance stream
956
+ * will override the new tint. For all other sub-types we keep the existing
957
+ * AP so custom artwork isn't lost.
958
+ *
959
+ * @param doc logical document object
960
+ * @param page logical page object
961
+ * @param annotation the annotation we want to recolour
962
+ * @param colour RGBA tuple (0-255 per channel)
963
+ * @param which 0 = stroke/fill colour (PDFium's "colourType" param)
964
+ *
965
+ * @returns `true` when the operation succeeded
966
+ */
967
+ updateAnnotationColor(doc: PdfDocumentObject, page: PdfPageObject, annotation: PdfAnnotationObjectBase, color: WebAlphaColor, which?: number): PdfTask<boolean>;
913
968
  /**
914
969
  * Set the rect of specified annotation
915
970
  * @param page - page info that the annotation is belonged to
@@ -986,6 +1041,6 @@ declare class PdfiumEngine<T = Blob> implements PdfEngine<T> {
986
1041
  private searchAllInPage;
987
1042
  }
988
1043
 
989
- declare function createPdfiumEngine(wasmUrl: string): Promise<PdfiumEngine>;
1044
+ declare function createPdfiumEngine(wasmUrl: string, logger?: Logger): Promise<PdfiumEngine>;
990
1045
 
991
1046
  export { createPdfiumEngine };