@embedpdf/engines 2.10.1 → 2.11.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-BNQEVS9L.cjs +2 -0
  2. package/dist/direct-engine-BNQEVS9L.cjs.map +1 -0
  3. package/dist/{direct-engine-4LZYs06h.js → direct-engine-cyecHjwI.js} +346 -27
  4. package/dist/direct-engine-cyecHjwI.js.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +17 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/orchestrator/pdf-engine.d.ts +5 -0
  10. package/dist/lib/orchestrator/remote-executor.d.ts +5 -0
  11. package/dist/lib/pdfium/cache.d.ts +1 -0
  12. package/dist/lib/pdfium/engine.d.ts +51 -7
  13. package/dist/lib/pdfium/index.cjs +1 -1
  14. package/dist/lib/pdfium/index.js +3 -3
  15. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  16. package/dist/lib/pdfium/web/direct-engine.js +2 -2
  17. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  18. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  19. package/dist/lib/pdfium/web/worker-engine.js +22 -2
  20. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  21. package/dist/lib/webworker/engine.cjs +1 -1
  22. package/dist/lib/webworker/engine.cjs.map +1 -1
  23. package/dist/lib/webworker/engine.d.ts +10 -0
  24. package/dist/lib/webworker/engine.js +79 -0
  25. package/dist/lib/webworker/engine.js.map +1 -1
  26. package/dist/pdf-engine-BoFryxxe.cjs +2 -0
  27. package/dist/{pdf-engine-BeHgaBOW.cjs.map → pdf-engine-BoFryxxe.cjs.map} +1 -1
  28. package/dist/{pdf-engine-sORqXhQk.js → pdf-engine-Dj-haWhC.js} +54 -1
  29. package/dist/{pdf-engine-sORqXhQk.js.map → pdf-engine-Dj-haWhC.js.map} +1 -1
  30. package/dist/preact/index.cjs +1 -1
  31. package/dist/preact/index.js +1 -1
  32. package/dist/react/index.cjs +1 -1
  33. package/dist/react/index.js +1 -1
  34. package/dist/svelte/index.cjs +1 -1
  35. package/dist/svelte/index.js +1 -1
  36. package/dist/vue/index.cjs +1 -1
  37. package/dist/vue/index.js +1 -1
  38. package/package.json +7 -7
  39. package/dist/direct-engine-4LZYs06h.js.map +0 -1
  40. package/dist/direct-engine-C29Euebw.cjs +0 -2
  41. package/dist/direct-engine-C29Euebw.cjs.map +0 -1
  42. package/dist/pdf-engine-BeHgaBOW.cjs +0 -2
@@ -1,6 +1,6 @@
1
1
  import { init } from "@embedpdf/pdfium";
