@embedpdf/engines 1.0.16 → 1.0.17

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 (37) hide show
  1. package/dist/engine-Bcr-xNy6.cjs +2 -0
  2. package/dist/engine-Bcr-xNy6.cjs.map +1 -0
  3. package/dist/{engine-B11yoQGd.js → engine-uSZXjmb5.js} +610 -295
  4. package/dist/engine-uSZXjmb5.js.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/lib/pdfium/cache.d.ts +7 -0
  8. package/dist/lib/pdfium/engine.d.ts +129 -56
  9. package/dist/lib/pdfium/index.cjs +1 -1
  10. package/dist/lib/pdfium/index.js +2 -2
  11. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  12. package/dist/lib/pdfium/web/direct-engine.js +1 -1
  13. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  14. package/dist/lib/pdfium/web/worker-engine.js +1 -1
  15. package/dist/lib/webworker/engine.cjs +1 -1
  16. package/dist/lib/webworker/engine.cjs.map +1 -1
  17. package/dist/lib/webworker/engine.d.ts +42 -36
  18. package/dist/lib/webworker/engine.js +22 -7
  19. package/dist/lib/webworker/engine.js.map +1 -1
  20. package/dist/lib/webworker/runner.d.ts +21 -1
  21. package/dist/preact/index.cjs +1 -1
  22. package/dist/preact/index.js +1 -1
  23. package/dist/react/index.cjs +1 -1
  24. package/dist/react/index.js +1 -1
  25. package/dist/{runner-D9_9TvyZ.js → runner-BOJ4naYI.js} +28 -2
  26. package/dist/runner-BOJ4naYI.js.map +1 -0
  27. package/dist/runner-C64KrEhP.cjs +2 -0
  28. package/dist/runner-C64KrEhP.cjs.map +1 -0
  29. package/dist/vue/index.cjs +1 -1
  30. package/dist/vue/index.js +1 -1
  31. package/package.json +3 -3
  32. package/dist/engine-B11yoQGd.js.map +0 -1
  33. package/dist/engine-v2kq6ghL.cjs +0 -2
  34. package/dist/engine-v2kq6ghL.cjs.map +0 -1
  35. package/dist/runner-D9_9TvyZ.js.map +0 -1
  36. package/dist/runner-Dnb6tfxR.cjs +0 -2
  37. package/dist/runner-Dnb6tfxR.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { NoopLogger, PdfTaskHelper, PdfErrorCode, Rotation, Task, PdfAnnotationSubtype, stripPdfUnwantedMarkers, PdfAnnotationBorderStyle, dateToPdfDate, PdfAnnotationColorType, PdfAnnotationLineEnding, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, quadToRect, pdfDateToDate, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, toIntRect, transformRect, makeMatrix, toIntSize, transformSize, PdfActionType, PdfZoomMode, MatchFlag, rectToQuad } from "@embedpdf/models";
1
+ import { NoopLogger, PdfTaskHelper, PdfErrorCode, Rotation, Task, ignore, PdfAnnotationSubtype, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, isUuidV4, uuidV4, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, pdfDateToDate, dateToPdfDate, quadToRect, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, toIntRect, transformRect, makeMatrix, toIntSize, transformSize, PdfActionType, PdfZoomMode, MatchFlag, rectToQuad } from "@embedpdf/models";
2
2
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
3
3
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
4
4
  for (let i = 0; i < defaultLength; i++) {
@@ -68,6 +68,10 @@ class DocumentContext {
68
68
  acquirePage(pageIdx) {
69
69
  return this.pageCache.acquire(pageIdx);
70
70
  }
71
+ /** Scoped accessor for one-off / bulk operations */
72
+ borrowPage(pageIdx, fn) {
73
+ return this.pageCache.borrowPage(pageIdx, fn);
74
+ }
71
75
  /** Tear down all pages + this document */
72
76
  dispose() {
73
77
  this.pageCache.forceReleaseAll();
@@ -94,6 +98,19 @@ class PageCache {
94
98
  ctx.bumpRefCount();
95
99
  return ctx;
96
100
  }
101
+ /** Helper: run a function “scoped” to a page.
102
+ * – if the page was already cached → .release() (keeps TTL logic)
103
+ * – if the page was loaded just now → .disposeImmediate() (free right away)
104
+ */
105
+ borrowPage(pageIdx, fn) {
106
+ const existed = this.cache.has(pageIdx);
107
+ const ctx = this.acquire(pageIdx);
108
+ try {
109
+ return fn(ctx);
110
+ } finally {
111
+ existed ? ctx.release() : ctx.disposeImmediate();
112
+ }
113
+ }
97
114
  forceReleaseAll() {
98
115
  for (const ctx of this.cache.values()) {
99
116
  ctx.disposeImmediate();
@@ -841,19 +858,41 @@ class PdfiumEngine {
841
858
  * @public
842
859
  */
843
860
  getAllAnnotations(doc) {
844
- this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getAllAnnotations", doc);
845
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetAllAnnotations`, "Begin", doc.id);
861
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getAllAnnotations-with-progress", doc);
862
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "Begin", doc.id);
863
+ const task = PdfTaskHelper.create();
864
+ let cancelled = false;
865
+ task.wait(ignore, (err) => {
866
+ if (err.type === "abort") cancelled = true;
867
+ });
846
868
  const ctx = this.cache.getContext(doc.id);
847
869
  if (!ctx) {
848
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetAllAnnotations`, "End", doc.id);
849
- return PdfTaskHelper.reject({
850
- code: PdfErrorCode.DocNotOpen,
851
- message: "document does not open"
852
- });
853
- }
854
- const annotations = this.readAllAnnotations(doc, ctx);
855
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `GetAllAnnotations`, "End", doc.id);
856
- return PdfTaskHelper.resolve(annotations);
870
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "End", doc.id);
871
+ task.reject({ code: PdfErrorCode.DocNotOpen, message: "document does not open" });
872
+ return task;
873
+ }
874
+ const CHUNK_SIZE = 100;
875
+ const out = {};
876
+ const processChunk = (startIdx) => {
877
+ if (cancelled) return;
878
+ const endIdx = Math.min(startIdx + CHUNK_SIZE, doc.pageCount);
879
+ for (let pageIdx = startIdx; pageIdx < endIdx && !cancelled; ++pageIdx) {
880
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "Begin", doc.id, pageIdx);
881
+ const annots = this.readPageAnnotationsRaw(ctx, doc.pages[pageIdx]);
882
+ out[pageIdx] = annots;
883
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "End", doc.id, pageIdx);
884
+ task.progress({ page: pageIdx, annotations: annots });
885
+ }
886
+ if (cancelled) return;
887
+ if (endIdx >= doc.pageCount) {
888
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "GetAllAnnotations", "End", doc.id);
889
+ task.resolve(out);
890
+ return;
891
+ }
892
+ setTimeout(() => processChunk(endIdx), 0);
893
+ };
894
+ processChunk(0);
895
+ return task;
857
896
  }
858
897
  readAllAnnotations(doc, ctx) {
859
898
  const annotationsByPage = {};
@@ -937,7 +976,7 @@ class PdfiumEngine {
937
976
  });
938
977
  }
939
978
  const pageCtx = ctx.acquirePage(page.index);
940
- const annotationPtr = this.pdfiumModule.FPDFPage_CreateAnnot(pageCtx.pagePtr, annotation.type);
979
+ const annotationPtr = this.pdfiumModule.EPDFPage_CreateAnnot(pageCtx.pagePtr, annotation.type);
941
980
  if (!annotationPtr) {
942
981
  this.logger.perf(
943
982
  LOG_SOURCE,
@@ -952,6 +991,14 @@ class PdfiumEngine {
952
991
  message: "can not create annotation with specified type"
953
992
  });
954
993
  }
994
+ if (!this.setAnnotString(annotationPtr, "NM", annotation.id)) {
995
+ this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);
996
+ pageCtx.release();
997
+ return PdfTaskHelper.reject({
998
+ code: PdfErrorCode.CantSetAnnotString,
999
+ message: "can not set the name of the annotation"
1000
+ });
1001
+ }
955
1002
  if (!this.setPageAnnoRect(page, pageCtx.pagePtr, annotationPtr, annotation.rect)) {
956
1003
  this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);
957
1004
  pageCtx.release();
@@ -982,6 +1029,9 @@ class PdfiumEngine {
982
1029
  context == null ? void 0 : context.imageData
983
1030
  );
984
1031
  break;
1032
+ case PdfAnnotationSubtype.TEXT:
1033
+ isSucceed = this.addTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);
1034
+ break;
985
1035
  case PdfAnnotationSubtype.FREETEXT:
986
1036
  isSucceed = this.addFreeTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);
987
1037
  break;
@@ -1072,7 +1122,7 @@ class PdfiumEngine {
1072
1122
  });
1073
1123
  }
1074
1124
  const pageCtx = ctx.acquirePage(page.index);
