@embedpdf/engines 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/{direct-engine-DGRkMlJ8.js → direct-engine-6BoAmGsC.js} +595 -417
  2. package/dist/direct-engine-6BoAmGsC.js.map +1 -0
  3. package/dist/direct-engine-Byh1BweU.cjs +2 -0
  4. package/dist/direct-engine-Byh1BweU.cjs.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +11 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/orchestrator/pdf-engine.d.ts +3 -0
  10. package/dist/lib/orchestrator/remote-executor.d.ts +3 -0
  11. package/dist/lib/pdfium/engine.d.ts +145 -0
  12. package/dist/lib/pdfium/index.cjs +1 -1
  13. package/dist/lib/pdfium/index.js +3 -3
  14. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  15. package/dist/lib/pdfium/web/direct-engine.js +2 -2
  16. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  17. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  18. package/dist/lib/pdfium/web/worker-engine.js +11 -2
  19. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  20. package/dist/lib/webworker/engine.cjs +1 -1
  21. package/dist/lib/webworker/engine.cjs.map +1 -1
  22. package/dist/lib/webworker/engine.d.ts +18 -0
  23. package/dist/lib/webworker/engine.js +47 -0
  24. package/dist/lib/webworker/engine.js.map +1 -1
  25. package/dist/{pdf-engine-DgNNP62W.cjs → pdf-engine-BXctylEz.cjs} +2 -2
  26. package/dist/{pdf-engine-DgNNP62W.cjs.map → pdf-engine-BXctylEz.cjs.map} +1 -1
  27. package/dist/{pdf-engine-ChjNHvQd.js → pdf-engine-D_Dua_6w.js} +28 -1
  28. package/dist/{pdf-engine-ChjNHvQd.js.map → pdf-engine-D_Dua_6w.js.map} +1 -1
  29. package/dist/preact/index.cjs +1 -1
  30. package/dist/preact/index.js +1 -1
  31. package/dist/react/index.cjs +1 -1
  32. package/dist/react/index.js +1 -1
  33. package/dist/svelte/index.cjs +1 -1
  34. package/dist/svelte/index.cjs.map +1 -1
  35. package/dist/svelte/index.js +1 -1
  36. package/dist/svelte/index.js.map +1 -1
  37. package/dist/vue/index.cjs +1 -1
  38. package/dist/vue/index.js +1 -1
  39. package/package.json +6 -6
  40. package/dist/direct-engine-CGBAQS04.cjs +0 -2
  41. package/dist/direct-engine-CGBAQS04.cjs.map +0 -1
  42. package/dist/direct-engine-DGRkMlJ8.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { init } from "@embedpdf/pdfium";
2
- import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
- import { P as PdfEngine } from "./pdf-engine-ChjNHvQd.js";
2
+ import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStandardFont, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
+ import { P as PdfEngine } from "./pdf-engine-D_Dua_6w.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-awZxztMA.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
6
6
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
@@ -1595,6 +1595,12 @@ class PdfiumNative {
1595
1595
  case PdfAnnotationSubtype.HIGHLIGHT:
1596
1596
  isSucceed = this.addTextMarkupContent(page, pageCtx.pagePtr, annotationPtr, annotation);
1597
1597
  break;
1598
+ case PdfAnnotationSubtype.LINK:
1599
+ isSucceed = this.addLinkContent(ctx.docPtr, pageCtx.pagePtr, annotationPtr, annotation);
1600
+ break;
1601
+ case PdfAnnotationSubtype.REDACT:
1602
+ isSucceed = this.addRedactContent(page, pageCtx.pagePtr, annotationPtr, annotation);
1603
+ break;
1598
1604
  }
1599
1605
  if (!isSucceed) {
1600
1606
  this.pdfiumModule.FPDFPage_RemoveAnnot(pageCtx.pagePtr, annotationPtr);
@@ -1735,6 +1741,16 @@ class PdfiumNative {
1735
1741
  ok = this.addTextMarkupContent(page, pageCtx.pagePtr, annotPtr, annotation);
1736
1742
  break;
1737
1743
  }
1744
+ /* ── Link ─────────────────────────────────────────────────────────────── */
1745
+ case PdfAnnotationSubtype.LINK: {
1746
+ ok = this.addLinkContent(ctx.docPtr, pageCtx.pagePtr, annotPtr, annotation);
1747
+ break;
1748
+ }
1749
+ /* ── Redact ───────────────────────────────────────────────────────────── */
1750
+ case PdfAnnotationSubtype.REDACT: {
1751
+ ok = this.addRedactContent(page, pageCtx.pagePtr, annotPtr, annotation);
1752
+ break;
1753
+ }
1738
1754
  /* ── Unsupported edits – fall through to error ───────────────────────── */
1739
1755
  default:
1740
1756
  ok = false;
@@ -2717,37 +2733,21 @@ class PdfiumNative {
2717
2733
  * @private
2718
2734
  */
2719
2735
  addTextContent(page, pagePtr, annotationPtr, annotation) {
2720
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2721
- return false;
2722
- }
2723
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2724
- return false;
2725
- }
2726
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2727
- return false;
2728
- }
2729
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2730
- return false;
2731
- }
2732
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2733
- return false;
2734
- }
2735
- if (annotation.inReplyToId && !this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)) {
2736
- return false;
2737
- }
2738
2736
  if (!this.setAnnotationIcon(annotationPtr, annotation.icon || PdfAnnotationIcon.Comment)) {
2739
2737
  return false;
2740
2738
  }
2741
- if (!this.setAnnotationFlags(annotationPtr, annotation.flags || ["print", "noZoom", "noRotate"])) {
2742
- return false;
2743
- }
2744
2739
  if (annotation.state && !this.setAnnotString(annotationPtr, "State", annotation.state)) {
2745
2740
  return false;
2746
2741
  }
2747
2742
  if (annotation.stateModel && !this.setAnnotString(annotationPtr, "StateModel", annotation.stateModel)) {
2748
2743
  return false;
2749
2744
  }
2750
- return true;
2745
+ if (!annotation.flags) {
2746
+ if (!this.setAnnotationFlags(annotationPtr, ["print", "noZoom", "noRotate"])) {
2747
+ return false;
2748
+ }
2749
+ }
2750
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2751
2751
  }
2752
2752
  /**
2753
2753
  * Add free text content to annotation
@@ -2760,27 +2760,9 @@ class PdfiumNative {
2760
2760
  * @private
2761
2761
  */
2762
2762
  addFreeTextContent(page, pagePtr, annotationPtr, annotation) {
2763
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2764
- return false;
2765
- }
2766
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2767
- return false;
2768
- }
2769
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2770
- return false;
2771
- }
2772
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2773
- return false;
2774
- }
2775
2763
  if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
2776
2764
  return false;
2777
2765
  }
2778
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2779
- return false;
2780
- }
2781
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2782
- return false;
2783
- }
2784
2766
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2785
2767
  return false;
2786
2768
  }
@@ -2801,18 +2783,15 @@ class PdfiumNative {
2801
2783
  if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
2802
2784
  return false;
2803
2785
  }
2804
- if (!annotation.backgroundColor || annotation.backgroundColor === "transparent") {
2786
+ const bgColor = annotation.color ?? annotation.backgroundColor;
2787
+ if (!bgColor || bgColor === "transparent") {
2805
2788
  if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {
2806
2789
  return false;
2807
2790
  }
2808
- } else if (!this.setAnnotationColor(
2809
- annotationPtr,
2810
- annotation.backgroundColor ?? "#FFFFFF",
2811
- PdfAnnotationColorType.Color
2812
- )) {
2791
+ } else if (!this.setAnnotationColor(annotationPtr, bgColor ?? "#FFFFFF", PdfAnnotationColorType.Color)) {
2813
2792
  return false;
2814
2793
  }
2815
- return true;
2794
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2816
2795
  }
2817
2796
  /**
2818
2797
  * Set the rect of specified annotation
@@ -2825,41 +2804,20 @@ class PdfiumNative {
2825
2804
  * @private
2826
2805
  */
2827
2806
  addInkStroke(page, pagePtr, annotationPtr, annotation) {
2828
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2829
- return false;
2830
- }
2831
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2832
- return false;
2833
- }
2834
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2835
- return false;
2836
- }
2837
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2838
- return false;
2839
- }
2840
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2841
- return false;
2842
- }
2843
2807
  if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, annotation.strokeWidth)) {
2844
2808
  return false;
2845
2809
  }