2
- import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, PdfJavaScriptActionTrigger, PdfAnnotationSubtype, isUuidV4, uuidV4, PdfJavaScriptWidgetEventType, PDF_ANNOT_AACTION_EVENT, PDF_FORM_FIELD_TYPE, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationColorType, PdfAnnotationBorderStyle, PdfStandardFont, PDF_FORM_FIELD_FLAG, webColorToPdfColor, pdfColorToWebColor, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
- import { P as PdfEngine } from "./pdf-engine-sORqXhQk.js";
2
+ import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, PdfJavaScriptActionTrigger, PdfAnnotationSubtype, isUuidV4, uuidV4, PdfJavaScriptWidgetEventType, PDF_ANNOT_AACTION_EVENT, PDF_FORM_FIELD_TYPE, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationName, PdfAnnotationColorType, PdfAnnotationBorderStyle, PdfStandardFont, PDF_FORM_FIELD_FLAG, webColorToPdfColor, pdfColorToWebColor, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
+ import { P as PdfEngine } from "./pdf-engine-Dj-haWhC.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-BISJ9naB.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
6
6
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
@@ -125,8 +125,8 @@ class PdfCache {
125
125
  closeDocument(docId) {
126
126
  const ctx = this.docs.get(docId);
127
127
  if (!ctx) return false;
128
- ctx.dispose();
129
128
  this.docs.delete(docId);
129
+ ctx.dispose();
130
130
  return true;
131
131
  }
132
132
  /** Close all documents */
@@ -164,6 +164,7 @@ class DocumentContext {
164
164
  this.filePtr = filePtr;
165
165
  this.docPtr = docPtr;
166
166
  this.memoryManager = memoryManager;
167
+ this.disposed = false;
167
168
  this.normalizeRotation = config.normalizeRotation;
168
169
  this.pageCache = new PageCache(pdfium, docPtr, config);
169
170
  }
@@ -185,6 +186,8 @@ class DocumentContext {
185
186
  }
186
187
  /** Tear down all pages + this document */
187
188
  dispose() {
189
+ if (this.disposed) return;
190
+ this.disposed = true;
188
191
  this.pageCache.forceReleaseAll();
189
192
  this.pageCache.pdf.FPDF_CloseDocument(this.docPtr);
190
193
  this.memoryManager.free(WasmPointer(this.filePtr));
@@ -1127,6 +1130,36 @@ class PdfiumNative {
1127
1130
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
1128
1131
  return PdfTaskHelper.resolve(pdfDoc);
1129
1132
  }
1133
+ /**
1134
+ * Create a new empty PDF document and register it in the cache.
1135
+ *
1136
+ * @param id - unique document identifier
1137
+ * @returns task containing the empty PdfDocumentObject
1138
+ */
1139
+ createDocument(id) {
1140
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "createDocument", id);
1141
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "CreateDocument", "Begin", id);
1142
+ const docPtr = this.pdfiumModule.FPDF_CreateNewDocument();
1143
+ if (!docPtr) {
1144
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "CreateDocument", "End", id);
1145
+ return PdfTaskHelper.reject({
1146
+ code: PdfErrorCode.CantCreateNewDoc,
1147
+ message: "can not create new document"
1148
+ });
1149
+ }
1150
+ const pdfDoc = {
1151
+ id,
1152
+ pageCount: 0,
1153
+ pages: [],
1154
+ isEncrypted: false,
1155
+ isOwnerUnlocked: true,
1156
+ permissions: 4294967295,
1157
+ normalizedRotation: false
1158
+ };
1159
+ this.cache.setDocument(id, 0, docPtr, false);
1160
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "CreateDocument", "End", id);
1161
+ return PdfTaskHelper.resolve(pdfDoc);
1162
+ }
1130
1163
  /**
1131
1164
  * {@inheritDoc @embedpdf/models!PdfEngine.getMetadata}
1132
1165
  *
@@ -1807,7 +1840,7 @@ class PdfiumNative {
1807
1840
  pageCtx.pagePtr,
1808
1841
  annotationPtr,
1809
1842
  saveAnnotation,
1810
- context == null ? void 0 : context.imageData
1843
+ context
1811
1844
  );
1812
1845
  break;
1813
1846
  case PdfAnnotationSubtype.TEXT:
@@ -2969,6 +3002,115 @@ class PdfiumNative {
2969
3002
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `ExtractPages`, "End", doc.id);
2970
3003
  return PdfTaskHelper.resolve(buffer);
2971
3004
  }
3005
+ /**
3006
+ * Import pages from a source document into a destination document.
3007
+ *
3008
+ * @param destDoc - destination document (must be open in cache)
3009
+ * @param srcDoc - source document (must be open in cache)
3010
+ * @param srcPageIndices - zero-based page indices in the source document
3011
+ * @param insertIndex - position to insert at in destination (defaults to end)
3012
+ * @returns task containing the newly added PdfPageObjects
3013
+ */
3014
+ importPages(destDoc, srcDoc, srcPageIndices, insertIndex) {
3015
+ this.logger.debug(
3016
+ LOG_SOURCE,
3017
+ LOG_CATEGORY,
3018
+ "importPages",
3019
+ destDoc.id,
3020
+ srcDoc.id,
3021
+ srcPageIndices
3022
+ );
3023
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "ImportPages", "Begin", destDoc.id);
3024
+ const destCtx = this.cache.getContext(destDoc.id);
3025
+ if (!destCtx) {
3026
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "ImportPages", "End", destDoc.id);
3027
+ return PdfTaskHelper.reject({
3028
+ code: PdfErrorCode.DocNotOpen,
3029
+ message: "destination document is not open"
3030
+ });
3031
+ }
3032
+ const srcCtx = this.cache.getContext(srcDoc.id);
3033
+ if (!srcCtx) {
3034
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "ImportPages", "End", destDoc.id);
3035
+ return PdfTaskHelper.reject({
3036
+ code: PdfErrorCode.DocNotOpen,
3037
+ message: "source document is not open"
3038
+ });
3039
+ }
3040
+ const destInsertIndex = insertIndex ?? this.pdfiumModule.FPDF_GetPageCount(destCtx.docPtr);
3041
+ const indicesPtr = this.memoryManager.malloc(srcPageIndices.length * 4);
3042
+ for (let i = 0; i < srcPageIndices.length; i++) {
3043
+ this.pdfiumModule.pdfium.setValue(indicesPtr + i * 4, srcPageIndices[i], "i32");
3044
+ }
3045
+ if (!this.pdfiumModule.FPDF_ImportPagesByIndex(
3046
+ destCtx.docPtr,
3047
+ srcCtx.docPtr,
3048
+ indicesPtr,
3049
+ srcPageIndices.length,
3050
+ destInsertIndex
3051
+ )) {
3052
+ this.memoryManager.free(indicesPtr);
3053
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "ImportPages", "End", destDoc.id);
3054
+ return PdfTaskHelper.reject({
3055
+ code: PdfErrorCode.CantImportPages,
3056
+ message: "can not import pages into destination document"
3057
+ });
3058
+ }
3059
+ this.memoryManager.free(indicesPtr);
3060
+ const newPages = [];
3061
+ const sizePtr = this.memoryManager.malloc(8);
3062
+ const normalizeRotation = destCtx.normalizeRotation;
3063
+ for (let i = 0; i < srcPageIndices.length; i++) {
3064
+ const newPageIndex = destInsertIndex + i;
3065
+ const result = normalizeRotation ? this.pdfiumModule.EPDF_GetPageSizeByIndexNormalized(destCtx.docPtr, newPageIndex, sizePtr) : this.pdfiumModule.FPDF_GetPageSizeByIndexF(destCtx.docPtr, newPageIndex, sizePtr);
3066
+ if (!result) {
3067
+ this.memoryManager.free(sizePtr);
3068
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "ImportPages", "End", destDoc.id);
3069
+ return PdfTaskHelper.reject({
3070
+ code: PdfErrorCode.Unknown,
3071
+ message: `failed to read metadata for imported page ${newPageIndex}`
3072
+ });
3073
+ }
3074
+ const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(
3075
+ destCtx.docPtr,
3076
+ newPageIndex
3077
+ );
3078
+ newPages.push({
3079
+ index: newPageIndex,
3080
+ size: {
3081
+ width: this.pdfiumModule.pdfium.getValue(sizePtr, "float"),
3082
+ height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, "float")
3083
+ },
3084
+ rotation
3085
+ });
3086
+ }
3087
+ this.memoryManager.free(sizePtr);
3088
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "ImportPages", "End", destDoc.id);
3089
+ return PdfTaskHelper.resolve(newPages);
3090
+ }
3091
+ deletePage(doc, pageIndex) {
3092
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "deletePage", doc.id, pageIndex);
3093
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "DeletePage", "Begin", doc.id);
3094
+ const ctx = this.cache.getContext(doc.id);
3095
+ if (!ctx) {
3096
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "DeletePage", "End", doc.id);
3097
+ return PdfTaskHelper.reject({
3098
+ code: PdfErrorCode.DocNotOpen,
3099
+ message: "document is not open"
3100
+ });
3101
+ }
3102
+ const pageCount = this.pdfiumModule.FPDF_GetPageCount(ctx.docPtr);
3103
+ if (pageIndex < 0 || pageIndex >= pageCount) {
3104
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "DeletePage", "End", doc.id);
3105
+ return PdfTaskHelper.reject({
3106
+ code: PdfErrorCode.CantDeletePage,
3107
+ message: `page index ${pageIndex} out of range (0..${pageCount - 1})`
3108
+ });
3109
+ }
3110
+ this.pdfiumModule.FPDFPage_Delete(ctx.docPtr, pageIndex);
3111
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "DeletePage", "End", doc.id);
3112
+ return PdfTaskHelper.resolve(true);
3113
+ }
2972
3114
  /**
2973
3115
  * {@inheritDoc @embedpdf/models!PdfEngine.extractText}
2974
3116
  *
@@ -3332,9 +3474,7 @@ class PdfiumNative {
3332
3474
  closeDocument(doc) {
3333
3475
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "closeDocument", doc);
3334
3476
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseDocument`, "Begin", doc.id);
3335
- const ctx = this.cache.getContext(doc.id);
3336
- if (!ctx) return PdfTaskHelper.resolve(true);
3337
- ctx.dispose();
3477
+ this.cache.closeDocument(doc.id);
3338
3478
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `CloseDocument`, "End", doc.id);
3339
3479
  return PdfTaskHelper.resolve(true);
3340
3480
  }
@@ -3361,7 +3501,10 @@ class PdfiumNative {
3361
3501
  * @private
3362
3502
  */