1075
- const annotPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, annotation.id);
1125
+ const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
1076
1126
  if (!annotPtr) {
1077
1127
  pageCtx.release();
1078
1128
  this.logger.perf(
@@ -1112,6 +1162,10 @@ class PdfiumEngine {
1112
1162
  ok = this.addStampContent(ctx.docPtr, page, pageCtx.pagePtr, annotPtr, annotation);
1113
1163
  break;
1114
1164
  }
1165
+ case PdfAnnotationSubtype.TEXT: {
1166
+ ok = this.addTextContent(page, pageCtx.pagePtr, annotPtr, annotation);
1167
+ break;
1168
+ }
1115
1169
  /* ── Free text ────────────────────────────────────────────────────────── */
1116
1170
  case PdfAnnotationSubtype.FREETEXT: {
1117
1171
  ok = this.addFreeTextContent(page, pageCtx.pagePtr, annotPtr, annotation);
@@ -1198,7 +1252,7 @@ class PdfiumEngine {
1198
1252
  }
1199
1253
  const pageCtx = ctx.acquirePage(page.index);
1200
1254
  let result = false;
1201
- result = this.pdfiumModule.FPDFPage_RemoveAnnot(pageCtx.pagePtr, annotation.id);
1255
+ result = this.removeAnnotationByName(pageCtx.pagePtr, annotation.id);
1202
1256
  if (!result) {
1203
1257
  this.logger.error(
1204
1258
  LOG_SOURCE,
@@ -1429,7 +1483,18 @@ class PdfiumEngine {
1429
1483
  );
1430
1484
  const pageCtx = ctx.acquirePage(page.index);
1431
1485
  this.pdfiumModule.FORM_OnAfterLoadPage(pageCtx.pagePtr, formHandle);
1432
- const annotationPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, annotation.id);
1486
+ const annotationPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
1487
+ if (!annotationPtr) {
1488
+ pageCtx.release();
1489
+ this.logger.perf(
1490
+ LOG_SOURCE,
1491
+ LOG_CATEGORY,
1492
+ "SetFormFieldValue",
1493
+ "End",
1494
+ `${doc.id}-${page.index}`
1495
+ );
1496
+ return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "annotation not found" });
1497
+ }
1433
1498
  if (!this.pdfiumModule.FORM_SetFocusedAnnot(formHandle, annotationPtr)) {
1434
1499
  this.logger.debug(
1435
1500
  LOG_SOURCE,
@@ -1918,7 +1983,66 @@ class PdfiumEngine {
1918
1983
  free(ptr) {
1919
1984
  this.pdfiumModule.pdfium.wasmExports.free(ptr);
1920
1985
  }
1986
+ /**
1987
+ * Add text content to annotation
1988
+ * @param page - page info
1989
+ * @param pagePtr - pointer to page object
1990
+ * @param annotationPtr - pointer to text annotation
1991
+ * @param annotation - text annotation
1992
+ * @returns whether text content is added to annotation
1993
+ *
1994
+ * @private
1995
+ */
1996
+ addTextContent(page, pagePtr, annotationPtr, annotation) {
1997
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
1998
+ return false;
1999
+ }
2000
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2001
+ return false;
2002
+ }
2003
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2004
+ return false;
2005
+ }
2006
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2007
+ return false;
2008
+ }
2009
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2010
+ return false;
2011
+ }
2012
+ if (annotation.inReplyToId && !this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)) {
2013
+ return false;
2014
+ }
2015
+ if (!this.setAnnotationIcon(annotationPtr, annotation.icon || PdfAnnotationIcon.Comment)) {
2016
+ return false;
2017
+ }
2018
+ if (!this.setAnnotationFlags(annotationPtr, annotation.flags || ["print", "noZoom", "noRotate"])) {
2019
+ return false;
2020
+ }
2021
+ if (annotation.state && !this.setAnnotString(annotationPtr, "State", annotation.state)) {
2022
+ return false;
2023
+ }
2024
+ if (annotation.stateModel && !this.setAnnotString(annotationPtr, "StateModel", annotation.stateModel)) {
2025
+ return false;
2026
+ }
2027
+ return true;
2028
+ }
2029
+ /**
2030
+ * Add free text content to annotation
2031
+ * @param page - page info
2032
+ * @param pagePtr - pointer to page object
2033
+ * @param annotationPtr - pointer to free text annotation
2034
+ * @param annotation - free text annotation
2035
+ * @returns whether free text content is added to annotation
2036
+ *
2037
+ * @private
2038
+ */
1921
2039
  addFreeTextContent(page, pagePtr, annotationPtr, annotation) {
2040
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2041
+ return false;
2042
+ }
2043
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2044
+ return false;
2045
+ }
1922
2046
  if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
1923
2047
  return false;
1924
2048
  }
@@ -1931,9 +2055,6 @@ class PdfiumEngine {
1931
2055
  if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
1932
2056
  return false;
1933
2057
  }
1934
- if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1935
- return false;
1936
- }
1937
2058
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
1938
2059
  return false;
1939
2060
  }
@@ -1978,6 +2099,15 @@ class PdfiumEngine {
1978
2099
  * @private
1979
2100
  */
1980
2101
  addInkStroke(page, pagePtr, annotationPtr, annotation) {
2102
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2103
+ return false;
2104
+ }
2105
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2106
+ return false;
2107
+ }
2108
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2109
+ return false;
2110
+ }
1981
2111
  if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, annotation.strokeWidth)) {
1982
2112
  return false;
1983
2113
  }
@@ -1990,9 +2120,6 @@ class PdfiumEngine {
1990
2120
  if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
1991
2121
  return false;
1992
2122
  }
1993
- if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1994
- return false;
1995
- }
1996
2123
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
1997
2124
  return false;
1998
2125
  }
@@ -2017,6 +2144,12 @@ class PdfiumEngine {
2017
2144
  */
2018
2145
  addLineContent(page, pagePtr, annotationPtr, annotation) {
2019
2146
  var _a, _b;
2147
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2148
+ return false;
2149
+ }
2150
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2151
+ return false;
2152
+ }
2020
2153
  if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2021
2154
  return false;
2022
2155
  }
@@ -2041,9 +2174,6 @@ class PdfiumEngine {
2041
2174
  if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2042
2175
  return false;
2043
2176
  }
2044
- if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2045
- return false;
2046
- }
2047
2177
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2048
2178
  return false;
2049
2179
  }
@@ -2088,6 +2218,12 @@ class PdfiumEngine {
2088
2218
  */
2089
2219
  addPolyContent(page, pagePtr, annotationPtr, annotation) {
2090
2220
  var _a, _b;
2221
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2222
+ return false;
2223
+ }
2224
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2225
+ return false;
2226
+ }
2091
2227
  if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2092
2228
  return false;
2093
2229
  }
@@ -2107,9 +2243,6 @@ class PdfiumEngine {
2107
2243
  if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2108
2244
  return false;
2109
2245
  }
2110
- if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2111
- return false;
2112
- }
2113
2246
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2114
2247
  return false;
2115
2248
  }
@@ -2153,6 +2286,12 @@ class PdfiumEngine {
2153
2286
  * @private
2154
2287
  */
2155
2288
  addShapeContent(page, pagePtr, annotationPtr, annotation) {
2289
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2290
+ return false;
2291
+ }
2292
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2293
+ return false;
2294
+ }
2156
2295
  if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2157
2296
  return false;
2158
2297
  }
@@ -2162,9 +2301,6 @@ class PdfiumEngine {
2162
2301
  if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2163
2302
  return false;
2164
2303
  }
2165
- if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2166
- return false;
2167
- }
2168
2304
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2169
2305
  return false;
2170
2306
  }
@@ -2207,6 +2343,12 @@ class PdfiumEngine {
2207
2343
  * @private
2208
2344
  */
2209
2345
  addTextMarkupContent(page, pagePtr, annotationPtr, annotation) {
2346
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2347
+ return false;
2348
+ }
2349
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2350
+ return false;
2351
+ }
2210
2352
  if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2211
2353
  return false;
2212
2354
  }
@@ -2219,9 +2361,6 @@ class PdfiumEngine {
2219
2361
  if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2220
2362
  return false;
2221
2363
  }
2222
- if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2223
- return false;
2224
- }
2225
2364
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2226
2365
  return false;
2227
2366
  }
@@ -2247,6 +2386,15 @@ class PdfiumEngine {
2247
2386
  * @private
2248
2387
  */
2249
2388
  addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
2389
+ if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2390
+ return false;
2391
+ }
2392
+ if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2393
+ return false;
2394
+ }
2395
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2396
+ return false;
2397
+ }
2250
2398
  if (imageData) {
2251
2399
  for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
2252
2400
  this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
@@ -2836,18 +2984,33 @@ class PdfiumEngine {
2836
2984
  * @private
2837
2985
  */
2838
2986
  readPageAnnotations(ctx, page) {
2839
- const pageCtx = ctx.acquirePage(page.index);
2840
- const annotationCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);
2841
- const annotations = [];
2842
- for (let i = 0; i < annotationCount; i++) {
2843
- pageCtx.withAnnotation(i, (annotPtr) => {
2844
- const annotation = this.readPageAnnotation(page, pageCtx, annotPtr, i);
2845
- if (annotation) {
2846
- annotations.push(annotation);
2847
- }
2848
- });
2987
+ return ctx.borrowPage(page.index, (pageCtx) => {
2988
+ const annotationCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);
2989
+ const annotations = [];
2990
+ for (let i = 0; i < annotationCount; i++) {
2991
+ pageCtx.withAnnotation(i, (annotPtr) => {
2992
+ const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr, pageCtx);
2993
+ if (anno) annotations.push(anno);
2994
+ });
2995
+ }
2996
+ return annotations;
2997
+ });
2998
+ }
2999
+ readPageAnnotationsRaw(ctx, page) {
3000
+ const count = this.pdfiumModule.EPDFPage_GetAnnotCountRaw(ctx.docPtr, page.index);
3001
+ if (count <= 0) return [];
3002
+ const out = [];
3003
+ for (let i = 0; i < count; ++i) {
3004
+ const annotPtr = this.pdfiumModule.EPDFPage_GetAnnotRaw(ctx.docPtr, page.index, i);
3005
+ if (!annotPtr) continue;
3006
+ try {
3007
+ const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr);
3008
+ if (anno) out.push(anno);
3009
+ } finally {
3010
+ this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
3011
+ }
2849
3012
  }