2846
2810
  if (!this.setInkList(page, annotationPtr, annotation.inkList)) {
2847
2811
  return false;
2848
2812
  }
2849
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2850
- return false;
2851
- }
2852
2813
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2853
2814
  return false;
2854
2815
  }
2855
- if (!this.setAnnotationColor(
2856
- annotationPtr,
2857
- annotation.color ?? "#FFFF00",
2858
- PdfAnnotationColorType.Color
2859
- )) {
2816
+ const strokeColor = annotation.strokeColor ?? annotation.color ?? "#FFFF00";
2817
+ if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
2860
2818
  return false;
2861
2819
  }
2862
- return true;
2820
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2863
2821
  }
2864
2822
  /**
2865
2823
  * Add line content to annotation
@@ -2873,18 +2831,6 @@ class PdfiumNative {
2873
2831
  */
2874
2832
  addLineContent(page, pagePtr, annotationPtr, annotation) {
2875
2833
  var _a, _b;
2876
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2877
- return false;
2878
- }
2879
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2880
- return false;
2881
- }
2882
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2883
- return false;
2884
- }
2885
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2886
- return false;
2887
- }
2888
2834
  if (!this.setLinePoints(
2889
2835
  page,
2890
2836
  annotationPtr,
@@ -2900,12 +2846,6 @@ class PdfiumNative {
2900
2846
  )) {
2901
2847
  return false;
2902
2848
  }
2903
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2904
- return false;
2905
- }
2906
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2907
- return false;
2908
- }
2909
2849
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2910
2850
  return false;
2911
2851
  }
@@ -2936,7 +2876,7 @@ class PdfiumNative {
2936
2876
  )) {
2937
2877
  return false;
2938
2878
  }
2939
- return true;
2879
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2940
2880
  }
2941
2881
  /**
2942
2882
  * Add polygon or polyline content to annotation
@@ -2950,18 +2890,6 @@ class PdfiumNative {
2950
2890
  */
2951
2891
  addPolyContent(page, pagePtr, annotationPtr, annotation) {
2952
2892
  var _a, _b;
2953
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2954
- return false;
2955
- }
2956
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2957
- return false;
2958
- }
2959
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2960
- return false;
2961
- }
2962
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2963
- return false;
2964
- }
2965
2893
  if (annotation.type === PdfAnnotationSubtype.POLYLINE && !this.setLineEndings(
2966
2894
  annotationPtr,
2967
2895
  ((_a = annotation.lineEndings) == null ? void 0 : _a.start) ?? PdfAnnotationLineEnding.None,
@@ -2972,12 +2900,6 @@ class PdfiumNative {
2972
2900
  if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {
2973
2901
  return false;
2974
2902
  }
2975
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2976
- return false;
2977
- }
2978
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2979
- return false;
2980
- }
2981
2903
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2982
2904
  return false;
2983
2905
  }
@@ -3008,7 +2930,42 @@ class PdfiumNative {
3008
2930
  )) {
3009
2931
  return false;
3010
2932
  }
3011
- return true;
2933
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2934
+ }
2935
+ /**
2936
+ * Add link content (action or destination) to a link annotation
2937
+ * @param docPtr - pointer to pdf document
2938
+ * @param pagePtr - pointer to the page
2939
+ * @param annotationPtr - pointer to pdf annotation
2940
+ * @param annotation - the link annotation object
2941
+ * @returns true if successful
2942
+ *
2943
+ * @private
2944
+ */
2945
+ addLinkContent(docPtr, pagePtr, annotationPtr, annotation) {
2946
+ const style = annotation.strokeStyle ?? PdfAnnotationBorderStyle.UNDERLINE;
2947
+ const width = annotation.strokeWidth ?? 2;
2948
+ if (!this.setBorderStyle(annotationPtr, style, width)) {
2949
+ return false;
2950
+ }
2951
+ if (annotation.strokeDashArray && !this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray)) {
2952
+ return false;
2953
+ }
2954
+ if (annotation.strokeColor) {
2955
+ if (!this.setAnnotationColor(
2956
+ annotationPtr,
2957
+ annotation.strokeColor,
2958
+ PdfAnnotationColorType.Color
2959
+ )) {
2960
+ return false;
2961
+ }
2962
+ }
2963
+ if (annotation.target) {
2964
+ if (!this.applyLinkTarget(docPtr, annotationPtr, annotation.target)) {
2965
+ return false;
2966
+ }
2967
+ }
2968
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3012
2969
  }
3013
2970
  /**
3014
2971
  * Add shape content to annotation
@@ -3021,30 +2978,12 @@ class PdfiumNative {
3021
2978
  * @private
3022
2979
  */
3023
2980
  addShapeContent(page, pagePtr, annotationPtr, annotation) {
3024
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
3025
- return false;
3026
- }
3027
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
3028
- return false;
3029
- }
3030
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
3031
- return false;
3032
- }
3033
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
3034
- return false;
3035
- }
3036
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
3037
- return false;
3038
- }
3039
2981
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
3040
2982
  return false;
3041
2983
  }
3042
2984
  if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
3043
2985
  return false;
3044
2986
  }
3045
- if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {
3046
- return false;
3047
- }
3048
2987
  if (!annotation.color || annotation.color === "transparent") {
3049
2988
  if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
3050
2989
  return false;
@@ -3066,7 +3005,7 @@ class PdfiumNative {
3066
3005
  )) {
3067
3006
  return false;
3068
3007
  }
3069
- return true;
3008
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3070
3009
  }
3071
3010
  /**
3072
3011
  * Add highlight content to annotation
@@ -3078,38 +3017,84 @@ class PdfiumNative {
3078
3017
  * @private
3079
3018
  */
3080
3019
  addTextMarkupContent(page, pagePtr, annotationPtr, annotation) {
3081
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
3020
+ if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
3082
3021
  return false;
3083
3022
  }
3084
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
3023
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
3085
3024
  return false;
3086
3025
  }
3087
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
3026
+ const strokeColor = annotation.strokeColor ?? annotation.color ?? "#FFFF00";
3027
+ if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
3088
3028
  return false;
3089
3029
  }
3090
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
3030
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3031
+ }
3032
+ /**
3033
+ * Add content to redact annotation
3034
+ * @param page - page info
3035
+ * @param pagePtr - pointer to page object
3036
+ * @param annotationPtr - pointer to redact annotation
3037
+ * @param annotation - redact annotation
3038
+ * @returns whether redact content is added to annotation
3039
+ *
3040
+ * @private
3041
+ */
3042
+ addRedactContent(page, pagePtr, annotationPtr, annotation) {
3043
+ if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
3091
3044
  return false;
3092
3045
  }
3093
- if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
3046
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
3094
3047
  return false;
3095
3048
  }
3096
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
3049
+ if (!annotation.color || annotation.color === "transparent") {
3050
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
3051
+ return false;
3052
+ }
3053
+ } else if (!this.setAnnotationColor(
3054
+ annotationPtr,
3055
+ annotation.color,
3056
+ PdfAnnotationColorType.InteriorColor
3057
+ )) {
3097
3058
  return false;
3098
3059
  }
3099
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
3060
+ if (!annotation.overlayColor || annotation.overlayColor === "transparent") {
3061
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.OverlayColor)) {
3062
+ return false;
3063
+ }
3064
+ } else if (!this.setAnnotationColor(
3065
+ annotationPtr,
3066
+ annotation.overlayColor,
3067
+ PdfAnnotationColorType.OverlayColor
3068
+ )) {
3100
3069
  return false;
3101
3070
  }
3102
- if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
3071
+ if (!annotation.strokeColor || annotation.strokeColor === "transparent") {
3072
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {
3073
+ return false;
3074
+ }
3075
+ } else if (!this.setAnnotationColor(annotationPtr, annotation.strokeColor, PdfAnnotationColorType.Color)) {
3103
3076
  return false;
3104
3077
  }