3363
3503
  addTextContent(doc, page, pagePtr, annotationPtr, annotation) {
3364
- if (!this.setAnnotationIcon(annotationPtr, annotation.icon || PdfAnnotationIcon.Comment)) {
3504
+ if (!this.setAnnotationName(
3505
+ annotationPtr,
3506
+ annotation.name ?? annotation.icon ?? PdfAnnotationName.Comment
3507
+ )) {
3365
3508
  return false;
3366
3509
  }
3367
3510
  if (annotation.state && !this.setAnnotString(annotationPtr, "State", annotation.state)) {
@@ -3956,18 +4099,28 @@ class PdfiumNative {
3956
4099
  *
3957
4100
  * @private
3958
4101
  */
3959
- addStampContent(doc, docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
3960
- if (annotation.icon && !this.setAnnotationIcon(annotationPtr, annotation.icon)) {
3961
- return false;
3962
- }
3963
- if (annotation.subject && !this.setAnnotString(annotationPtr, "Subj", annotation.subject)) {
4102
+ addStampContent(doc, docPtr, page, pagePtr, annotationPtr, annotation, context) {
4103
+ const stampName = annotation.name ?? annotation.icon;
4104
+ if (stampName && !this.setAnnotationName(annotationPtr, stampName)) {
3964
4105
  return false;
3965
4106
  }
3966
- if (imageData) {
4107
+ if (context && "appearance" in context && context.appearance) {
4108
+ if (!this.setAppearanceFromPdf(docPtr, annotationPtr, context.appearance)) {
4109
+ return false;
4110
+ }
4111
+ } else if (context && "imageData" in context && context.imageData) {
3967
4112
  for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
3968
4113
  this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
3969
4114
  }
3970
- if (!this.addImageObject(doc, docPtr, page, pagePtr, annotationPtr, annotation.rect, imageData)) {
4115
+ if (!this.addImageObject(
4116
+ doc,
4117
+ docPtr,
4118
+ page,
4119
+ pagePtr,
4120
+ annotationPtr,
4121
+ annotation.rect,
4122
+ context.imageData
4123
+ )) {
3971
4124
  return false;
3972
4125
  }
3973
4126
  }
@@ -3976,6 +4129,25 @@ class PdfiumNative {
3976
4129
  }
3977
4130
  return !!this.pdfiumModule.EPDFAnnot_UpdateAppearanceToRect(annotationPtr, PdfStampFit.Cover);
3978
4131
  }
4132
+ /**
4133
+ * Set an annotation's appearance from a single-page PDF document.
4134
+ * Loads the PDF into WASM memory, calls the native SetAppearanceFromPage,
4135
+ * then cleans up.
4136
+ */
4137
+ setAppearanceFromPdf(docPtr, annotationPtr, appearance) {
4138
+ const data = new Uint8Array(appearance);
4139
+ const filePtr = this.memoryManager.malloc(data.byteLength);
4140
+ this.pdfiumModule.pdfium.HEAPU8.set(data, filePtr);
4141
+ const tempDocPtr = this.pdfiumModule.FPDF_LoadMemDocument(filePtr, data.byteLength, "");
4142
+ if (!tempDocPtr) {
4143
+ this.memoryManager.free(filePtr);
4144
+ return false;
4145
+ }
4146
+ const ok = this.pdfiumModule.EPDFAnnot_SetAppearanceFromPage(annotationPtr, tempDocPtr, 0);
4147
+ this.pdfiumModule.FPDF_CloseDocument(tempDocPtr);
4148
+ this.memoryManager.free(filePtr);
4149
+ return !!ok;
4150
+ }
3979
4151
  /**
3980
4152
  * Add image object to annotation
3981
4153
  * @param doc - pdf document object
@@ -5635,23 +5807,23 @@ class PdfiumNative {
5635
5807
  return this.pdfiumModule.EPDFAnnot_SetBorderStyle(annotationPtr, style, width);
5636
5808
  }
5637
5809
  /**
5638
- * Get the icon of the annotation
5810
+ * Get the /Name entry of the annotation
5639
5811
  *
5640
5812
  * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
5641
- * @returns `PdfAnnotationIcon`
5813
+ * @returns `PdfAnnotationName`
5642
5814
  */
5643
- getAnnotationIcon(annotationPtr) {
5644
- return this.pdfiumModule.EPDFAnnot_GetIcon(annotationPtr);
5815
+ getAnnotationName(annotationPtr) {
5816
+ return this.pdfiumModule.EPDFAnnot_GetName(annotationPtr);
5645
5817
  }
5646
5818
  /**
5647
- * Set the icon of the annotation
5819
+ * Set the /Name entry of the annotation
5648
5820
  *
5649
5821
  * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
5650
- * @param icon - `PdfAnnotationIcon`
5822
+ * @param name - `PdfAnnotationName`
5651
5823
  * @returns `true` on success
5652
5824
  */
5653
- setAnnotationIcon(annotationPtr, icon) {
5654
- return this.pdfiumModule.EPDFAnnot_SetIcon(annotationPtr, icon);
5825
+ setAnnotationName(annotationPtr, name) {
5826
+ return this.pdfiumModule.EPDFAnnot_SetName(annotationPtr, name);
5655
5827
  }
5656
5828
  /**
5657
5829
  * Get the reply type of the annotation (RT property per ISO 32000-2)
@@ -6225,6 +6397,143 @@ class PdfiumNative {
6225
6397
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6226
6398
  return PdfTaskHelper.resolve(!!ok);
6227
6399
  }
6400
+ /**
6401
+ * Export an annotation's appearance as a standalone single-page PDF.
6402
+ *
6403
+ * @param doc - document object
6404
+ * @param page - page object
6405
+ * @param annotation - the annotation to export
6406
+ * @returns a PDF buffer containing the annotation appearance
6407
+ */
6408
+ exportAnnotationAppearanceAsPdf(doc, page, annotation) {
6409
+ this.logger.debug(
6410
+ LOG_SOURCE,
6411
+ LOG_CATEGORY,
6412
+ "exportAnnotationAppearanceAsPdf",
6413
+ doc.id,
6414
+ page.index,
6415
+ annotation.id
6416
+ );
6417
+ const label = "ExportAnnotationAppearanceAsPdf";
6418
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "Begin", `${doc.id}-${page.index}`);
6419
+ const ctx = this.cache.getContext(doc.id);
6420
+ if (!ctx) {
6421
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6422
+ return PdfTaskHelper.reject({
6423
+ code: PdfErrorCode.DocNotOpen,
6424
+ message: "document does not open"
6425
+ });
6426
+ }
6427
+ const pageCtx = ctx.acquirePage(page.index);
6428
+ const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
6429
+ if (!annotPtr) {
6430
+ pageCtx.release();
6431
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6432
+ return PdfTaskHelper.reject({
6433
+ code: PdfErrorCode.NotFound,
6434
+ message: "annotation not found"
6435
+ });
6436
+ }
6437
+ const exportedDocPtr = this.pdfiumModule.EPDFAnnot_ExportAppearanceAsDocument(annotPtr);
6438
+ this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
6439
+ if (!exportedDocPtr) {
6440
+ pageCtx.release();
6441
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6442
+ return PdfTaskHelper.reject({
6443
+ code: PdfErrorCode.CantCreateNewDoc,
6444
+ message: "can not export annotation as pdf"
6445
+ });
6446
+ }
6447
+ try {
6448
+ return PdfTaskHelper.resolve(this.saveDocument(exportedDocPtr));
6449
+ } finally {
6450
+ this.pdfiumModule.FPDF_CloseDocument(exportedDocPtr);
6451
+ pageCtx.release();
6452
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6453
+ }
6454
+ }
6455
+ /**
6456
+ * Export multiple annotations' appearances as a standalone single-page PDF.
6457
+ * All annotations must be on the same page. The resulting page is sized to
6458
+ * the union of all annotation rects, with each appearance positioned correctly.
6459
+ *
6460
+ * @param doc - document object
6461
+ * @param page - page object
6462
+ * @param annotations - the annotations to export
6463
+ * @returns a PDF buffer containing the combined appearances
6464
+ */
6465
+ exportAnnotationsAppearanceAsPdf(doc, page, annotations) {
6466
+ this.logger.debug(
6467
+ LOG_SOURCE,
6468
+ LOG_CATEGORY,
6469
+ "exportAnnotationsAppearanceAsPdf",
6470
+ doc.id,
6471
+ page.index,
6472
+ annotations.map((a) => a.id)
6473
+ );
6474
+ const label = "ExportAnnotationsAppearanceAsPdf";
6475
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "Begin", `${doc.id}-${page.index}`);
6476
+ const ctx = this.cache.getContext(doc.id);
6477
+ if (!ctx) {
6478
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6479
+ return PdfTaskHelper.reject({
6480
+ code: PdfErrorCode.DocNotOpen,
6481
+ message: "document does not open"
6482
+ });
6483
+ }
6484
+ if (annotations.length === 0) {
6485
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6486
+ return PdfTaskHelper.reject({
6487
+ code: PdfErrorCode.NotFound,
6488
+ message: "no annotations provided"
6489
+ });
6490
+ }
6491
+ const pageCtx = ctx.acquirePage(page.index);
6492
+ const annotPtrs = [];
6493
+ for (const annotation of annotations) {
6494
+ const annotPtr = this.getAnnotationByName(pageCtx.pagePtr, annotation.id);
6495
+ if (!annotPtr) {
6496
+ for (const ptr of annotPtrs) {
6497
+ this.pdfiumModule.FPDFPage_CloseAnnot(ptr);
6498
+ }
6499
+ pageCtx.release();
6500
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6501
+ return PdfTaskHelper.reject({
6502
+ code: PdfErrorCode.NotFound,
6503
+ message: `annotation not found: ${annotation.id}`
6504
+ });
6505
+ }
6506
+ annotPtrs.push(annotPtr);
6507
+ }
6508
+ const ptrArraySize = annotPtrs.length * 4;
6509
+ const ptrArrayPtr = this.memoryManager.malloc(ptrArraySize);
6510
+ for (let i = 0; i < annotPtrs.length; i++) {
6511
+ this.pdfiumModule.pdfium.setValue(ptrArrayPtr + i * 4, annotPtrs[i], "i32");
6512
+ }
6513
+ const exportedDocPtr = this.pdfiumModule.EPDFAnnot_ExportMultipleAppearancesAsDocument(
6514
+ ptrArrayPtr,
6515
+ annotPtrs.length
6516
+ );
6517
+ this.memoryManager.free(ptrArrayPtr);
6518
+ for (const ptr of annotPtrs) {
6519
+ this.pdfiumModule.FPDFPage_CloseAnnot(ptr);
6520
+ }
6521
+ if (!exportedDocPtr) {
6522
+ pageCtx.release();
6523
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6524
+ return PdfTaskHelper.reject({
6525
+ code: PdfErrorCode.CantCreateNewDoc,
6526
+ message: "can not export annotations as pdf"
6527
+ });
6528
+ }
6529
+ try {
6530
+ return PdfTaskHelper.resolve(this.saveDocument(exportedDocPtr));
6531
+ } finally {
6532
+ this.pdfiumModule.FPDF_CloseDocument(exportedDocPtr);
6533
+ pageCtx.release();
6534
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", `${doc.id}-${page.index}`);
6535
+ }
6536
+ }
6228
6537
  /** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */
6229
6538
  allocFSQuadsBufferFromRects(doc, page, rects) {
6230
6539
  const STRIDE = 32;
@@ -6329,7 +6638,7 @@ class PdfiumNative {
6329
6638
  const stateModel = this.getAnnotString(annotationPtr, "StateModel");
6330
6639
  const color = this.getAnnotationColor(annotationPtr);
6331
6640
  const opacity = this.getAnnotationOpacity(annotationPtr);
6332
- const icon = this.getAnnotationIcon(annotationPtr);
6641
+ const name = this.getAnnotationName(annotationPtr);
6333
6642
  return {
6334
6643
  pageIndex: page.index,
6335
6644
  id: index,
@@ -6340,7 +6649,8 @@ class PdfiumNative {
6340
6649
  opacity,
6341
6650
  state,
6342
6651
  stateModel,
6343
- icon,
6652
+ name,
6653
+ icon: name,
6344
6654
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6345
6655
  };
6346
6656
  }
@@ -6881,11 +7191,14 @@ class PdfiumNative {
6881
7191
  readPdfStampAnno(doc, page, annotationPtr, index) {
6882
7192
  const pageRect = this.readPageAnnoRect(annotationPtr);
6883
7193
  const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
7194
+ const name = this.getAnnotationName(annotationPtr);
6884
7195
  return {
6885
7196
  pageIndex: page.index,
6886
7197
  id: index,
6887
7198
  type: PdfAnnotationSubtype.STAMP,
6888
7199
  rect,
7200
+ name,
7201
+ icon: name,
6889
7202
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6890
7203
  };
6891
7204
  }
@@ -7353,6 +7666,9 @@ class PdfiumNative {
7353
7666
  if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
7354
7667
  return false;
7355
7668
  }
7669
+ if (annotation.subject && !this.setAnnotString(annotationPtr, "Subj", annotation.subject)) {
7670
+ return false;
7671
+ }
7356
7672
  if (annotation.modified) {
7357
7673
  if (!this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
7358
7674
  return false;
@@ -7416,6 +7732,7 @@ class PdfiumNative {
7416
7732
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
7417
7733
  const modified = this.getAnnotationDate(annotationPtr, "M");
7418
7734
  const created = this.getAnnotationDate(annotationPtr, "CreationDate");
7735
+ const subject = this.getAnnotString(annotationPtr, "Subj");
7419
7736
  const flags = this.getAnnotationFlags(annotationPtr);
7420
7737
  const custom = this.getAnnotCustom(annotationPtr);
7421
7738
  const inReplyToId = this.getInReplyToId(annotationPtr);
@@ -7433,6 +7750,7 @@ class PdfiumNative {
7433
7750
  flags,
7434
7751
  custom,
7435
7752
  blendMode,
7753
+ ...subject && { subject },
7436
7754
  // Only include IRT if present
7437
7755
  ...inReplyToId && { inReplyToId },
7438
7756
  // Only include RT if present and not the default (Reply)
@@ -8174,7 +8492,8 @@ class PdfiumNative {
8174
8492
  heapPtr,
8175
8493
  stride
8176
8494
  );
8177
- this.pdfiumModule.FPDFBitmap_FillRect(bitmapPtr, 0, 0, wDev, hDev, 4294967295);
8495
+ const bgColor = (options == null ? void 0 : options.transparentBackground) ? 0 : 4294967295;
8496
+ this.pdfiumModule.FPDFBitmap_FillRect(bitmapPtr, 0, 0, wDev, hDev, bgColor);
8178
8497
  const M = buildUserToDeviceMatrix(rect, rotation, wDev, hDev);
8179
8498
  const mPtr = this.memoryManager.malloc(6 * 4);
8180
8499
  const mView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, mPtr, 6);
@@ -9366,4 +9685,4 @@ export {
9366
9685
  isValidCustomKey as i,
9367
9686
  readArrayBuffer as r
9368
9687
  };
9369
- //# sourceMappingURL=direct-engine-4LZYs06h.js.map
9688
+ //# sourceMappingURL=direct-engine-cyecHjwI.js.map