2850
- return annotations;
3013
+ return out;
2851
3014
  }
2852
3015
  /**
2853
3016
  * Read pdf annotation from pdf document
@@ -2863,7 +3026,12 @@ class PdfiumEngine {
2863
3026
  *
2864
3027
  * @private
2865
3028
  */
2866
- readPageAnnotation(page, pageCtx, annotationPtr, index) {
3029
+ readPageAnnotation(docPtr, page, annotationPtr, pageCtx) {
3030
+ let index = this.getAnnotString(annotationPtr, "NM");
3031
+ if (!index || !isUuidV4(index)) {
3032
+ index = uuidV4();
3033
+ this.setAnnotString(annotationPtr, "NM", index);
3034
+ }
2867
3035
  const subType = this.pdfiumModule.FPDFAnnot_GetSubtype(
2868
3036
  annotationPtr
2869
3037
  );
@@ -2871,109 +3039,89 @@ class PdfiumEngine {
2871
3039
  switch (subType) {
2872
3040
  case PdfAnnotationSubtype.TEXT:
2873
3041
  {
2874
- annotation = this.readPdfTextAnno(page, pageCtx.pagePtr, annotationPtr, index);
3042
+ annotation = this.readPdfTextAnno(page, annotationPtr, index);
2875
3043
  }
2876
3044
  break;
2877
3045
  case PdfAnnotationSubtype.FREETEXT:
2878
3046
  {
2879
- annotation = this.readPdfFreeTextAnno(page, pageCtx.pagePtr, annotationPtr, index);
3047
+ annotation = this.readPdfFreeTextAnno(page, annotationPtr, index);
2880
3048
  }
2881
3049
  break;
2882
3050
  case PdfAnnotationSubtype.LINK:
2883
3051
  {
2884
- annotation = this.readPdfLinkAnno(
2885
- page,
2886
- pageCtx.docPtr,
2887
- pageCtx.pagePtr,
2888
- pageCtx.getTextPage(),
2889
- annotationPtr,
2890
- index
2891
- );
3052
+ annotation = this.readPdfLinkAnno(page, docPtr, annotationPtr, index);
2892
3053
  }
2893
3054
  break;
2894
3055
  case PdfAnnotationSubtype.WIDGET:
2895
- {
2896
- annotation = this.readPdfWidgetAnno(
2897
- page,
2898
- pageCtx.pagePtr,
2899
- annotationPtr,
2900
- pageCtx.getFormHandle(),
2901
- index
2902
- );
3056
+ if (pageCtx) {
3057
+ return this.readPdfWidgetAnno(page, annotationPtr, pageCtx.getFormHandle(), index);
2903
3058
  }
2904
- break;
2905
3059
  case PdfAnnotationSubtype.FILEATTACHMENT:
2906
3060
  {
2907
- annotation = this.readPdfFileAttachmentAnno(page, pageCtx.pagePtr, annotationPtr, index);
3061
+ annotation = this.readPdfFileAttachmentAnno(page, annotationPtr, index);
2908
3062
  }
2909
3063
  break;
2910
3064
  case PdfAnnotationSubtype.INK:
2911
3065
  {
2912
- annotation = this.readPdfInkAnno(page, pageCtx.pagePtr, annotationPtr, index);
3066
+ annotation = this.readPdfInkAnno(page, annotationPtr, index);
2913
3067
  }
2914
3068
  break;
2915
3069
  case PdfAnnotationSubtype.POLYGON:
2916
3070
  {
2917
- annotation = this.readPdfPolygonAnno(page, pageCtx.pagePtr, annotationPtr, index);
3071
+ annotation = this.readPdfPolygonAnno(page, annotationPtr, index);
2918
3072
  }
2919
3073
  break;
2920
3074
  case PdfAnnotationSubtype.POLYLINE:
2921
3075
  {
2922
- annotation = this.readPdfPolylineAnno(page, pageCtx.pagePtr, annotationPtr, index);
3076
+ annotation = this.readPdfPolylineAnno(page, annotationPtr, index);
2923
3077
  }
2924
3078
  break;
2925
3079
  case PdfAnnotationSubtype.LINE:
2926
3080
  {
2927
- annotation = this.readPdfLineAnno(page, pageCtx.pagePtr, annotationPtr, index);
3081
+ annotation = this.readPdfLineAnno(page, annotationPtr, index);
2928
3082
  }
2929
3083
  break;
2930
3084
  case PdfAnnotationSubtype.HIGHLIGHT:
2931
- annotation = this.readPdfHighlightAnno(page, pageCtx.pagePtr, annotationPtr, index);
3085
+ annotation = this.readPdfHighlightAnno(page, annotationPtr, index);
2932
3086
  break;
2933
3087
  case PdfAnnotationSubtype.STAMP:
2934
3088
  {
2935
- annotation = this.readPdfStampAnno(
2936
- pageCtx.docPtr,
2937
- page,
2938
- pageCtx.pagePtr,
2939
- annotationPtr,
2940
- index
2941
- );
3089
+ annotation = this.readPdfStampAnno(page, annotationPtr, index);
2942
3090
  }
2943
3091
  break;
2944
3092
  case PdfAnnotationSubtype.SQUARE:
2945
3093
  {
2946
- annotation = this.readPdfSquareAnno(page, pageCtx.pagePtr, annotationPtr, index);
3094
+ annotation = this.readPdfSquareAnno(page, annotationPtr, index);
2947
3095
  }
2948
3096
  break;
2949
3097
  case PdfAnnotationSubtype.CIRCLE:
2950
3098
  {
2951
- annotation = this.readPdfCircleAnno(page, pageCtx.pagePtr, annotationPtr, index);
3099
+ annotation = this.readPdfCircleAnno(page, annotationPtr, index);
2952
3100
  }
2953
3101
  break;
2954
3102
  case PdfAnnotationSubtype.UNDERLINE:
2955
3103
  {
2956
- annotation = this.readPdfUnderlineAnno(page, pageCtx.pagePtr, annotationPtr, index);
3104
+ annotation = this.readPdfUnderlineAnno(page, annotationPtr, index);
2957
3105
  }
2958
3106
  break;
2959
3107
  case PdfAnnotationSubtype.SQUIGGLY:
2960
3108
  {
2961
- annotation = this.readPdfSquigglyAnno(page, pageCtx.pagePtr, annotationPtr, index);
3109
+ annotation = this.readPdfSquigglyAnno(page, annotationPtr, index);
2962
3110
  }
2963
3111
  break;
2964
3112
  case PdfAnnotationSubtype.STRIKEOUT:
2965
3113
  {
2966
- annotation = this.readPdfStrikeOutAnno(page, pageCtx.pagePtr, annotationPtr, index);
3114
+ annotation = this.readPdfStrikeOutAnno(page, annotationPtr, index);
2967
3115
  }
2968
3116
  break;
2969
3117
  case PdfAnnotationSubtype.CARET:
2970
3118
  {
2971
- annotation = this.readPdfCaretAnno(page, pageCtx.pagePtr, annotationPtr, index);
3119
+ annotation = this.readPdfCaretAnno(page, annotationPtr, index);
2972
3120
  }
2973
3121
  break;
2974
3122
  default:
2975
3123
  {
2976
- annotation = this.readPdfAnno(page, pageCtx.pagePtr, subType, annotationPtr, index);
3124
+ annotation = this.readPdfAnno(page, subType, annotationPtr, index);
2977
3125
  }
2978
3126
  break;
2979
3127
  }
@@ -3198,6 +3346,25 @@ class PdfiumEngine {
3198
3346
  setBorderStyle(annotationPtr, style, width) {
3199
3347
  return this.pdfiumModule.EPDFAnnot_SetBorderStyle(annotationPtr, style, width);
3200
3348
  }
3349
+ /**
3350
+ * Get the icon of the annotation
3351
+ *
3352
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3353
+ * @returns `PdfAnnotationIcon`
3354
+ */
3355
+ getAnnotationIcon(annotationPtr) {
3356
+ return this.pdfiumModule.EPDFAnnot_GetIcon(annotationPtr);
3357
+ }
3358
+ /**
3359
+ * Set the icon of the annotation
3360
+ *
3361
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3362
+ * @param icon - `PdfAnnotationIcon`
3363
+ * @returns `true` on success
3364
+ */
3365
+ setAnnotationIcon(annotationPtr, icon) {
3366
+ return this.pdfiumModule.EPDFAnnot_SetIcon(annotationPtr, icon);
3367
+ }
3201
3368
  /**
3202
3369
  * Border-effect (“cloudy”) helper
3203
3370
  *
@@ -3249,6 +3416,29 @@ class PdfiumEngine {
3249
3416
  this.free(bPtr);
3250
3417
  return { ok, left, top, right, bottom };
3251
3418
  }
3419
+ /**
3420
+ * Get the date of the annotation
3421
+ *
3422
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3423
+ * @param key - 'M' for modified date, 'CreationDate' for creation date
3424
+ * @returns `Date` or `undefined` when PDFium can't read the date
3425
+ */
3426
+ getAnnotationDate(annotationPtr, key) {
3427
+ const raw = this.getAnnotString(annotationPtr, key);
3428
+ return raw ? pdfDateToDate(raw) : void 0;
3429
+ }
3430
+ /**
3431
+ * Set the date of the annotation
3432
+ *
3433
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3434
+ * @param key - 'M' for modified date, 'CreationDate' for creation date
3435
+ * @param date - `Date` to set
3436
+ * @returns `true` on success
3437
+ */
3438
+ setAnnotationDate(annotationPtr, key, date) {
3439
+ const raw = dateToPdfDate(date);
3440
+ return this.setAnnotString(annotationPtr, key, raw);
3441
+ }
3252
3442
  /**
3253
3443
  * Dash-pattern helper ( /BS → /D array, dashed borders only )
3254
3444
  *
@@ -3542,28 +3732,30 @@ class PdfiumEngine {
3542
3732
  /**
3543
3733
  * Read pdf text annotation
3544
3734
  * @param page - pdf page infor
3545
- * @param pagePtr - pointer to pdf page object
3546
3735
  * @param annotationPtr - pointer to pdf annotation
3547
3736
  * @param index - index of annotation in the pdf page
3548
3737
  * @returns pdf text annotation
3549
3738
  *
3550
3739
  * @private
3551
3740
  */
3552
- readPdfTextAnno(page, pagePtr, annotationPtr, index) {
3741
+ readPdfTextAnno(page, annotationPtr, index) {
3742
+ const custom = this.getAnnotCustom(annotationPtr);
3553
3743
  const annoRect = this.readPageAnnoRect(annotationPtr);
3554
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, annoRect);
3744
+ const rect = this.convertPageRectToDeviceRect(page, annoRect);
3555
3745
  const author = this.getAnnotString(annotationPtr, "T");
3556
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3557
- const modified = pdfDateToDate(modifiedRaw);
3746
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3747
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3558
3748
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3559
3749
  const state = this.getAnnotString(annotationPtr, "State");
3560
3750
  const stateModel = this.getAnnotString(annotationPtr, "StateModel");
3561
3751
  const color = this.getAnnotationColor(annotationPtr);
3562
3752
  const opacity = this.getAnnotationOpacity(annotationPtr);
3563
- const inReplyToId = this.getInReplyToId(pagePtr, annotationPtr);
3753
+ const inReplyToId = this.getInReplyToId(annotationPtr);
3564
3754
  const flags = this.getAnnotationFlags(annotationPtr);
3755
+ const icon = this.getAnnotationIcon(annotationPtr);
3565
3756
  return {
3566
3757
  pageIndex: page.index,
3758
+ custom,
3567
3759
  id: index,
3568
3760
  type: PdfAnnotationSubtype.TEXT,
3569
3761
  flags,
@@ -3574,37 +3766,40 @@ class PdfiumEngine {
3574
3766
  inReplyToId,
3575
3767
  author,
3576
3768
  modified,
3769
+ created,
3577
3770
  state,
3578
- stateModel
3771
+ stateModel,
3772
+ icon
3579
3773
  };
3580
3774
  }
3581
3775
  /**
3582
3776
  * Read pdf freetext annotation
3583
3777
  * @param page - pdf page infor
3584
- * @param pagePtr - pointer to pdf page object
3585
3778
  * @param annotationPtr - pointer to pdf annotation
3586
3779
  * @param index - index of annotation in the pdf page
3587
3780
  * @returns pdf freetext annotation
3588
3781
  *
3589
3782
  * @private
3590
3783
  */
3591
- readPdfFreeTextAnno(page, pagePtr, annotationPtr, index) {
3784
+ readPdfFreeTextAnno(page, annotationPtr, index) {
3785
+ const custom = this.getAnnotCustom(annotationPtr);
3592
3786
  const annoRect = this.readPageAnnoRect(annotationPtr);
3593
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, annoRect);
3787
+ const rect = this.convertPageRectToDeviceRect(page, annoRect);
3594
3788
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3595
3789
  const author = this.getAnnotString(annotationPtr, "T");
3596
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3790
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3791
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3597
3792
  const defaultStyle = this.getAnnotString(annotationPtr, "DS");
3598
3793
  const da = this.getAnnotationDefaultAppearance(annotationPtr);
3599
3794
  const backgroundColor = this.getAnnotationColor(annotationPtr);
3600
3795
  const textAlign = this.getAnnotationTextAlignment(annotationPtr);
3601
3796
  const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
3602
3797
  const opacity = this.getAnnotationOpacity(annotationPtr);
3603
- const modified = pdfDateToDate(modifiedRaw);
3604
3798
  const richContent = this.getAnnotRichContent(annotationPtr);
3605
3799
  const flags = this.getAnnotationFlags(annotationPtr);
3606
3800
  return {
3607
3801
  pageIndex: page.index,
3802
+ custom,
3608
3803
  id: index,
3609
3804
  type: PdfAnnotationSubtype.FREETEXT,
3610
3805
  fontFamily: (da == null ? void 0 : da.fontFamily) ?? PdfStandardFont.Unknown,
@@ -3620,6 +3815,7 @@ class PdfiumEngine {
3620
3815
  contents,
3621
3816
  author,
3622
3817
  modified,
3818
+ created,
3623
3819
  rect
3624
3820
  };
3625
3821
  }
@@ -3627,48 +3823,24 @@ class PdfiumEngine {
3627
3823
  * Read pdf link annotation from pdf document
3628
3824
  * @param page - pdf page infor
3629
3825
  * @param docPtr - pointer to pdf document object
3630
- * @param pagePtr - pointer to pdf page object
3631
- * @param textPagePtr - pointer to pdf text page object
3632
3826
  * @param annotationPtr - pointer to pdf annotation
3633
3827
  * @param index - index of annotation in the pdf page
3634
3828
  * @returns pdf link annotation
3635
3829
  *
3636
3830
  * @private
3637
3831
  */
3638
- readPdfLinkAnno(page, docPtr, pagePtr, textPagePtr, annotationPtr, index) {
3832
+ readPdfLinkAnno(page, docPtr, annotationPtr, index) {
3833
+ const custom = this.getAnnotCustom(annotationPtr);
3639
3834
  const linkPtr = this.pdfiumModule.FPDFAnnot_GetLink(annotationPtr);
3640
3835
  if (!linkPtr) {
3641
3836
  return;
3642
3837
  }
3643
3838
  const annoRect = this.readPageAnnoRect(annotationPtr);
3644
- const { left, top, right, bottom } = annoRect;
3645
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, annoRect);
3839
+ const rect = this.convertPageRectToDeviceRect(page, annoRect);
3646
3840
  const author = this.getAnnotString(annotationPtr, "T");
3647
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3648
- const modified = pdfDateToDate(modifiedRaw);
3841
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3842
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3649
3843
  const flags = this.getAnnotationFlags(annotationPtr);
3650
- const utf16Length = this.pdfiumModule.FPDFText_GetBoundedText(
3651
- textPagePtr,
3652
- left,
3653
- top,
3654
- right,
3655
- bottom,
3656
- 0,
3657
- 0
3658
- );
3659
- const bytesCount = (utf16Length + 1) * 2;
3660
- const textBufferPtr = this.malloc(bytesCount);
3661
- this.pdfiumModule.FPDFText_GetBoundedText(
3662
- textPagePtr,
3663
- left,
3664
- top,
3665
- right,
3666
- bottom,
3667
- textBufferPtr,
3668
- utf16Length
3669
- );
3670
- const text = this.pdfiumModule.pdfium.UTF16ToString(textBufferPtr);
3671
- this.free(textBufferPtr);
3672
3844
  const target = this.readPdfLinkAnnoTarget(
3673
3845
  docPtr,
3674
3846
  () => {
@@ -3680,20 +3852,20 @@ class PdfiumEngine {
3680
3852
  );
3681
3853
  return {
3682
3854
  pageIndex: page.index,
3855
+ custom,
3683
3856
  id: index,
3684
3857
  type: PdfAnnotationSubtype.LINK,
3685
3858
  flags,
3686
- text,
3687
3859
  target,
3688
3860
  rect,
3689
3861
  author,
3690
- modified
3862
+ modified,
3863
+ created
3691
3864
  };
3692
3865
  }
3693
3866
  /**
3694
3867
  * Read pdf widget annotation
3695
3868
  * @param page - pdf page infor
3696
- * @param pagePtr - pointer to pdf page object
3697
3869
  * @param annotationPtr - pointer to pdf annotation
3698
3870
  * @param formHandle - form handle
3699
3871
  * @param index - index of annotation in the pdf page
@@ -3701,68 +3873,73 @@ class PdfiumEngine {
3701
3873
  *
3702
3874
  * @private
3703
3875
  */
3704
- readPdfWidgetAnno(page, pagePtr, annotationPtr, formHandle, index) {
3876
+ readPdfWidgetAnno(page, annotationPtr, formHandle, index) {
3877
+ const custom = this.getAnnotCustom(annotationPtr);
3705
3878
  const pageRect = this.readPageAnnoRect(annotationPtr);
3706
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
3879
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3707
3880
  const author = this.getAnnotString(annotationPtr, "T");
3708
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3709
- const modified = pdfDateToDate(modifiedRaw);
3881
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3882
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3710
3883
  const flags = this.getAnnotationFlags(annotationPtr);
3711
3884
  const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
3712
3885
  return {
3713
3886
  pageIndex: page.index,
3887
+ custom,
3714
3888
  id: index,
3715
3889
  type: PdfAnnotationSubtype.WIDGET,
3716
3890
  flags,
3717
3891
  rect,
3718
3892
  field,
3719
3893
  author,
3720
- modified
3894
+ modified,
3895
+ created
3721
3896
  };
3722
3897
  }
3723
3898
  /**
3724
3899
  * Read pdf file attachment annotation
3725
3900
  * @param page - pdf page infor
3726
- * @param pagePtr - pointer to pdf page object
3727
3901
  * @param annotationPtr - pointer to pdf annotation
3728
3902
  * @param index - index of annotation in the pdf page
3729
3903
  * @returns pdf file attachment annotation
3730
3904
  *
3731
3905
  * @private
3732
3906
  */
3733
- readPdfFileAttachmentAnno(page, pagePtr, annotationPtr, index) {
3907
+ readPdfFileAttachmentAnno(page, annotationPtr, index) {
3908
+ const custom = this.getAnnotCustom(annotationPtr);
3734
3909
  const pageRect = this.readPageAnnoRect(annotationPtr);
3735
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
3910
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3736
3911
  const author = this.getAnnotString(annotationPtr, "T");
3737
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3738
- const modified = pdfDateToDate(modifiedRaw);
3912
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3913
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3739
3914
  const flags = this.getAnnotationFlags(annotationPtr);
3740
3915
  return {
3741
3916
  pageIndex: page.index,
3917
+ custom,
3742
3918
  id: index,
3743
3919
  type: PdfAnnotationSubtype.FILEATTACHMENT,
3744
3920
  flags,
3745
3921
  rect,
3746
3922
  author,
3747
- modified
3923
+ modified,
3924
+ created
3748
3925
  };
3749
3926
  }
3750
3927
  /**
3751
3928
  * Read pdf ink annotation
3752
3929
  * @param page - pdf page infor
3753
- * @param pagePtr - pointer to pdf page object
3754
3930
  * @param annotationPtr - pointer to pdf annotation
3755
3931
  * @param index - index of annotation in the pdf page
3756
3932
  * @returns pdf ink annotation
3757
3933
  *
3758
3934
  * @private
3759
3935
  */
3760
- readPdfInkAnno(page, pagePtr, annotationPtr, index) {
3936
+ readPdfInkAnno(page, annotationPtr, index) {
3937
+ const custom = this.getAnnotCustom(annotationPtr);
3761
3938
  const pageRect = this.readPageAnnoRect(annotationPtr);
3762
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
3939
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3763
3940
  const author = this.getAnnotString(annotationPtr, "T");
3764
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3765
- const modified = pdfDateToDate(modifiedRaw);
3941
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3942
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3766
3943
  const color = this.getAnnotationColor(annotationPtr);
3767
3944
  const opacity = this.getAnnotationOpacity(annotationPtr);
3768
3945
  const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
@@ -3770,11 +3947,14 @@ class PdfiumEngine {
3770
3947
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3771
3948
  const intent = this.getAnnotIntent(annotationPtr);
3772
3949
  const flags = this.getAnnotationFlags(annotationPtr);
3950
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3773
3951
  return {
3774
3952
  pageIndex: page.index,
3953
+ custom,
3775
3954
  id: index,
3776
3955
  type: PdfAnnotationSubtype.INK,
3777
3956
  ...intent && { intent },
3957
+ contents,
3778
3958
  blendMode,
3779
3959
  flags,
3780
3960
  color: color ?? "#FF0000",
@@ -3783,26 +3963,27 @@ class PdfiumEngine {
3783
3963
  rect,
3784
3964
  inkList,
3785
3965
  author,
3786
- modified
3966
+ modified,
3967
+ created
3787
3968
  };
3788
3969
  }
3789
3970
  /**
3790
3971
  * Read pdf polygon annotation
3791
3972
  * @param page - pdf page infor
3792
- * @param pagePtr - pointer to pdf page object
3793
3973
  * @param annotationPtr - pointer to pdf annotation
3794
3974
  * @param index - index of annotation in the pdf page
3795
3975
  * @returns pdf polygon annotation
3796
3976
  *
3797
3977
  * @private
3798
3978
  */
3799
- readPdfPolygonAnno(page, pagePtr, annotationPtr, index) {
3979
+ readPdfPolygonAnno(page, annotationPtr, index) {
3980
+ const custom = this.getAnnotCustom(annotationPtr);
3800
3981
  const pageRect = this.readPageAnnoRect(annotationPtr);
3801
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
3982
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3802
3983
  const author = this.getAnnotString(annotationPtr, "T");
3803
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3804
- const modified = pdfDateToDate(modifiedRaw);
3805
- const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3984
+ const modified = this.getAnnotationDate(annotationPtr, "M");
3985
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3986
+ const vertices = this.readPdfAnnoVertices(page, annotationPtr);
3806
3987
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3807
3988
  const flags = this.getAnnotationFlags(annotationPtr);
3808
3989
  const strokeColor = this.getAnnotationColor(annotationPtr);
@@ -3828,6 +4009,7 @@ class PdfiumEngine {
3828
4009
  }
3829
4010
  return {
3830
4011
  pageIndex: page.index,
4012
+ custom,
3831
4013
  id: index,
3832
4014
  type: PdfAnnotationSubtype.POLYGON,
3833
4015
  contents,
@@ -3841,26 +4023,27 @@ class PdfiumEngine {
3841
4023
  rect,
3842
4024
  vertices,
3843
4025
  author,
3844
- modified
4026
+ modified,
4027
+ created
3845
4028
  };
3846
4029
  }
3847
4030
  /**
3848
4031
  * Read pdf polyline annotation
3849
4032
  * @param page - pdf page infor
3850
- * @param pagePtr - pointer to pdf page object
3851
4033
  * @param annotationPtr - pointer to pdf annotation
3852
4034
  * @param index - index of annotation in the pdf page
3853
4035
  * @returns pdf polyline annotation
3854
4036
  *
3855
4037
  * @private
3856
4038
  */
3857
- readPdfPolylineAnno(page, pagePtr, annotationPtr, index) {
4039
+ readPdfPolylineAnno(page, annotationPtr, index) {
4040
+ const custom = this.getAnnotCustom(annotationPtr);
3858
4041
  const pageRect = this.readPageAnnoRect(annotationPtr);
3859
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4042
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3860
4043
  const author = this.getAnnotString(annotationPtr, "T");
3861
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3862
- const modified = pdfDateToDate(modifiedRaw);
3863
- const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
4044
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4045
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4046
+ const vertices = this.readPdfAnnoVertices(page, annotationPtr);
3864
4047
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3865
4048
  const strokeColor = this.getAnnotationColor(annotationPtr);
3866
4049
  const flags = this.getAnnotationFlags(annotationPtr);
@@ -3880,6 +4063,7 @@ class PdfiumEngine {
3880
4063
  const lineEndings = this.getLineEndings(annotationPtr);
3881
4064
  return {
3882
4065
  pageIndex: page.index,
4066
+ custom,
3883
4067
  id: index,
3884
4068
  type: PdfAnnotationSubtype.POLYLINE,
3885
4069
  contents,
@@ -3894,25 +4078,26 @@ class PdfiumEngine {
3894
4078
  rect,
3895
4079
  vertices,
3896
4080
  author,
3897
- modified
4081
+ modified,
4082
+ created
3898
4083
  };
3899
4084
  }
3900
4085
  /**
3901
4086
  * Read pdf line annotation
3902
4087
  * @param page - pdf page infor
3903
- * @param pagePtr - pointer to pdf page object
3904
4088
  * @param annotationPtr - pointer to pdf annotation
3905
4089
  * @param index - index of annotation in the pdf page
3906
4090
  * @returns pdf line annotation
3907
4091
  *
3908
4092
  * @private
3909
4093
  */
3910
- readPdfLineAnno(page, pagePtr, annotationPtr, index) {
4094
+ readPdfLineAnno(page, annotationPtr, index) {
4095
+ const custom = this.getAnnotCustom(annotationPtr);
3911
4096
  const pageRect = this.readPageAnnoRect(annotationPtr);
3912
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4097
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3913
4098
  const author = this.getAnnotString(annotationPtr, "T");
3914
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3915
- const modified = pdfDateToDate(modifiedRaw);
4099
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4100
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3916
4101
  const linePoints = this.getLinePoints(annotationPtr, page);
3917
4102
  const lineEndings = this.getLineEndings(annotationPtr);
3918
4103
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
@@ -3933,6 +4118,7 @@ class PdfiumEngine {
3933
4118
  }
3934
4119
  return {
3935
4120
  pageIndex: page.index,
4121
+ custom,
3936
4122
  id: index,
3937
4123
  type: PdfAnnotationSubtype.LINE,
3938
4124
  flags,
@@ -3950,33 +4136,35 @@ class PdfiumEngine {
3950
4136
  end: PdfAnnotationLineEnding.None
3951
4137
  },
3952
4138
  author,
3953
- modified
4139
+ modified,
4140
+ created
3954
4141
  };
3955
4142
  }
3956
4143
  /**
3957
4144
  * Read pdf highlight annotation
3958
4145
  * @param page - pdf page infor
3959
- * @param pagePtr - pointer to pdf page object
3960
4146
  * @param annotationPtr - pointer to pdf annotation
3961
4147
  * @param index - index of annotation in the pdf page
3962
4148
  * @returns pdf highlight annotation
3963
4149
  *
3964
4150
  * @private
3965
4151
  */
3966
- readPdfHighlightAnno(page, pagePtr, annotationPtr, index) {
4152
+ readPdfHighlightAnno(page, annotationPtr, index) {
4153
+ const custom = this.getAnnotCustom(annotationPtr);
3967
4154
  const pageRect = this.readPageAnnoRect(annotationPtr);
3968
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4155
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
3969
4156
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3970
4157
  const color = this.getAnnotationColor(annotationPtr);
3971
4158
  const opacity = this.getAnnotationOpacity(annotationPtr);
3972
4159
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3973
4160
  const author = this.getAnnotString(annotationPtr, "T");
3974
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3975
- const modified = pdfDateToDate(modifiedRaw);
4161
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4162
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
3976
4163
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3977
4164
  const flags = this.getAnnotationFlags(annotationPtr);
3978
4165
  return {
3979
4166
  pageIndex: page.index,
4167
+ custom,
3980
4168
  id: index,
3981
4169
  blendMode,
3982
4170
  type: PdfAnnotationSubtype.HIGHLIGHT,
@@ -3987,25 +4175,26 @@ class PdfiumEngine {
3987
4175
  color: color ?? "#FFFF00",
3988
4176
  opacity,
3989
4177
  author,
3990
- modified
4178
+ modified,
4179
+ created
3991
4180
  };
3992
4181
  }
3993
4182
  /**
3994
4183
  * Read pdf underline annotation
3995
4184
  * @param page - pdf page infor
3996
- * @param pagePtr - pointer to pdf page object
3997
4185
  * @param annotationPtr - pointer to pdf annotation
3998
4186
  * @param index - index of annotation in the pdf page
3999
4187
  * @returns pdf underline annotation
4000
4188
  *
4001
4189
  * @private
4002
4190
  */
4003
- readPdfUnderlineAnno(page, pagePtr, annotationPtr, index) {
4191
+ readPdfUnderlineAnno(page, annotationPtr, index) {
4192
+ const custom = this.getAnnotCustom(annotationPtr);
4004
4193
  const pageRect = this.readPageAnnoRect(annotationPtr);
4005
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4194
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4006
4195
  const author = this.getAnnotString(annotationPtr, "T");
4007
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4008
- const modified = pdfDateToDate(modifiedRaw);
4196
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4197
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4009
4198
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
4010
4199
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4011
4200
  const color = this.getAnnotationColor(annotationPtr);
@@ -4014,6 +4203,7 @@ class PdfiumEngine {
4014
4203
  const flags = this.getAnnotationFlags(annotationPtr);
4015
4204
  return {
4016
4205
  pageIndex: page.index,
4206
+ custom,
4017
4207
  id: index,
4018
4208
  blendMode,
4019
4209
  type: PdfAnnotationSubtype.UNDERLINE,
@@ -4024,25 +4214,26 @@ class PdfiumEngine {
4024
4214
  color: color ?? "#FF0000",
4025
4215
  opacity,
4026
4216
  author,
4027
- modified
4217
+ modified,
4218
+ created
4028
4219
  };
4029
4220
  }
4030
4221
  /**
4031
4222
  * Read strikeout annotation
4032
4223
  * @param page - pdf page infor
4033
- * @param pagePtr - pointer to pdf page object
4034
4224
  * @param annotationPtr - pointer to pdf annotation
4035
4225
  * @param index - index of annotation in the pdf page
4036
4226
  * @returns pdf strikeout annotation
4037
4227
  *
4038
4228
  * @private
4039
4229
  */
4040
- readPdfStrikeOutAnno(page, pagePtr, annotationPtr, index) {
4230
+ readPdfStrikeOutAnno(page, annotationPtr, index) {
4231
+ const custom = this.getAnnotCustom(annotationPtr);
4041
4232
  const pageRect = this.readPageAnnoRect(annotationPtr);
4042
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4233
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4043
4234
  const author = this.getAnnotString(annotationPtr, "T");
4044
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4045
- const modified = pdfDateToDate(modifiedRaw);
4235
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4236
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4046
4237
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
4047
4238
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4048
4239
  const color = this.getAnnotationColor(annotationPtr);
@@ -4051,6 +4242,7 @@ class PdfiumEngine {
4051
4242
  const flags = this.getAnnotationFlags(annotationPtr);
4052
4243
  return {
4053
4244
  pageIndex: page.index,
4245
+ custom,
4054
4246
  id: index,
4055
4247
  blendMode,
4056
4248
  type: PdfAnnotationSubtype.STRIKEOUT,
@@ -4061,25 +4253,26 @@ class PdfiumEngine {
4061
4253
  color: color ?? "#FF0000",
4062
4254
  opacity,
4063
4255
  author,
4064
- modified
4256
+ modified,
4257
+ created
4065
4258
  };
4066
4259
  }
4067
4260
  /**
4068
4261
  * Read pdf squiggly annotation
4069
4262
  * @param page - pdf page infor
4070
- * @param pagePtr - pointer to pdf page object
4071
4263
  * @param annotationPtr - pointer to pdf annotation
4072
4264
  * @param index - index of annotation in the pdf page
4073
4265
  * @returns pdf squiggly annotation
4074
4266
  *
4075
4267
  * @private
4076
4268
  */
4077
- readPdfSquigglyAnno(page, pagePtr, annotationPtr, index) {
4269
+ readPdfSquigglyAnno(page, annotationPtr, index) {
4270
+ const custom = this.getAnnotCustom(annotationPtr);
4078
4271
  const pageRect = this.readPageAnnoRect(annotationPtr);
4079
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4272
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4080
4273
  const author = this.getAnnotString(annotationPtr, "T");
4081
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4082
- const modified = pdfDateToDate(modifiedRaw);
4274
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4275
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4083
4276
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
4084
4277
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4085
4278
  const color = this.getAnnotationColor(annotationPtr);
@@ -4088,6 +4281,7 @@ class PdfiumEngine {
4088
4281
  const flags = this.getAnnotationFlags(annotationPtr);
4089
4282
  return {
4090
4283
  pageIndex: page.index,
4284
+ custom,
4091
4285
  id: index,
4092
4286
  blendMode,
4093
4287
  type: PdfAnnotationSubtype.SQUIGGLY,
@@ -4098,61 +4292,67 @@ class PdfiumEngine {
4098
4292
  color: color ?? "#FF0000",
4099
4293
  opacity,
4100
4294
  author,
4101
- modified
4295
+ modified,
4296
+ created
4102
4297
  };
4103
4298
  }
4104
4299
  /**
4105
4300
  * Read pdf caret annotation
4106
4301
  * @param page - pdf page infor
4107
- * @param pagePtr - pointer to pdf page object
4108
4302
  * @param annotationPtr - pointer to pdf annotation
4109
4303
  * @param index - index of annotation in the pdf page
4110
4304
  * @returns pdf caret annotation
4111
4305
  *
4112
4306
  * @private
4113
4307
  */
4114
- readPdfCaretAnno(page, pagePtr, annotationPtr, index) {
4308
+ readPdfCaretAnno(page, annotationPtr, index) {
4309
+ const custom = this.getAnnotCustom(annotationPtr);
4115
4310
  const pageRect = this.readPageAnnoRect(annotationPtr);
4116
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4311
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4117
4312
  const author = this.getAnnotString(annotationPtr, "T");
4118
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4119
- const modified = pdfDateToDate(modifiedRaw);
4313
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4314
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4120
4315
  const flags = this.getAnnotationFlags(annotationPtr);
4121
4316
  return {
4122
4317
  pageIndex: page.index,
4318
+ custom,
4123
4319
  id: index,
4124
4320
  type: PdfAnnotationSubtype.CARET,
4125
4321
  rect,
4126
4322
  flags,
4127
4323
  author,
4128
- modified
4324
+ modified,
4325
+ created
4129
4326
  };
4130
4327
  }
4131
4328
  /**
4132
4329
  * Read pdf stamp annotation
4133
- * @param docPtr - pointer to pdf document object
4134
4330
  * @param page - pdf page infor
4135
- * @param pagePtr - pointer to pdf page object
4136
4331
  * @param annotationPtr - pointer to pdf annotation
4137
4332
  * @param index - index of annotation in the pdf page
4138
4333
  * @returns pdf stamp annotation
4139
4334
  *
4140
4335
  * @private
4141
4336
  */
4142
- readPdfStampAnno(docPtr, page, pagePtr, annotationPtr, index) {
4337
+ readPdfStampAnno(page, annotationPtr, index) {
4338
+ const custom = this.getAnnotCustom(annotationPtr);
4143
4339
  const pageRect = this.readPageAnnoRect(annotationPtr);
4144
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4340
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4145
4341
  const author = this.getAnnotString(annotationPtr, "T");
4146
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4147
- const modified = pdfDateToDate(modifiedRaw);
4342
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4343
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4148
4344
  const flags = this.getAnnotationFlags(annotationPtr);
4345
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4149
4346
  return {
4150
4347
  pageIndex: page.index,
4348
+ custom,
4151
4349
  id: index,
4152
4350
  type: PdfAnnotationSubtype.STAMP,
4351
+ contents,
4153
4352
  rect,
4154
4353
  author,
4155
4354
  modified,
4355
+ created,
4156
4356
  flags
4157
4357
  };
4158
4358
  }
@@ -4378,20 +4578,21 @@ class PdfiumEngine {
4378
4578
  /**
4379
4579
  * Read circle annotation
4380
4580
  * @param page - pdf page infor
4381
- * @param pagePtr - pointer to pdf page object
4382
4581
  * @param annotationPtr - pointer to pdf annotation
4383
4582
  * @param index - index of annotation in the pdf page
4384
4583
  * @returns pdf circle annotation
4385
4584
  *
4386
4585
  * @private
4387
4586
  */
4388
- readPdfCircleAnno(page, pagePtr, annotationPtr, index) {
4587
+ readPdfCircleAnno(page, annotationPtr, index) {
4588
+ const custom = this.getAnnotCustom(annotationPtr);
4389
4589
  const flags = this.getAnnotationFlags(annotationPtr);
4390
4590
  const pageRect = this.readPageAnnoRect(annotationPtr);
4391
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4591
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4392
4592
  const author = this.getAnnotString(annotationPtr, "T");
4393
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4394
- const modified = pdfDateToDate(modifiedRaw);
4593
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4594
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4595
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4395
4596
  const interiorColor = this.getAnnotationColor(
4396
4597
  annotationPtr,
4397
4598
  PdfAnnotationColorType.InteriorColor
@@ -4408,37 +4609,41 @@ class PdfiumEngine {
4408
4609
  }
4409
4610
  return {
4410
4611
  pageIndex: page.index,
4612
+ custom,
4411
4613
  id: index,
4412
4614
  type: PdfAnnotationSubtype.CIRCLE,
4413
4615
  flags,
4414
4616
  color: interiorColor ?? "transparent",
4415
4617
  opacity,
4618
+ contents,
4416
4619
  strokeWidth,
4417
4620
  strokeColor: strokeColor ?? "#FF0000",
4418
4621
  strokeStyle,
4419
4622
  rect,
4420
4623
  author,
4421
4624
  modified,
4625
+ created,
4422
4626
  ...strokeDashArray !== void 0 && { strokeDashArray }
4423
4627
  };
4424
4628
  }
4425
4629
  /**
4426
4630
  * Read square annotation
4427
4631
  * @param page - pdf page infor
4428
- * @param pagePtr - pointer to pdf page object
4429
4632
  * @param annotationPtr - pointer to pdf annotation
4430
4633
  * @param index - index of annotation in the pdf page
4431
4634
  * @returns pdf square annotation
4432
4635
  *
4433
4636
  * @private
4434
4637
  */
4435
- readPdfSquareAnno(page, pagePtr, annotationPtr, index) {
4638
+ readPdfSquareAnno(page, annotationPtr, index) {
4639
+ const custom = this.getAnnotCustom(annotationPtr);
4436
4640
  const flags = this.getAnnotationFlags(annotationPtr);
4437
4641
  const pageRect = this.readPageAnnoRect(annotationPtr);
4438
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4642
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4439
4643
  const author = this.getAnnotString(annotationPtr, "T");
4440
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4441
- const modified = pdfDateToDate(modifiedRaw);
4644
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4645
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4646
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4442
4647
  const interiorColor = this.getAnnotationColor(
4443
4648
  annotationPtr,
4444
4649
  PdfAnnotationColorType.InteriorColor
@@ -4455,24 +4660,26 @@ class PdfiumEngine {
4455
4660
  }
4456
4661
  return {
4457
4662
  pageIndex: page.index,
4663
+ custom,
4458
4664
  id: index,
4459
4665
  type: PdfAnnotationSubtype.SQUARE,
4460
4666
  flags,
4461
4667
  color: interiorColor ?? "transparent",
4462
4668
  opacity,
4669
+ contents,
4463
4670
  strokeColor: strokeColor ?? "#FF0000",
4464
4671
  strokeWidth,
4465
4672
  strokeStyle,
4466
4673
  rect,
4467
4674
  author,
4468
4675
  modified,
4676
+ created,
4469
4677
  ...strokeDashArray !== void 0 && { strokeDashArray }
4470
4678
  };
4471
4679
  }
4472
4680
  /**
4473
4681
  * Read basic info of unsupported pdf annotation
4474
4682
  * @param page - pdf page infor
4475
- * @param pagePtr - pointer to pdf page object
4476
4683
  * @param type - type of annotation
4477
4684
  * @param annotationPtr - pointer to pdf annotation
4478
4685
  * @param index - index of annotation in the pdf page
@@ -4480,21 +4687,24 @@ class PdfiumEngine {
4480
4687
  *
4481
4688
  * @private
4482
4689
  */
4483
- readPdfAnno(page, pagePtr, type, annotationPtr, index) {
4690
+ readPdfAnno(page, type, annotationPtr, index) {
4691
+ const custom = this.getAnnotCustom(annotationPtr);
4484
4692
  const pageRect = this.readPageAnnoRect(annotationPtr);
4485
- const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
4693
+ const rect = this.convertPageRectToDeviceRect(page, pageRect);
4486
4694
  const author = this.getAnnotString(annotationPtr, "T");
4487
- const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4488
- const modified = pdfDateToDate(modifiedRaw);
4695
+ const modified = this.getAnnotationDate(annotationPtr, "M");
4696
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4489
4697
  const flags = this.getAnnotationFlags(annotationPtr);
4490
4698
  return {
4491
4699
  pageIndex: page.index,
4700
+ custom,
4492
4701
  id: index,
4493
4702
  flags,
4494
4703
  type,
4495
4704
  rect,
4496
4705
  author,
4497
- modified
4706
+ modified,
4707
+ created
4498
4708
  };
4499
4709
  }
4500
4710
  /**
@@ -4506,11 +4716,22 @@ class PdfiumEngine {
4506
4716
  *
4507
4717
  * @private
4508
4718
  */
4509
- getInReplyToId(pagePtr, annotationPtr) {
4719
+ getInReplyToId(annotationPtr) {
4510
4720
  const parentPtr = this.pdfiumModule.FPDFAnnot_GetLinkedAnnot(annotationPtr, "IRT");
4511
4721
  if (!parentPtr) return;
4512
- const idx = this.pdfiumModule.FPDFPage_GetAnnotIndex(pagePtr, parentPtr);
4513
- return idx >= 0 ? idx : void 0;
4722
+ return this.getAnnotString(parentPtr, "NM");
4723
+ }
4724
+ /**
4725
+ * Set the in reply to id of the annotation
4726
+ *
4727
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
4728
+ * @param id - the id of the parent annotation
4729
+ * @returns `true` on success
4730
+ */
4731
+ setInReplyToId(pagePtr, annotationPtr, id) {
4732
+ const parentPtr = this.getAnnotationByName(pagePtr, id);
4733
+ if (!parentPtr) return false;
4734
+ return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, "IRT", parentPtr);
4514
4735
  }
4515
4736
  /**
4516
4737
  * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
@@ -4529,6 +4750,41 @@ class PdfiumEngine {
4529
4750
  this.free(ptr);
4530
4751
  return value || void 0;
4531
4752
  }
4753
+ /**
4754
+ * Get custom data of the annotation
4755
+ * @param annotationPtr - pointer to pdf annotation
4756
+ * @returns custom data of the annotation
4757
+ *
4758
+ * @private
4759
+ */
4760
+ getAnnotCustom(annotationPtr) {
4761
+ const custom = this.getAnnotString(annotationPtr, "EPDFCustom");
4762
+ if (!custom) return;
4763
+ try {
4764
+ return JSON.parse(custom);
4765
+ } catch (error) {
4766
+ console.warn("Failed to parse annotation custom data as JSON:", error);
4767
+ console.warn("Invalid JSON string:", custom);
4768
+ return void 0;
4769
+ }
4770
+ }
4771
+ /**
4772
+ * Sets custom data for an annotation by safely stringifying and storing JSON
4773
+ * @private
4774
+ */
4775
+ setAnnotCustom(annotationPtr, data) {
4776
+ if (data === void 0 || data === null) {
4777
+ return this.setAnnotString(annotationPtr, "EPDFCustom", "");
4778
+ }
4779
+ try {
4780
+ const jsonString = JSON.stringify(data);
4781
+ return this.setAnnotString(annotationPtr, "EPDFCustom", jsonString);
4782
+ } catch (error) {
4783
+ console.warn("Failed to stringify annotation custom data as JSON:", error);
4784
+ console.warn("Invalid data object:", data);
4785
+ return false;
4786
+ }
4787
+ }
4532
4788
  /**
4533
4789
  * Fetches the /IT (Intent) name from an annotation as a UTF-8 JS string.
4534
4790
  *
@@ -4576,6 +4832,38 @@ class PdfiumEngine {
4576
4832
  this.free(ptr);
4577
4833
  return value || void 0;
4578
4834
  }
4835
+ /**
4836
+ * Get annotation by name
4837
+ * @param pagePtr - pointer to pdf page object
4838
+ * @param name - name of annotation
4839
+ * @returns pointer to pdf annotation
4840
+ *
4841
+ * @private
4842
+ */
4843
+ getAnnotationByName(pagePtr, name) {
4844
+ const bytes = 2 * (name.length + 1);
4845
+ const ptr = this.malloc(bytes);
4846
+ this.pdfiumModule.pdfium.stringToUTF16(name, ptr, bytes);
4847
+ const ok = this.pdfiumModule.EPDFPage_GetAnnotByName(pagePtr, ptr);
4848
+ this.free(ptr);
4849
+ return ok;
4850
+ }
4851
+ /**
4852
+ * Remove annotation by name
4853
+ * @param pagePtr - pointer to pdf page object
4854
+ * @param name - name of annotation
4855
+ * @returns true on success
4856
+ *
4857
+ * @private
4858
+ */
4859
+ removeAnnotationByName(pagePtr, name) {
4860
+ const bytes = 2 * (name.length + 1);
4861
+ const ptr = this.malloc(bytes);
4862
+ this.pdfiumModule.pdfium.stringToUTF16(name, ptr, bytes);
4863
+ const ok = this.pdfiumModule.EPDFPage_RemoveAnnotByName(pagePtr, ptr);
4864
+ this.free(ptr);
4865
+ return ok;
4866
+ }
4579
4867
  /**
4580
4868
  * Set a string value (`/T`, `/M`, `/State`, …) to an annotation.
4581
4869
  *
@@ -4594,13 +4882,12 @@ class PdfiumEngine {
4594
4882
  /**
4595
4883
  * Read vertices of pdf annotation
4596
4884
  * @param page - pdf page infor
4597
- * @param pagePtr - pointer to pdf page object
4598
4885
  * @param annotationPtr - pointer to pdf annotation
4599
4886
  * @returns vertices of pdf annotation
4600
4887
  *
4601
4888
  * @private
4602
4889
  */
4603
- readPdfAnnoVertices(page, pagePtr, annotationPtr) {
4890
+ readPdfAnnoVertices(page, annotationPtr) {
4604
4891
  const vertices = [];
4605
4892
  const count = this.pdfiumModule.FPDFAnnot_GetVertices(annotationPtr, 0, 0);
4606
4893
  const pointMemorySize = 8;
@@ -4812,7 +5099,7 @@ class PdfiumEngine {
4812
5099
  });
4813
5100
  }
4814
5101
  const pageCtx = ctx.acquirePage(page.index);
4815
- const annotPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, annotation.id);
5102
+ const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
4816
5103
  if (!annotPtr) {
4817
5104
  pageCtx.release();
4818
5105
  this.logger.perf(
@@ -5248,7 +5535,7 @@ class PdfiumEngine {
5248
5535
  *
5249
5536
  * @private
5250
5537
  */
5251
- convertPageRectToDeviceRect(page, pagePtr, pageRect) {
5538
+ convertPageRectToDeviceRect(page, pageRect) {
5252
5539
  const { x, y } = this.convertPagePointToDevicePoint(page, {
5253
5540
  x: pageRect.left,
5254
5541
  y: pageRect.top
@@ -5436,53 +5723,82 @@ class PdfiumEngine {
5436
5723
  return highlightRects;
5437
5724
  }
5438
5725
  /**
5439
- * Search for a keyword across all pages in the document
5440
- * Returns all search results throughout the entire document
5726
+ * {@inheritDoc @embedpdf/models!PdfEngine.searchAllPages}
5441
5727
  *
5442
- * @param doc - Pdf document object
5443
- * @param keyword - Search keyword
5444
- * @param flags - Match flags for search
5445
- * @returns Promise of all search results in the document
5728
+ * Runs inside the worker.
5729
+ * Emits per-page progress: { page, results }
5446
5730
  *
5447
5731
  * @public
5448
5732
  */
5449
5733
  searchAllPages(doc, keyword, flags = []) {
5450
5734
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "searchAllPages", doc, keyword, flags);
5451
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SearchAllPages`, "Begin", doc.id);
5735
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchAllPages", "Begin", doc.id);
5452
5736
  const ctx = this.cache.getContext(doc.id);
5453
5737
  if (!ctx) {
5454
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SearchAllPages`, "End", doc.id);
5455
- return PdfTaskHelper.resolve({ results: [], total: 0 });
5738
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchAllPages", "End", doc.id);
5739
+ return PdfTaskHelper.resolve({
5740
+ results: [],
5741
+ total: 0
5742
+ });
5456
5743
  }
5457
5744
  const length = 2 * (keyword.length + 1);
5458
5745
  const keywordPtr = this.malloc(length);
5459
5746
  this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);
5460
- const flag = flags.reduce((flag2, currFlag) => {
5461
- return flag2 | currFlag;
5462
- }, MatchFlag.None);
5463
- const results = [];
5464
- const searchAllPagesTask = PdfTaskHelper.create();
5465
- const executeSearch = async () => {
5466
- for (let pageIndex = 0; pageIndex < doc.pageCount; pageIndex++) {
5467
- const pageResults = this.searchAllInPage(ctx, doc.pages[pageIndex], keywordPtr, flag);
5468
- results.push(...pageResults);
5747
+ const flag = flags.reduce((acc, f) => acc | f, MatchFlag.None);
5748
+ const task = PdfTaskHelper.create();
5749
+ let cancelled = false;
5750
+ task.wait(
5751
+ () => {
5752
+ },
5753
+ (err) => {
5754
+ if (err.type === "abort") cancelled = true;
5469
5755
  }
5470
- this.free(keywordPtr);
5471
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SearchAllPages`, "End", doc.id);
5472
- searchAllPagesTask.resolve({
5473
- results,
5474
- total: results.length
5475
- });
5756
+ );
5757
+ const CHUNK_SIZE = 100;
5758
+ const allResults = [];
5759
+ const processChunk = (startIdx) => {
5760
+ if (cancelled) return;
5761
+ const endIdx = Math.min(startIdx + CHUNK_SIZE, doc.pageCount);
5762
+ try {
5763
+ for (let pageIndex = startIdx; pageIndex < endIdx && !cancelled; pageIndex++) {
5764
+ const pageResults = this.searchAllInPage(ctx, doc.pages[pageIndex], keywordPtr, flag);
5765
+ allResults.push(...pageResults);
5766
+ task.progress({ page: pageIndex, results: pageResults });
5767
+ }
5768
+ } catch (e) {
5769
+ if (!cancelled) {
5770
+ this.free(keywordPtr);
5771
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchAllPages", "End", doc.id);
5772
+ task.reject({
5773
+ code: PdfErrorCode.Unknown,
5774
+ message: `Error searching document: ${e}`
5775
+ });
5776
+ }
5777
+ return;
5778
+ }
5779
+ if (cancelled) return;
5780
+ if (endIdx >= doc.pageCount) {
5781
+ this.free(keywordPtr);
5782
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "SearchAllPages", "End", doc.id);
5783
+ task.resolve({ results: allResults, total: allResults.length });
5784
+ return;
5785
+ }
5786
+ setTimeout(() => processChunk(endIdx), 0);
5476
5787
  };
5477
- executeSearch().catch((error) => {
5478
- this.free(keywordPtr);
5479
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `SearchAllPages`, "End", doc.id);
5480
- searchAllPagesTask.reject({
5481
- code: PdfErrorCode.Unknown,
5482
- message: `Error searching document: ${error}`
5483
- });
5484
- });
5485
- return searchAllPagesTask;
5788
+ setTimeout(() => processChunk(0), 0);
5789
+ task.wait(
5790
+ () => {
5791
+ },
5792
+ (err) => {
5793
+ if (err.type === "abort") {
5794
+ try {
5795
+ this.free(keywordPtr);
5796
+ } catch {
5797
+ }
5798
+ }
5799
+ }
5800
+ );
5801
+ return task;
5486
5802
  }
5487
5803
  /**
5488
5804
  * Extract word-aligned context for a search hit.
@@ -5553,44 +5869,43 @@ class PdfiumEngine {
5553
5869
  * @private
5554
5870
  */
5555
5871
  searchAllInPage(ctx, page, keywordPtr, flag) {
5556
- const pageIndex = page.index;
5557
- const pageCtx = ctx.acquirePage(pageIndex);
5558
- const textPagePtr = pageCtx.getTextPage();
5559
- const total = this.pdfiumModule.FPDFText_CountChars(textPagePtr);
5560
- const bufPtr = this.malloc(2 * (total + 1));
5561
- this.pdfiumModule.FPDFText_GetText(textPagePtr, 0, total, bufPtr);
5562
- const fullText = this.pdfiumModule.pdfium.UTF16ToString(bufPtr);
5563
- this.free(bufPtr);
5564
- const pageResults = [];
5565
- const searchHandle = this.pdfiumModule.FPDFText_FindStart(
5566
- textPagePtr,
5567
- keywordPtr,
5568
- flag,
5569
- 0
5570
- // Start from the beginning of the page
5571
- );
5572
- while (this.pdfiumModule.FPDFText_FindNext(searchHandle)) {
5573
- const charIndex = this.pdfiumModule.FPDFText_GetSchResultIndex(searchHandle);
5574
- const charCount = this.pdfiumModule.FPDFText_GetSchCount(searchHandle);
5575
- const rects = this.getHighlightRects(
5576
- page,
5577
- pageCtx.pagePtr,
5872
+ return ctx.borrowPage(page.index, (pageCtx) => {
5873
+ const textPagePtr = pageCtx.getTextPage();
5874
+ const total = this.pdfiumModule.FPDFText_CountChars(textPagePtr);
5875
+ const bufPtr = this.malloc(2 * (total + 1));
5876
+ this.pdfiumModule.FPDFText_GetText(textPagePtr, 0, total, bufPtr);
5877
+ const fullText = this.pdfiumModule.pdfium.UTF16ToString(bufPtr);
5878
+ this.free(bufPtr);
5879
+ const pageResults = [];
5880
+ const searchHandle = this.pdfiumModule.FPDFText_FindStart(
5578
5881
  textPagePtr,
5579
- charIndex,
5580
- charCount
5882
+ keywordPtr,
5883
+ flag,
5884
+ 0
5885
+ // Start from the beginning of the page
5581
5886
  );
5582
- const context = this.buildContext(fullText, charIndex, charCount);
5583
- pageResults.push({
5584
- pageIndex,
5585
- charIndex,
5586
- charCount,
5587
- rects,
5588
- context
5589
- });
5590
- }
5591
- this.pdfiumModule.FPDFText_FindClose(searchHandle);
5592
- pageCtx.release();
5593
- return pageResults;
5887
+ while (this.pdfiumModule.FPDFText_FindNext(searchHandle)) {
5888
+ const charIndex = this.pdfiumModule.FPDFText_GetSchResultIndex(searchHandle);
5889
+ const charCount = this.pdfiumModule.FPDFText_GetSchCount(searchHandle);
5890
+ const rects = this.getHighlightRects(
5891
+ page,
5892
+ pageCtx.pagePtr,
5893
+ textPagePtr,
5894
+ charIndex,
5895
+ charCount
5896
+ );
5897
+ const context = this.buildContext(fullText, charIndex, charCount);
5898
+ pageResults.push({
5899
+ pageIndex: page.index,
5900
+ charIndex,
5901
+ charCount,
5902
+ rects,
5903
+ context
5904
+ });
5905
+ }
5906
+ this.pdfiumModule.FPDFText_FindClose(searchHandle);
5907
+ return pageResults;
5908
+ });
5594
5909
  }
5595
5910
  }
5596
5911
  export {
@@ -5602,4 +5917,4 @@ export {
5602
5917
  readArrayBuffer as c,
5603
5918
  readString as r
5604
5919
  };
5605
- //# sourceMappingURL=engine-B11yoQGd.js.map
5920
+ //# sourceMappingURL=engine-uSZXjmb5.js.map