3105
- if (!this.setAnnotationColor(
3106
- annotationPtr,
3107
- annotation.color ?? "#FFFF00",
3108
- PdfAnnotationColorType.Color
3109
- )) {
3078
+ if (!this.setOverlayText(annotationPtr, annotation.overlayText)) {
3110
3079
  return false;
3111
3080
  }
3112
- return true;
3081
+ if (annotation.overlayTextRepeat !== void 0 && !this.setOverlayTextRepeat(annotationPtr, annotation.overlayTextRepeat)) {
3082
+ return false;
3083
+ }
3084
+ if (annotation.fontFamily !== void 0 || annotation.fontSize !== void 0) {
3085
+ if (!this.setAnnotationDefaultAppearance(
3086
+ annotationPtr,
3087
+ annotation.fontFamily ?? PdfStandardFont.Helvetica,
3088
+ annotation.fontSize ?? 12,
3089
+ annotation.fontColor ?? "#000000"
3090
+ )) {
3091
+ return false;
3092
+ }
3093
+ }
3094
+ if (annotation.textAlign !== void 0 && !this.setAnnotationTextAlignment(annotationPtr, annotation.textAlign)) {
3095
+ return false;
3096
+ }
3097
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3113
3098
  }
3114
3099
  /**
3115
3100
  * Add contents to stamp annotation
@@ -3124,30 +3109,12 @@ class PdfiumNative {
3124
3109
  * @private
3125
3110
  */
3126
3111
  addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
3127
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
3128
- return false;
3129
- }
3130
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
3131
- return false;
3132
- }
3133
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
3134
- return false;
3135
- }
3136
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
3137
- return false;
3138
- }
3139
3112
  if (annotation.icon && !this.setAnnotationIcon(annotationPtr, annotation.icon)) {
3140
3113
  return false;
3141
3114
  }
3142
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
3143
- return false;
3144
- }
3145
3115
  if (annotation.subject && !this.setAnnotString(annotationPtr, "Subj", annotation.subject)) {
3146
3116
  return false;
3147
3117
  }
3148
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
3149
- return false;
3150
- }
3151
3118
  if (imageData) {
3152
3119
  for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
3153
3120
  this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
@@ -3159,7 +3126,7 @@ class PdfiumNative {
3159
3126
  if (!this.pdfiumModule.EPDFAnnot_UpdateAppearanceToRect(annotationPtr, PdfStampFit.Cover)) {
3160
3127
  return false;
3161
3128
  }
3162
- return true;
3129
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3163
3130
  }
3164
3131
  /**
3165
3132
  * Add image object to annotation
@@ -4044,6 +4011,11 @@ class PdfiumNative {
4044
4011
  annotation = this.readPdfCaretAnno(page, annotationPtr, index);
4045
4012
  }
4046
4013
  break;
4014
+ case PdfAnnotationSubtype.REDACT:
4015
+ {
4016
+ annotation = this.readPdfRedactAnno(page, annotationPtr, index);
4017
+ }
4018
+ break;
4047
4019
  default:
4048
4020
  {
4049
4021
  annotation = this.readPdfAnno(page, subType, annotationPtr, index);
@@ -4184,6 +4156,64 @@ class PdfiumNative {
4184
4156
  setAnnotationVerticalAlignment(annotationPtr, alignment) {
4185
4157
  return !!this.pdfiumModule.EPDFAnnot_SetVerticalAlignment(annotationPtr, alignment);
4186
4158
  }
4159
+ /**
4160
+ * Get the overlay text from a Redact annotation.
4161
+ *
4162
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
4163
+ * @returns overlay text string or `undefined` if not set
4164
+ *
4165
+ * @private
4166
+ */
4167
+ getOverlayText(annotationPtr) {
4168
+ const len = this.pdfiumModule.EPDFAnnot_GetOverlayText(annotationPtr, 0, 0);
4169
+ if (len === 0) return void 0;
4170
+ const bytes = (len + 1) * 2;
4171
+ const ptr = this.memoryManager.malloc(bytes);
4172
+ this.pdfiumModule.EPDFAnnot_GetOverlayText(annotationPtr, ptr, bytes);
4173
+ const value = this.pdfiumModule.pdfium.UTF16ToString(ptr);
4174
+ this.memoryManager.free(ptr);
4175
+ return value || void 0;
4176
+ }
4177
+ /**
4178
+ * Set the overlay text on a Redact annotation.
4179
+ *
4180
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
4181
+ * @param text overlay text to set, or undefined/empty to clear
4182
+ * @returns `true` on success
4183
+ *
4184
+ * @private
4185
+ */
4186
+ setOverlayText(annotationPtr, text) {
4187
+ if (!text) {
4188
+ return this.pdfiumModule.EPDFAnnot_SetOverlayText(annotationPtr, 0);
4189
+ }
4190
+ return this.withWString(text, (wPtr) => {
4191
+ return this.pdfiumModule.EPDFAnnot_SetOverlayText(annotationPtr, wPtr);
4192
+ });
4193
+ }
4194
+ /**
4195
+ * Get whether overlay text repeats in a Redact annotation.
4196
+ *
4197
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
4198
+ * @returns `true` if overlay text repeats
4199
+ *
4200
+ * @private
4201
+ */
4202
+ getOverlayTextRepeat(annotationPtr) {
4203
+ return this.pdfiumModule.EPDFAnnot_GetOverlayTextRepeat(annotationPtr);
4204
+ }
4205
+ /**
4206
+ * Set whether overlay text repeats in a Redact annotation.
4207
+ *
4208
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
4209
+ * @param repeat whether overlay text should repeat
4210
+ * @returns `true` on success
4211
+ *
4212
+ * @private
4213
+ */
4214
+ setOverlayTextRepeat(annotationPtr, repeat) {
4215
+ return this.pdfiumModule.EPDFAnnot_SetOverlayTextRepeat(annotationPtr, repeat);
4216
+ }
4187
4217
  /**
4188
4218
  * Return the **default appearance** (font, size, colour) declared in the
4189
4219
  * `/DA` string of a **FreeText** annotation.
@@ -4290,6 +4320,28 @@ class PdfiumNative {
4290
4320
  setAnnotationIcon(annotationPtr, icon) {
4291
4321
  return this.pdfiumModule.EPDFAnnot_SetIcon(annotationPtr, icon);
4292
4322
  }
4323
+ /**
4324
+ * Get the reply type of the annotation (RT property per ISO 32000-2)
4325
+ *
4326
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
4327
+ * @returns `PdfAnnotationReplyType`
4328
+ */
4329
+ getReplyType(annotationPtr) {
4330
+ return this.pdfiumModule.EPDFAnnot_GetReplyType(annotationPtr);
4331
+ }
4332
+ /**
4333
+ * Set the reply type of the annotation (RT property per ISO 32000-2)
4334
+ *
4335
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
4336
+ * @param replyType - `PdfAnnotationReplyType`
4337
+ * @returns `true` on success
4338
+ */
4339
+ setReplyType(annotationPtr, replyType) {
4340
+ return this.pdfiumModule.EPDFAnnot_SetReplyType(
4341
+ annotationPtr,
4342
+ replyType ?? PdfAnnotationReplyType.Unknown
4343
+ );
4344
+ }
4293
4345
  /**
4294
4346
  * Border-effect (“cloudy”) helper
4295
4347
  *
@@ -4678,19 +4730,145 @@ class PdfiumNative {
4678
4730
  this.logger.perf("PDFiumEngine", "Engine", label, "End", `${doc.id}-${page.index}`);
4679
4731
  return PdfTaskHelper.resolve(!!ok);
4680
4732
  }
4681
- /** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */
4682
- allocFSQuadsBufferFromRects(page, rects) {
4683
- const STRIDE = 32;
4684
- const count = rects.length;
4685
- const ptr = this.memoryManager.malloc(STRIDE * count);
4686
- const pdf = this.pdfiumModule.pdfium;
4687
- for (let i = 0; i < count; i++) {
4688
- const r = rects[i];
4689
- const q = rectToQuad(r);
4690
- const p1 = this.convertDevicePointToPagePoint(page, q.p1);
4691
- const p2 = this.convertDevicePointToPagePoint(page, q.p2);
4692
- const p3 = this.convertDevicePointToPagePoint(page, q.p3);
4693
- const p4 = this.convertDevicePointToPagePoint(page, q.p4);
4733
+ /**
4734
+ * Apply a single redaction annotation, permanently removing content underneath
4735
+ * and flattening the RO (Redact Overlay) appearance stream if present.
4736
+ * The annotation is removed after successful application.
4737
+ *
4738
+ * @param doc - document object
4739
+ * @param page - page object
4740
+ * @param annotation - the redact annotation to apply
4741
+ * @returns true if successful
4742
+ */
4743
+ applyRedaction(doc, page, annotation) {
4744
+ this.logger.debug(
4745
+ LOG_SOURCE,
4746
+ LOG_CATEGORY,
4747
+ "applyRedaction",
4748
+ doc.id,
4749
+ page.index,
4750
+ annotation.id
4751
+ );
4752
+ const label = "ApplyRedaction";
4753
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "Begin", `${doc.id}-${page.index}`);
4754
+ const ctx = this.cache.getContext(doc.id);
4755
+ if (!ctx) {
4756
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4757
+ return PdfTaskHelper.reject({
4758
+ code: PdfErrorCode.DocNotOpen,
4759
+ message: "document does not open"
4760
+ });
4761
+ }
4762
+ const pageCtx = ctx.acquirePage(page.index);
4763
+ const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
4764
+ if (!annotPtr) {
4765
+ pageCtx.release();
4766
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4767
+ return PdfTaskHelper.reject({
4768
+ code: PdfErrorCode.NotFound,
4769
+ message: "annotation not found"
4770
+ });
4771
+ }
4772
+ const ok = this.pdfiumModule.EPDFAnnot_ApplyRedaction(pageCtx.pagePtr, annotPtr);
4773
+ this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
4774
+ if (ok) {
4775
+ this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
4776
+ }
4777
+ pageCtx.disposeImmediate();
4778
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4779
+ return PdfTaskHelper.resolve(!!ok);
4780
+ }
4781
+ /**
4782
+ * Apply all redaction annotations on a page, permanently removing content
4783
+ * underneath each one and flattening RO streams if present.
4784
+ * All redact annotations are removed after successful application.
4785
+ *
4786
+ * @param doc - document object
4787
+ * @param page - page object
4788
+ * @returns true if any redactions were applied
4789
+ */
4790
+ applyAllRedactions(doc, page) {
4791
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "applyAllRedactions", doc.id, page.index);
4792
+ const label = "ApplyAllRedactions";
4793
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "Begin", `${doc.id}-${page.index}`);
4794
+ const ctx = this.cache.getContext(doc.id);
4795
+ if (!ctx) {
4796
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4797
+ return PdfTaskHelper.reject({
4798
+ code: PdfErrorCode.DocNotOpen,
4799
+ message: "document does not open"
4800
+ });
4801
+ }
4802
+ const pageCtx = ctx.acquirePage(page.index);
4803
+ const ok = this.pdfiumModule.EPDFPage_ApplyRedactions(pageCtx.pagePtr);
4804
+ if (ok) {
4805
+ this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
4806
+ }
4807
+ pageCtx.disposeImmediate();
4808
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4809
+ return PdfTaskHelper.resolve(!!ok);
4810
+ }
4811
+ /**
4812
+ * Flatten an annotation's appearance (AP/N) to page content.
4813
+ * The annotation's visual appearance becomes part of the page itself.
4814
+ * The annotation is automatically removed after flattening.
4815
+ *
4816
+ * @param doc - document object
4817
+ * @param page - page object
4818
+ * @param annotation - the annotation to flatten
4819
+ * @returns true if successful
4820
+ */
4821
+ flattenAnnotation(doc, page, annotation) {
4822
+ this.logger.debug(
4823
+ LOG_SOURCE,
4824
+ LOG_CATEGORY,
4825
+ "flattenAnnotation",
4826
+ doc.id,
4827
+ page.index,
4828
+ annotation.id
4829
+ );
4830
+ const label = "FlattenAnnotation";
4831
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "Begin", `${doc.id}-${page.index}`);
4832
+ const ctx = this.cache.getContext(doc.id);
4833
+ if (!ctx) {
4834
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4835
+ return PdfTaskHelper.reject({
4836
+ code: PdfErrorCode.DocNotOpen,
4837
+ message: "document does not open"
4838
+ });
4839
+ }
4840
+ const pageCtx = ctx.acquirePage(page.index);
4841
+ const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
4842
+ if (!annotPtr) {
4843
+ pageCtx.release();
4844
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4845
+ return PdfTaskHelper.reject({
4846
+ code: PdfErrorCode.NotFound,
4847
+ message: "annotation not found"
4848
+ });
4849
+ }
4850
+ const ok = this.pdfiumModule.EPDFAnnot_Flatten(pageCtx.pagePtr, annotPtr);
4851
+ this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
4852
+ if (ok) {
4853
+ this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
4854
+ }
4855
+ pageCtx.disposeImmediate();
4856
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
4857
+ return PdfTaskHelper.resolve(!!ok);
4858
+ }
4859
+ /** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */
4860
+ allocFSQuadsBufferFromRects(page, rects) {
4861
+ const STRIDE = 32;
4862
+ const count = rects.length;
4863
+ const ptr = this.memoryManager.malloc(STRIDE * count);
4864
+ const pdf = this.pdfiumModule.pdfium;
4865
+ for (let i = 0; i < count; i++) {
4866
+ const r = rects[i];
4867
+ const q = rectToQuad(r);
4868
+ const p1 = this.convertDevicePointToPagePoint(page, q.p1);
4869
+ const p2 = this.convertDevicePointToPagePoint(page, q.p2);
4870
+ const p3 = this.convertDevicePointToPagePoint(page, q.p3);
4871
+ const p4 = this.convertDevicePointToPagePoint(page, q.p4);
4694
4872
  const base = ptr + i * STRIDE;
4695
4873
  pdf.setValue(base + 0, p1.x, "float");
4696
4874
  pdf.setValue(base + 4, p1.y, "float");
@@ -4774,37 +4952,24 @@ class PdfiumNative {
4774
4952
  * @private
4775
4953
  */
4776
4954
  readPdfTextAnno(page, annotationPtr, index) {
4777
- const custom = this.getAnnotCustom(annotationPtr);
4778
4955
  const annoRect = this.readPageAnnoRect(annotationPtr);
4779
4956
  const rect = this.convertPageRectToDeviceRect(page, annoRect);
4780
- const author = this.getAnnotString(annotationPtr, "T");
4781
- const modified = this.getAnnotationDate(annotationPtr, "M");
4782
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4783
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4784
4957
  const state = this.getAnnotString(annotationPtr, "State");
4785
4958
  const stateModel = this.getAnnotString(annotationPtr, "StateModel");
4786
4959
  const color = this.getAnnotationColor(annotationPtr);
4787
4960
  const opacity = this.getAnnotationOpacity(annotationPtr);
4788
- const inReplyToId = this.getInReplyToId(annotationPtr);
4789
- const flags = this.getAnnotationFlags(annotationPtr);
4790
4961
  const icon = this.getAnnotationIcon(annotationPtr);
4791
4962
  return {
4792
4963
  pageIndex: page.index,
4793
- custom,
4794
4964
  id: index,
4795
4965
  type: PdfAnnotationSubtype.TEXT,
4796
- flags,
4797
- contents,
4966
+ rect,
4798
4967
  color: color ?? "#FFFF00",
4799
4968
  opacity,
4800
- rect,
4801
- inReplyToId,
4802
- author,
4803
- modified,
4804
- created,
4805
4969
  state,
4806
4970
  stateModel,
4807
- icon
4971
+ icon,
4972
+ ...this.readBaseAnnotationProperties(annotationPtr)
4808
4973
  };
4809
4974
  }
4810
4975
  /**
@@ -4817,41 +4982,33 @@ class PdfiumNative {
4817
4982
  * @private
4818
4983
  */
4819
4984
  readPdfFreeTextAnno(page, annotationPtr, index) {
4820
- const custom = this.getAnnotCustom(annotationPtr);
4821
4985
  const annoRect = this.readPageAnnoRect(annotationPtr);
4822
4986
  const rect = this.convertPageRectToDeviceRect(page, annoRect);
4823
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4824
- const author = this.getAnnotString(annotationPtr, "T");
4825
- const modified = this.getAnnotationDate(annotationPtr, "M");
4826
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4827
4987
  const defaultStyle = this.getAnnotString(annotationPtr, "DS");
4828
4988
  const da = this.getAnnotationDefaultAppearance(annotationPtr);
4829
- const backgroundColor = this.getAnnotationColor(annotationPtr);
4989
+ const bgColor = this.getAnnotationColor(annotationPtr);
4830
4990
  const textAlign = this.getAnnotationTextAlignment(annotationPtr);
4831
4991
  const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
4832
4992
  const opacity = this.getAnnotationOpacity(annotationPtr);
4833
4993
  const richContent = this.getAnnotRichContent(annotationPtr);
4834
- const flags = this.getAnnotationFlags(annotationPtr);
4835
4994
  return {
4836
4995
  pageIndex: page.index,
4837
- custom,
4838
4996
  id: index,
4839
4997
  type: PdfAnnotationSubtype.FREETEXT,
4998
+ rect,
4840
4999
  fontFamily: (da == null ? void 0 : da.fontFamily) ?? PdfStandardFont.Unknown,
4841
5000
  fontSize: (da == null ? void 0 : da.fontSize) ?? 12,
4842
5001
  fontColor: (da == null ? void 0 : da.fontColor) ?? "#000000",
4843
5002
  verticalAlign,
4844
- backgroundColor,
4845
- flags,
5003
+ color: bgColor,
5004
+ // fill color (matches shape convention)
5005
+ backgroundColor: bgColor,
5006
+ // deprecated alias
4846
5007
  opacity,
4847
5008
  textAlign,
4848
5009
  defaultStyle,
4849
5010
  richContent,
4850
- contents,
4851
- author,
4852
- modified,
4853
- created,
4854
- rect
5011
+ ...this.readBaseAnnotationProperties(annotationPtr)
4855
5012
  };
4856
5013
  }
4857
5014
  /**
@@ -4865,17 +5022,21 @@ class PdfiumNative {
4865
5022
  * @private
4866
5023
  */
4867
5024
  readPdfLinkAnno(page, docPtr, annotationPtr, index) {
4868
- const custom = this.getAnnotCustom(annotationPtr);
4869
5025
  const linkPtr = this.pdfiumModule.FPDFAnnot_GetLink(annotationPtr);
4870
5026
  if (!linkPtr) {
4871
5027
  return;
4872
5028
  }
4873
5029
  const annoRect = this.readPageAnnoRect(annotationPtr);
4874
5030
  const rect = this.convertPageRectToDeviceRect(page, annoRect);
4875
- const author = this.getAnnotString(annotationPtr, "T");
4876
- const modified = this.getAnnotationDate(annotationPtr, "M");
4877
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4878
- const flags = this.getAnnotationFlags(annotationPtr);
5031
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5032
+ const strokeColor = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.Color);
5033
+ let strokeDashArray;
5034
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5035
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
5036
+ if (ok) {
5037
+ strokeDashArray = pattern;
5038
+ }
5039
+ }
4879
5040
  const target = this.readPdfLinkAnnoTarget(
4880
5041
  docPtr,
4881
5042
  () => {
@@ -4887,15 +5048,15 @@ class PdfiumNative {
4887
5048
  );
4888
5049
  return {
4889
5050
  pageIndex: page.index,
4890
- custom,
4891
5051
  id: index,
4892
5052
  type: PdfAnnotationSubtype.LINK,
4893
- flags,
4894
- target,
4895
5053
  rect,
4896
- author,
4897
- modified,
4898
- created
5054
+ target,
5055
+ strokeColor,
5056
+ strokeWidth,
5057
+ strokeStyle,
5058
+ strokeDashArray,
5059
+ ...this.readBaseAnnotationProperties(annotationPtr)
4899
5060
  };
4900
5061
  }
4901
5062
  /**
@@ -4909,25 +5070,16 @@ class PdfiumNative {
4909
5070
  * @private
4910
5071
  */
4911
5072
  readPdfWidgetAnno(page, annotationPtr, formHandle, index) {
4912
- const custom = this.getAnnotCustom(annotationPtr);
4913
5073
  const pageRect = this.readPageAnnoRect(annotationPtr);
4914
5074
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
4915
- const author = this.getAnnotString(annotationPtr, "T");
4916
- const modified = this.getAnnotationDate(annotationPtr, "M");
4917
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4918
- const flags = this.getAnnotationFlags(annotationPtr);
4919
5075
  const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
4920
5076
  return {
4921
5077
  pageIndex: page.index,
4922
- custom,
4923
5078
  id: index,
4924
5079
  type: PdfAnnotationSubtype.WIDGET,
4925
- flags,
4926
5080
  rect,
4927
5081
  field,
4928
- author,
4929
- modified,
4930
- created
5082
+ ...this.readBaseAnnotationProperties(annotationPtr)
4931
5083
  };
4932
5084
  }
4933
5085
  /**
@@ -4940,23 +5092,14 @@ class PdfiumNative {
4940
5092
  * @private
4941
5093
  */
4942
5094
  readPdfFileAttachmentAnno(page, annotationPtr, index) {
4943
- const custom = this.getAnnotCustom(annotationPtr);
4944
5095
  const pageRect = this.readPageAnnoRect(annotationPtr);
4945
5096
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
4946
- const author = this.getAnnotString(annotationPtr, "T");
4947
- const modified = this.getAnnotationDate(annotationPtr, "M");
4948
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4949
- const flags = this.getAnnotationFlags(annotationPtr);
4950
5097
  return {
4951
5098
  pageIndex: page.index,
4952
- custom,
4953
5099
  id: index,
4954
5100
  type: PdfAnnotationSubtype.FILEATTACHMENT,
4955
- flags,
4956
5101
  rect,
4957
- author,
4958
- modified,
4959
- created
5102
+ ...this.readBaseAnnotationProperties(annotationPtr)
4960
5103
  };
4961
5104
  }
4962
5105
  /**
@@ -4969,37 +5112,28 @@ class PdfiumNative {
4969
5112
  * @private
4970
5113
  */
4971
5114
  readPdfInkAnno(page, annotationPtr, index) {
4972
- const custom = this.getAnnotCustom(annotationPtr);
4973
5115
  const pageRect = this.readPageAnnoRect(annotationPtr);
4974
5116
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
4975
- const author = this.getAnnotString(annotationPtr, "T");
4976
- const modified = this.getAnnotationDate(annotationPtr, "M");
4977
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4978
- const color = this.getAnnotationColor(annotationPtr);
5117
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
4979
5118
  const opacity = this.getAnnotationOpacity(annotationPtr);
4980
5119
  const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
4981
5120
  const inkList = this.getInkList(page, annotationPtr);
4982
5121
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4983
5122
  const intent = this.getAnnotIntent(annotationPtr);
4984
- const flags = this.getAnnotationFlags(annotationPtr);
4985
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4986
5123
  return {
4987
5124
  pageIndex: page.index,
4988
- custom,
4989
5125
  id: index,
4990
5126
  type: PdfAnnotationSubtype.INK,
5127
+ rect,
4991
5128
  ...intent && { intent },
4992
- contents,
4993
5129
  blendMode,
4994
- flags,
4995
- color: color ?? "#FF0000",
5130
+ strokeColor,
5131
+ color: strokeColor,
5132
+ // deprecated alias
4996
5133
  opacity,
4997
5134
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
4998
- rect,
4999
5135
  inkList,
5000
- author,
5001
- modified,
5002
- created
5136
+ ...this.readBaseAnnotationProperties(annotationPtr)
5003
5137
  };
5004
5138
  }
5005
5139
  /**
@@ -5012,22 +5146,16 @@ class PdfiumNative {
5012
5146
  * @private
5013
5147
  */
5014
5148
  readPdfPolygonAnno(page, annotationPtr, index) {
5015
- const custom = this.getAnnotCustom(annotationPtr);
5016
5149
  const pageRect = this.readPageAnnoRect(annotationPtr);
5017
5150
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5018
- const author = this.getAnnotString(annotationPtr, "T");
5019
- const modified = this.getAnnotationDate(annotationPtr, "M");
5020
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5021
5151
  const vertices = this.readPdfAnnoVertices(page, annotationPtr);
5022
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5023
- const flags = this.getAnnotationFlags(annotationPtr);
5024
5152
  const strokeColor = this.getAnnotationColor(annotationPtr);
5025
5153
  const interiorColor = this.getAnnotationColor(
5026
5154
  annotationPtr,
5027
5155
  PdfAnnotationColorType.InteriorColor
5028
5156
  );
5029
5157
  const opacity = this.getAnnotationOpacity(annotationPtr);
5030
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5158
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5031
5159
  let strokeDashArray;
5032
5160
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5033
5161
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5044,22 +5172,17 @@ class PdfiumNative {
5044
5172
  }
5045
5173
  return {
5046
5174
  pageIndex: page.index,
5047
- custom,
5048
5175
  id: index,
5049
5176
  type: PdfAnnotationSubtype.POLYGON,
5050
- contents,
5051
- flags,
5177
+ rect,
5052
5178
  strokeColor: strokeColor ?? "#FF0000",
5053
5179
  color: interiorColor ?? "transparent",
5054
5180
  opacity,
5055
5181
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
5056
5182
  strokeStyle,
5057
5183
  strokeDashArray,
5058
- rect,
5059
5184
  vertices,
5060
- author,
5061
- modified,
5062
- created
5185
+ ...this.readBaseAnnotationProperties(annotationPtr)
5063
5186
  };
5064
5187
  }
5065
5188
  /**
@@ -5072,22 +5195,16 @@ class PdfiumNative {
5072
5195
  * @private
5073
5196
  */
5074
5197
  readPdfPolylineAnno(page, annotationPtr, index) {
5075
- const custom = this.getAnnotCustom(annotationPtr);
5076
5198
  const pageRect = this.readPageAnnoRect(annotationPtr);
5077
5199
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5078
- const author = this.getAnnotString(annotationPtr, "T");
5079
- const modified = this.getAnnotationDate(annotationPtr, "M");
5080
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5081
5200
  const vertices = this.readPdfAnnoVertices(page, annotationPtr);
5082
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5083
5201
  const strokeColor = this.getAnnotationColor(annotationPtr);
5084
- const flags = this.getAnnotationFlags(annotationPtr);
5085
5202
  const interiorColor = this.getAnnotationColor(
5086
5203
  annotationPtr,
5087
5204
  PdfAnnotationColorType.InteriorColor
5088
5205
  );
5089
5206
  const opacity = this.getAnnotationOpacity(annotationPtr);
5090
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5207
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5091
5208
  let strokeDashArray;
5092
5209
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5093
5210
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5098,11 +5215,9 @@ class PdfiumNative {
5098
5215
  const lineEndings = this.getLineEndings(annotationPtr);
5099
5216
  return {
5100
5217
  pageIndex: page.index,
5101
- custom,
5102
5218
  id: index,
5103
5219
  type: PdfAnnotationSubtype.POLYLINE,
5104
- contents,
5105
- flags,
5220
+ rect,
5106
5221
  strokeColor: strokeColor ?? "#FF0000",
5107
5222
  color: interiorColor ?? "transparent",
5108
5223
  opacity,
@@ -5110,11 +5225,8 @@ class PdfiumNative {
5110
5225
  strokeStyle,
5111
5226
  strokeDashArray,
5112
5227
  lineEndings,
5113
- rect,
5114
5228
  vertices,
5115
- author,
5116
- modified,
5117
- created
5229
+ ...this.readBaseAnnotationProperties(annotationPtr)
5118
5230
  };
5119
5231
  }
5120
5232
  /**
@@ -5127,23 +5239,17 @@ class PdfiumNative {
5127
5239
  * @private
5128
5240
  */
5129
5241
  readPdfLineAnno(page, annotationPtr, index) {
5130
- const custom = this.getAnnotCustom(annotationPtr);
5131
5242
  const pageRect = this.readPageAnnoRect(annotationPtr);
5132
5243
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5133
- const author = this.getAnnotString(annotationPtr, "T");
5134
- const modified = this.getAnnotationDate(annotationPtr, "M");
5135
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5136
5244
  const linePoints = this.getLinePoints(page, annotationPtr);
5137
5245
  const lineEndings = this.getLineEndings(annotationPtr);
5138
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5139
5246
  const strokeColor = this.getAnnotationColor(annotationPtr);
5140
- const flags = this.getAnnotationFlags(annotationPtr);
5141
5247
  const interiorColor = this.getAnnotationColor(
5142
5248
  annotationPtr,
5143
5249
  PdfAnnotationColorType.InteriorColor
5144
5250
  );
5145
5251
  const opacity = this.getAnnotationOpacity(annotationPtr);
5146
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5252
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5147
5253
  let strokeDashArray;
5148
5254
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5149
5255
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5153,12 +5259,9 @@ class PdfiumNative {
5153
5259
  }
5154
5260
  return {
5155
5261
  pageIndex: page.index,
5156
- custom,
5157
5262
  id: index,
5158
5263
  type: PdfAnnotationSubtype.LINE,
5159
- flags,
5160
5264
  rect,
5161
- contents,
5162
5265
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
5163
5266
  strokeStyle,
5164
5267
  strokeDashArray,
@@ -5170,9 +5273,7 @@ class PdfiumNative {
5170
5273
  start: PdfAnnotationLineEnding.None,
5171
5274
  end: PdfAnnotationLineEnding.None
5172
5275
  },
5173
- author,
5174
- modified,
5175
- created
5276
+ ...this.readBaseAnnotationProperties(annotationPtr)
5176
5277
  };
5177
5278
  }
5178
5279
  /**
@@ -5185,33 +5286,24 @@ class PdfiumNative {
5185
5286
  * @private
5186
5287
  */
5187
5288
  readPdfHighlightAnno(page, annotationPtr, index) {
5188
- const custom = this.getAnnotCustom(annotationPtr);
5189
5289
  const pageRect = this.readPageAnnoRect(annotationPtr);
5190
5290
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5191
5291
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5192
- const color = this.getAnnotationColor(annotationPtr);
5292
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FFFF00";
5193
5293
  const opacity = this.getAnnotationOpacity(annotationPtr);
5194
5294
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5195
- const author = this.getAnnotString(annotationPtr, "T");
5196
- const modified = this.getAnnotationDate(annotationPtr, "M");
5197
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5198
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5199
- const flags = this.getAnnotationFlags(annotationPtr);
5200
5295
  return {
5201
5296
  pageIndex: page.index,
5202
- custom,
5203
5297
  id: index,
5204
- blendMode,
5205
5298
  type: PdfAnnotationSubtype.HIGHLIGHT,
5206
5299
  rect,
5207
- flags,
5208
- contents,
5300
+ blendMode,
5209
5301
  segmentRects,
5210
- color: color ?? "#FFFF00",
5302
+ strokeColor,
5303
+ color: strokeColor,
5304
+ // deprecated alias
5211
5305
  opacity,
5212
- author,
5213
- modified,
5214
- created
5306
+ ...this.readBaseAnnotationProperties(annotationPtr)
5215
5307
  };
5216
5308
  }
5217
5309
  /**
@@ -5224,33 +5316,24 @@ class PdfiumNative {
5224
5316
  * @private
5225
5317
  */
5226
5318
  readPdfUnderlineAnno(page, annotationPtr, index) {
5227
- const custom = this.getAnnotCustom(annotationPtr);
5228
5319
  const pageRect = this.readPageAnnoRect(annotationPtr);
5229
5320
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5230
- const author = this.getAnnotString(annotationPtr, "T");
5231
- const modified = this.getAnnotationDate(annotationPtr, "M");
5232
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5233
5321
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5234
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5235
- const color = this.getAnnotationColor(annotationPtr);
5322
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5236
5323
  const opacity = this.getAnnotationOpacity(annotationPtr);
5237
5324
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5238
- const flags = this.getAnnotationFlags(annotationPtr);
5239
5325
  return {
5240
5326
  pageIndex: page.index,
5241
- custom,
5242
5327
  id: index,
5243
- blendMode,
5244
5328
  type: PdfAnnotationSubtype.UNDERLINE,
5245
5329
  rect,
5246
- flags,
5247
- contents,
5330
+ blendMode,
5248
5331
  segmentRects,
5249
- color: color ?? "#FF0000",
5332
+ strokeColor,
5333
+ color: strokeColor,
5334
+ // deprecated alias
5250
5335
  opacity,
5251
- author,
5252
- modified,
5253
- created
5336
+ ...this.readBaseAnnotationProperties(annotationPtr)
5254
5337
  };
5255
5338
  }
5256
5339
  /**
@@ -5263,33 +5346,24 @@ class PdfiumNative {
5263
5346
  * @private
5264
5347
  */
5265
5348
  readPdfStrikeOutAnno(page, annotationPtr, index) {
5266
- const custom = this.getAnnotCustom(annotationPtr);
5267
5349
  const pageRect = this.readPageAnnoRect(annotationPtr);
5268
5350
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5269
- const author = this.getAnnotString(annotationPtr, "T");
5270
- const modified = this.getAnnotationDate(annotationPtr, "M");
5271
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5272
5351
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5273
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5274
- const color = this.getAnnotationColor(annotationPtr);
5352
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5275
5353
  const opacity = this.getAnnotationOpacity(annotationPtr);
5276
5354
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5277
- const flags = this.getAnnotationFlags(annotationPtr);
5278
5355
  return {
5279
5356
  pageIndex: page.index,
5280
- custom,
5281
5357
  id: index,
5282
- blendMode,
5283
5358
  type: PdfAnnotationSubtype.STRIKEOUT,
5284
- flags,
5285
5359
  rect,
5286
- contents,
5360
+ blendMode,
5287
5361
  segmentRects,
5288
- color: color ?? "#FF0000",
5362
+ strokeColor,
5363
+ color: strokeColor,
5364
+ // deprecated alias
5289
5365
  opacity,
5290
- author,
5291
- modified,
5292
- created
5366
+ ...this.readBaseAnnotationProperties(annotationPtr)
5293
5367
  };
5294
5368
  }
5295
5369
  /**
@@ -5302,33 +5376,24 @@ class PdfiumNative {
5302
5376
  * @private
5303
5377
  */
5304
5378
  readPdfSquigglyAnno(page, annotationPtr, index) {
5305
- const custom = this.getAnnotCustom(annotationPtr);
5306
5379
  const pageRect = this.readPageAnnoRect(annotationPtr);
5307
5380
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5308
- const author = this.getAnnotString(annotationPtr, "T");
5309
- const modified = this.getAnnotationDate(annotationPtr, "M");
5310
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5311
5381
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5312
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5313
- const color = this.getAnnotationColor(annotationPtr);
5382
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5314
5383
  const opacity = this.getAnnotationOpacity(annotationPtr);
5315
5384
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5316
- const flags = this.getAnnotationFlags(annotationPtr);
5317
5385
  return {
5318
5386
  pageIndex: page.index,
5319
- custom,
5320
5387
  id: index,
5321
- blendMode,
5322
5388
  type: PdfAnnotationSubtype.SQUIGGLY,
5323
5389
  rect,
5324
- flags,
5325
- contents,
5390
+ blendMode,
5326
5391
  segmentRects,
5327
- color: color ?? "#FF0000",
5392
+ strokeColor,
5393
+ color: strokeColor,
5394
+ // deprecated alias
5328
5395
  opacity,
5329
- author,
5330
- modified,
5331
- created
5396
+ ...this.readBaseAnnotationProperties(annotationPtr)
5332
5397
  };
5333
5398
  }
5334
5399
  /**
@@ -5341,23 +5406,57 @@ class PdfiumNative {
5341
5406
  * @private
5342
5407
  */
5343
5408
  readPdfCaretAnno(page, annotationPtr, index) {
5344
- const custom = this.getAnnotCustom(annotationPtr);
5345
5409
  const pageRect = this.readPageAnnoRect(annotationPtr);
5346
5410
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5347
- const author = this.getAnnotString(annotationPtr, "T");
5348
- const modified = this.getAnnotationDate(annotationPtr, "M");
5349
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5350
- const flags = this.getAnnotationFlags(annotationPtr);
5351
5411
  return {
5352
5412
  pageIndex: page.index,
5353
- custom,
5354
5413
  id: index,
5355
5414
  type: PdfAnnotationSubtype.CARET,
5356
5415
  rect,
5357
- flags,
5358
- author,
5359
- modified,
5360
- created
5416
+ ...this.readBaseAnnotationProperties(annotationPtr)
5417
+ };
5418
+ }
5419
+ /**
5420
+ * Read pdf redact annotation
5421
+ * @param page - pdf page info
5422
+ * @param annotationPtr - pointer to pdf annotation
5423
+ * @param index - index of annotation in the pdf page
5424
+ * @returns pdf redact annotation
5425
+ *
5426
+ * @private
5427
+ */
5428
+ readPdfRedactAnno(page, annotationPtr, index) {
5429
+ const pageRect = this.readPageAnnoRect(annotationPtr);
5430
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
5431
+ const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5432
+ const color = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.InteriorColor);
5433
+ const overlayColor = this.getAnnotationColor(
5434
+ annotationPtr,
5435
+ PdfAnnotationColorType.OverlayColor
5436
+ );
5437
+ const strokeColor = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.Color);
5438
+ const opacity = this.getAnnotationOpacity(annotationPtr);
5439
+ const overlayText = this.getOverlayText(annotationPtr);
5440
+ const overlayTextRepeat = this.getOverlayTextRepeat(annotationPtr);
5441
+ const da = this.getAnnotationDefaultAppearance(annotationPtr);
5442
+ const textAlign = this.getAnnotationTextAlignment(annotationPtr);
5443
+ return {
5444
+ pageIndex: page.index,
5445
+ id: index,
5446
+ type: PdfAnnotationSubtype.REDACT,
5447
+ rect,
5448
+ segmentRects,
5449
+ color,
5450
+ overlayColor,
5451
+ strokeColor,
5452
+ opacity,
5453
+ overlayText,
5454
+ overlayTextRepeat,
5455
+ fontFamily: da == null ? void 0 : da.fontFamily,
5456
+ fontSize: da == null ? void 0 : da.fontSize,
5457
+ fontColor: da == null ? void 0 : da.fontColor,
5458
+ textAlign,
5459
+ ...this.readBaseAnnotationProperties(annotationPtr)
5361
5460
  };
5362
5461
  }
5363
5462
  /**
@@ -5370,25 +5469,14 @@ class PdfiumNative {
5370
5469
  * @private
5371
5470
  */
5372
5471
  readPdfStampAnno(page, annotationPtr, index) {
5373
- const custom = this.getAnnotCustom(annotationPtr);
5374
5472
  const pageRect = this.readPageAnnoRect(annotationPtr);
5375
5473
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5376
- const author = this.getAnnotString(annotationPtr, "T");
5377
- const modified = this.getAnnotationDate(annotationPtr, "M");
5378
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5379
- const flags = this.getAnnotationFlags(annotationPtr);
5380
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5381
5474
  return {
5382
5475
  pageIndex: page.index,
5383
- custom,
5384
5476
  id: index,
5385
5477
  type: PdfAnnotationSubtype.STAMP,
5386
- contents,
5387
5478
  rect,
5388
- author,
5389
- modified,
5390
- created,
5391
- flags
5479
+ ...this.readBaseAnnotationProperties(annotationPtr)
5392
5480
  };
5393
5481
  }
5394
5482
  /**
@@ -5624,21 +5712,15 @@ class PdfiumNative {
5624
5712
  * @private
5625
5713
  */
5626
5714
  readPdfCircleAnno(page, annotationPtr, index) {
5627
- const custom = this.getAnnotCustom(annotationPtr);
5628
- const flags = this.getAnnotationFlags(annotationPtr);
5629
5715
  const pageRect = this.readPageAnnoRect(annotationPtr);
5630
5716
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5631
- const author = this.getAnnotString(annotationPtr, "T");
5632
- const modified = this.getAnnotationDate(annotationPtr, "M");
5633
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5634
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5635
5717
  const interiorColor = this.getAnnotationColor(
5636
5718
  annotationPtr,
5637
5719
  PdfAnnotationColorType.InteriorColor
5638
5720
  );
5639
5721
  const strokeColor = this.getAnnotationColor(annotationPtr);
5640
5722
  const opacity = this.getAnnotationOpacity(annotationPtr);
5641
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5723
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5642
5724
  let strokeDashArray;
5643
5725
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5644
5726
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5648,21 +5730,16 @@ class PdfiumNative {
5648
5730
  }
5649
5731
  return {
5650
5732
  pageIndex: page.index,
5651
- custom,
5652
5733
  id: index,
5653
5734
  type: PdfAnnotationSubtype.CIRCLE,
5654
- flags,
5735
+ rect,
5655
5736
  color: interiorColor ?? "transparent",
5656
5737
  opacity,
5657
- contents,
5658
5738
  strokeWidth,
5659
5739
  strokeColor: strokeColor ?? "#FF0000",
5660
5740
  strokeStyle,
5661
- rect,
5662
- author,
5663
- modified,
5664
- created,
5665
- ...strokeDashArray !== void 0 && { strokeDashArray }
5741
+ ...strokeDashArray !== void 0 && { strokeDashArray },
5742
+ ...this.readBaseAnnotationProperties(annotationPtr)
5666
5743
  };
5667
5744
  }
5668
5745
  /**
@@ -5675,21 +5752,15 @@ class PdfiumNative {
5675
5752
  * @private
5676
5753
  */
5677
5754
  readPdfSquareAnno(page, annotationPtr, index) {
5678
- const custom = this.getAnnotCustom(annotationPtr);
5679
- const flags = this.getAnnotationFlags(annotationPtr);
5680
5755
  const pageRect = this.readPageAnnoRect(annotationPtr);
5681
5756
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5682
- const author = this.getAnnotString(annotationPtr, "T");
5683
- const modified = this.getAnnotationDate(annotationPtr, "M");
5684
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5685
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5686
5757
  const interiorColor = this.getAnnotationColor(
5687
5758
  annotationPtr,
5688
5759
  PdfAnnotationColorType.InteriorColor
5689
5760
  );
5690
5761
  const strokeColor = this.getAnnotationColor(annotationPtr);
5691
5762
  const opacity = this.getAnnotationOpacity(annotationPtr);
5692
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5763
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5693
5764
  let strokeDashArray;
5694
5765
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5695
5766
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5699,21 +5770,16 @@ class PdfiumNative {
5699
5770
  }
5700
5771
  return {
5701
5772
  pageIndex: page.index,
5702
- custom,
5703
5773
  id: index,
5704
5774
  type: PdfAnnotationSubtype.SQUARE,
5705
- flags,
5775
+ rect,
5706
5776
  color: interiorColor ?? "transparent",
5707
5777
  opacity,
5708
- contents,
5709
5778
  strokeColor: strokeColor ?? "#FF0000",
5710
5779
  strokeWidth,
5711
5780
  strokeStyle,
5712
- rect,
5713
- author,
5714
- modified,
5715
- created,
5716
- ...strokeDashArray !== void 0 && { strokeDashArray }
5781
+ ...strokeDashArray !== void 0 && { strokeDashArray },
5782
+ ...this.readBaseAnnotationProperties(annotationPtr)
5717
5783
  };
5718
5784
  }
5719
5785
  /**
@@ -5727,23 +5793,14 @@ class PdfiumNative {
5727
5793
  * @private
5728
5794
  */
5729
5795
  readPdfAnno(page, type, annotationPtr, index) {
5730
- const custom = this.getAnnotCustom(annotationPtr);
5731
5796
  const pageRect = this.readPageAnnoRect(annotationPtr);
5732
5797
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5733
- const author = this.getAnnotString(annotationPtr, "T");
5734
- const modified = this.getAnnotationDate(annotationPtr, "M");
5735
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5736
- const flags = this.getAnnotationFlags(annotationPtr);
5737
5798
  return {
5738
5799
  pageIndex: page.index,
5739
- custom,
5740
5800
  id: index,
5741
- flags,
5742
5801
  type,
5743
5802
  rect,
5744
- author,
5745
- modified,
5746
- created
5803
+ ...this.readBaseAnnotationProperties(annotationPtr)
5747
5804
  };
5748
5805
  }
5749
5806
  /**
@@ -5768,10 +5825,86 @@ class PdfiumNative {
5768
5825
  * @returns `true` on success
5769
5826
  */
5770
5827
  setInReplyToId(pagePtr, annotationPtr, id) {
5828
+ if (!id) {
5829
+ return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, "IRT", 0);
5830
+ }
5771
5831
  const parentPtr = this.getAnnotationByName(pagePtr, id);
5772
5832
  if (!parentPtr) return false;
5773
5833
  return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, "IRT", parentPtr);
5774
5834
  }
5835
+ /**
5836
+ * Apply all base annotation properties from PdfAnnotationObjectBase.
5837
+ * The setInReplyToId and setReplyType functions handle clearing when undefined.
5838
+ *
5839
+ * @param pagePtr - pointer to page object
5840
+ * @param annotationPtr - pointer to annotation object
5841
+ * @param annotation - the annotation object containing properties to apply
5842
+ * @returns `true` on success
5843
+ */
5844
+ applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation) {
5845
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
5846
+ return false;
5847
+ }
5848
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
5849
+ return false;
5850
+ }
5851
+ if (annotation.modified) {
5852
+ if (!this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
5853
+ return false;
5854
+ }
5855
+ }
5856
+ if (annotation.created) {
5857
+ if (!this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
5858
+ return false;
5859
+ }
5860
+ }
5861
+ if (annotation.flags) {
5862
+ if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {
5863
+ return false;
5864
+ }
5865
+ }
5866
+ if (annotation.custom) {
5867
+ if (!this.setAnnotCustom(annotationPtr, annotation.custom)) {
5868
+ return false;
5869
+ }
5870
+ }
5871
+ if (!this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)) {
5872
+ return false;
5873
+ }
5874
+ if (!this.setReplyType(annotationPtr, annotation.replyType)) {
5875
+ return false;
5876
+ }
5877
+ return true;
5878
+ }
5879
+ /**
5880
+ * Read all base annotation properties from PdfAnnotationObjectBase.
5881
+ * Returns an object that can be spread into the annotation return value.
5882
+ *
5883
+ * @param annotationPtr - pointer to annotation object
5884
+ * @returns object with base annotation properties
5885
+ */
5886
+ readBaseAnnotationProperties(annotationPtr) {
5887
+ const author = this.getAnnotString(annotationPtr, "T");
5888
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5889
+ const modified = this.getAnnotationDate(annotationPtr, "M");
5890
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5891
+ const flags = this.getAnnotationFlags(annotationPtr);
5892
+ const custom = this.getAnnotCustom(annotationPtr);
5893
+ const inReplyToId = this.getInReplyToId(annotationPtr);
5894
+ const replyType = this.getReplyType(annotationPtr);
5895
+ return {
5896
+ author,
5897
+ contents,
5898
+ modified,
5899
+ created,
5900
+ flags,
5901
+ custom,
5902
+ // Only include IRT if present
5903
+ ...inReplyToId && { inReplyToId },
5904
+ // Only include RT if present and not the default (Reply)
5905
+ ...replyType && replyType !== PdfAnnotationReplyType.Reply && { replyType }
5906
+ };
5907
+ }
5775
5908
  /**
5776
5909
  * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
5777
5910
  *
@@ -6486,6 +6619,51 @@ class PdfiumNative {
6486
6619
  return false;
6487
6620
  }
6488
6621
  }
6622
+ /**
6623
+ * Apply a link target (action or destination) to a link annotation
6624
+ * @param docPtr - pointer to pdf document
6625
+ * @param annotationPtr - pointer to the link annotation
6626
+ * @param target - the link target to apply
6627
+ * @returns true if successful
6628
+ *
6629
+ * @private
6630
+ */
6631
+ applyLinkTarget(docPtr, annotationPtr, target) {
6632
+ if (target.type === "destination") {
6633
+ const destPtr = this.createLocalDestPtr(docPtr, target.destination);
6634
+ if (!destPtr) return false;
6635
+ const actPtr = this.pdfiumModule.EPDFAction_CreateGoTo(docPtr, destPtr);
6636
+ if (!actPtr) return false;
6637
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6638
+ }
6639
+ const action = target.action;
6640
+ switch (action.type) {
6641
+ case PdfActionType.Goto: {
6642
+ const destPtr = this.createLocalDestPtr(docPtr, action.destination);
6643
+ if (!destPtr) return false;
6644
+ const actPtr = this.pdfiumModule.EPDFAction_CreateGoTo(docPtr, destPtr);
6645
+ if (!actPtr) return false;
6646
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6647
+ }
6648
+ case PdfActionType.URI: {
6649
+ const actPtr = this.pdfiumModule.EPDFAction_CreateURI(docPtr, action.uri);
6650
+ if (!actPtr) return false;
6651
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6652
+ }
6653
+ case PdfActionType.LaunchAppOrOpenFile: {
6654
+ const actPtr = this.withWString(
6655
+ action.path,
6656
+ (wptr) => this.pdfiumModule.EPDFAction_CreateLaunch(docPtr, wptr)
6657
+ );
6658
+ if (!actPtr) return false;
6659
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6660
+ }
6661
+ case PdfActionType.RemoteGoto:
6662
+ case PdfActionType.Unsupported:
6663
+ default:
6664
+ return false;
6665
+ }
6666
+ }
6489
6667
  /**
6490
6668
  * Read pdf action from pdf document
6491
6669
  * @param docPtr - pointer to pdf document object
@@ -7422,4 +7600,4 @@ export {
7422
7600
  isValidCustomKey as i,
7423
7601
  readString as r
7424
7602
  };
7425
- //# sourceMappingURL=direct-engine-DGRkMlJ8.js.map
7603
+ //# sourceMappingURL=direct-engine-6BoAmGsC.js.map