@embedpdf/engines 1.0.14 → 1.0.16

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 (35) hide show
  1. package/dist/{engine-O49988D4.js → engine-B11yoQGd.js} +77 -42
  2. package/dist/engine-B11yoQGd.js.map +1 -0
  3. package/dist/engine-v2kq6ghL.cjs +2 -0
  4. package/dist/engine-v2kq6ghL.cjs.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +2 -2
  7. package/dist/lib/pdfium/engine.d.ts +11 -3
  8. package/dist/lib/pdfium/index.cjs +1 -1
  9. package/dist/lib/pdfium/index.js +2 -2
  10. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  11. package/dist/lib/pdfium/web/direct-engine.js +1 -1
  12. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  13. package/dist/lib/pdfium/web/worker-engine.js +1 -1
  14. package/dist/lib/webworker/engine.cjs +1 -1
  15. package/dist/lib/webworker/engine.cjs.map +1 -1
  16. package/dist/lib/webworker/engine.d.ts +2 -2
  17. package/dist/lib/webworker/engine.js +123 -275
  18. package/dist/lib/webworker/engine.js.map +1 -1
  19. package/dist/lib/webworker/runner.d.ts +12 -0
  20. package/dist/preact/index.cjs +1 -1
  21. package/dist/preact/index.js +1 -1
  22. package/dist/react/index.cjs +1 -1
  23. package/dist/react/index.js +1 -1
  24. package/dist/{runner-CABEqeFp.js → runner-D9_9TvyZ.js} +2 -2
  25. package/dist/runner-D9_9TvyZ.js.map +1 -0
  26. package/dist/{runner-Br_PKNmU.cjs → runner-Dnb6tfxR.cjs} +2 -2
  27. package/dist/runner-Dnb6tfxR.cjs.map +1 -0
  28. package/dist/vue/index.cjs +1 -1
  29. package/dist/vue/index.js +1 -1
  30. package/package.json +3 -3
  31. package/dist/engine-1ZSXSAtm.cjs +0 -2
  32. package/dist/engine-1ZSXSAtm.cjs.map +0 -1
  33. package/dist/engine-O49988D4.js.map +0 -1
  34. package/dist/runner-Br_PKNmU.cjs.map +0 -1
  35. package/dist/runner-CABEqeFp.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { NoopLogger, PdfTaskHelper, PdfErrorCode, Rotation, Task, PdfAnnotationSubtype, stripPdfUnwantedMarkers, PdfAnnotationBorderStyle, dateToPdfDate, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfPageObjectType, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, quadToRect, pdfDateToDate, PdfStandardFont, 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, 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";
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++) {
@@ -913,7 +913,7 @@ class PdfiumEngine {
913
913
  *
914
914
  * @public
915
915
  */
916
- createPageAnnotation(doc, page, annotation) {
916
+ createPageAnnotation(doc, page, annotation, context) {
917
917
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "createPageAnnotation", doc, page, annotation);
918
918
  this.logger.perf(
919
919
  LOG_SOURCE,
@@ -978,8 +978,8 @@ class PdfiumEngine {
978
978
  page,
979
979
  pageCtx.pagePtr,
980
980
  annotationPtr,
981
- annotation.rect,
982
- annotation.contents
981
+ annotation,
982
+ context == null ? void 0 : context.imageData
983
983
  );
984
984
  break;
985
985
  case PdfAnnotationSubtype.FREETEXT:
@@ -1109,17 +1109,7 @@ class PdfiumEngine {
1109
1109
  }
1110
1110
  /* ── Stamp ───────────────────────────────────────────────────────────── */
1111
1111
  case PdfAnnotationSubtype.STAMP: {
1112
- for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotPtr) - 1; i >= 0; i--) {
1113
- this.pdfiumModule.FPDFAnnot_RemoveObject(annotPtr, i);
1114
- }
1115
- ok = this.addStampContent(
1116
- ctx.docPtr,
1117
- page,
1118
- pageCtx.pagePtr,
1119
- annotPtr,
1120
- annotation.rect,
1121
- annotation.contents
1122
- );
1112
+ ok = this.addStampContent(ctx.docPtr, page, pageCtx.pagePtr, annotPtr, annotation);
1123
1113
  break;
1124
1114
  }
1125
1115
  /* ── Free text ────────────────────────────────────────────────────────── */
@@ -2256,21 +2246,21 @@ class PdfiumEngine {
2256
2246
  *
2257
2247
  * @private
2258
2248
  */
2259
- addStampContent(docPtr, page, pagePtr, annotationPtr, rect, contents) {
2260
- for (const content of contents) {
2261
- switch (content.type) {
2262
- case PdfPageObjectType.IMAGE:
2263
- return this.addImageObject(
2264
- docPtr,
2265
- page,
2266
- pagePtr,
2267
- annotationPtr,
2268
- rect.origin,
2269
- content.imageData
2270
- );
2249
+ addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
2250
+ if (imageData) {
2251
+ for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
2252
+ this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
2271
2253
  }
2254
+ return this.addImageObject(
2255
+ docPtr,
2256
+ page,
2257
+ pagePtr,
2258
+ annotationPtr,
2259
+ annotation.rect.origin,
2260
+ imageData
2261
+ );
2272
2262
  }
2273
- return false;
2263
+ return true;
2274
2264
  }
2275
2265
  /**
2276
2266
  * Add image object to annotation
@@ -2340,14 +2330,18 @@ class PdfiumEngine {
2340
2330
  return false;
2341
2331
  }
2342
2332
  this.free(matrixPtr);
2343
- this.pdfiumModule.FPDFPageObj_Transform(imageObjectPtr, 1, 0, 0, 1, position.x, position.y);
2333
+ const pagePos = this.convertDevicePointToPagePoint(page, {
2334
+ x: position.x,
2335
+ y: position.y + imageData.height
2336
+ // shift down by the image height
2337
+ });
2338
+ this.pdfiumModule.FPDFPageObj_Transform(imageObjectPtr, 1, 0, 0, 1, pagePos.x, pagePos.y);
2344
2339
  if (!this.pdfiumModule.FPDFAnnot_AppendObject(annotationPtr, imageObjectPtr)) {
2345
2340
  this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
2346
2341
  this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);
2347
2342
  this.free(bitmapBufferPtr);
2348
2343
  return false;
2349
2344
  }
2350
- this.pdfiumModule.FPDFPage_GenerateContent(pagePtr);
2351
2345
  this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
2352
2346
  this.free(bitmapBufferPtr);
2353
2347
  return true;
@@ -3567,10 +3561,12 @@ class PdfiumEngine {
3567
3561
  const color = this.getAnnotationColor(annotationPtr);
3568
3562
  const opacity = this.getAnnotationOpacity(annotationPtr);
3569
3563
  const inReplyToId = this.getInReplyToId(pagePtr, annotationPtr);
3564
+ const flags = this.getAnnotationFlags(annotationPtr);
3570
3565
  return {
3571
3566
  pageIndex: page.index,
3572
3567
  id: index,
3573
3568
  type: PdfAnnotationSubtype.TEXT,
3569
+ flags,
3574
3570
  contents,
3575
3571
  color: color ?? "#FFFF00",
3576
3572
  opacity,
@@ -3606,6 +3602,7 @@ class PdfiumEngine {
3606
3602
  const opacity = this.getAnnotationOpacity(annotationPtr);
3607
3603
  const modified = pdfDateToDate(modifiedRaw);
3608
3604
  const richContent = this.getAnnotRichContent(annotationPtr);
3605
+ const flags = this.getAnnotationFlags(annotationPtr);
3609
3606
  return {
3610
3607
  pageIndex: page.index,
3611
3608
  id: index,
@@ -3615,6 +3612,7 @@ class PdfiumEngine {
3615
3612
  fontColor: (da == null ? void 0 : da.fontColor) ?? "#000000",
3616
3613
  verticalAlign,
3617
3614
  backgroundColor,
3615
+ flags,
3618
3616
  opacity,
3619
3617
  textAlign,
3620
3618
  defaultStyle,
@@ -3648,6 +3646,7 @@ class PdfiumEngine {
3648
3646
  const author = this.getAnnotString(annotationPtr, "T");
3649
3647
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3650
3648
  const modified = pdfDateToDate(modifiedRaw);
3649
+ const flags = this.getAnnotationFlags(annotationPtr);
3651
3650
  const utf16Length = this.pdfiumModule.FPDFText_GetBoundedText(
3652
3651
  textPagePtr,
3653
3652
  left,
@@ -3683,6 +3682,7 @@ class PdfiumEngine {
3683
3682
  pageIndex: page.index,
3684
3683
  id: index,
3685
3684
  type: PdfAnnotationSubtype.LINK,
3685
+ flags,
3686
3686
  text,
3687
3687
  target,
3688
3688
  rect,
@@ -3707,11 +3707,13 @@ class PdfiumEngine {
3707
3707
  const author = this.getAnnotString(annotationPtr, "T");
3708
3708
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3709
3709
  const modified = pdfDateToDate(modifiedRaw);
3710
+ const flags = this.getAnnotationFlags(annotationPtr);
3710
3711
  const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
3711
3712
  return {
3712
3713
  pageIndex: page.index,
3713
3714
  id: index,
3714
3715
  type: PdfAnnotationSubtype.WIDGET,
3716
+ flags,
3715
3717
  rect,
3716
3718
  field,
3717
3719
  author,
@@ -3734,10 +3736,12 @@ class PdfiumEngine {
3734
3736
  const author = this.getAnnotString(annotationPtr, "T");
3735
3737
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3736
3738
  const modified = pdfDateToDate(modifiedRaw);
3739
+ const flags = this.getAnnotationFlags(annotationPtr);
3737
3740
  return {
3738
3741
  pageIndex: page.index,
3739
3742
  id: index,
3740
3743
  type: PdfAnnotationSubtype.FILEATTACHMENT,
3744
+ flags,
3741
3745
  rect,
3742
3746
  author,
3743
3747
  modified
@@ -3765,12 +3769,14 @@ class PdfiumEngine {
3765
3769
  const inkList = this.getInkList(page, annotationPtr);
3766
3770
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3767
3771
  const intent = this.getAnnotIntent(annotationPtr);
3772
+ const flags = this.getAnnotationFlags(annotationPtr);
3768
3773
  return {
3769
3774
  pageIndex: page.index,
3770
3775
  id: index,
3771
3776
  type: PdfAnnotationSubtype.INK,
3772
3777
  ...intent && { intent },
3773
3778
  blendMode,
3779
+ flags,
3774
3780
  color: color ?? "#FF0000",
3775
3781
  opacity,
3776
3782
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
@@ -3798,6 +3804,7 @@ class PdfiumEngine {
3798
3804
  const modified = pdfDateToDate(modifiedRaw);
3799
3805
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3800
3806
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3807
+ const flags = this.getAnnotationFlags(annotationPtr);
3801
3808
  const strokeColor = this.getAnnotationColor(annotationPtr);
3802
3809
  const interiorColor = this.getAnnotationColor(
3803
3810
  annotationPtr,
@@ -3824,6 +3831,7 @@ class PdfiumEngine {
3824
3831
  id: index,
3825
3832
  type: PdfAnnotationSubtype.POLYGON,
3826
3833
  contents,
3834
+ flags,
3827
3835
  strokeColor: strokeColor ?? "#FF0000",
3828
3836
  color: interiorColor ?? "transparent",
3829
3837
  opacity,
@@ -3855,6 +3863,7 @@ class PdfiumEngine {
3855
3863
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3856
3864
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3857
3865
  const strokeColor = this.getAnnotationColor(annotationPtr);
3866
+ const flags = this.getAnnotationFlags(annotationPtr);
3858
3867
  const interiorColor = this.getAnnotationColor(
3859
3868
  annotationPtr,
3860
3869
  PdfAnnotationColorType.InteriorColor
@@ -3874,6 +3883,7 @@ class PdfiumEngine {
3874
3883
  id: index,
3875
3884
  type: PdfAnnotationSubtype.POLYLINE,
3876
3885
  contents,
3886
+ flags,
3877
3887
  strokeColor: strokeColor ?? "#FF0000",
3878
3888
  color: interiorColor ?? "transparent",
3879
3889
  opacity,
@@ -3907,6 +3917,7 @@ class PdfiumEngine {
3907
3917
  const lineEndings = this.getLineEndings(annotationPtr);
3908
3918
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3909
3919
  const strokeColor = this.getAnnotationColor(annotationPtr);
3920
+ const flags = this.getAnnotationFlags(annotationPtr);
3910
3921
  const interiorColor = this.getAnnotationColor(
3911
3922
  annotationPtr,
3912
3923
  PdfAnnotationColorType.InteriorColor
@@ -3924,6 +3935,7 @@ class PdfiumEngine {
3924
3935
  pageIndex: page.index,
3925
3936
  id: index,
3926
3937
  type: PdfAnnotationSubtype.LINE,
3938
+ flags,
3927
3939
  rect,
3928
3940
  contents,
3929
3941
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
@@ -3962,12 +3974,14 @@ class PdfiumEngine {
3962
3974
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3963
3975
  const modified = pdfDateToDate(modifiedRaw);
3964
3976
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3977
+ const flags = this.getAnnotationFlags(annotationPtr);
3965
3978
  return {
3966
3979
  pageIndex: page.index,
3967
3980
  id: index,
3968
3981
  blendMode,
3969
3982
  type: PdfAnnotationSubtype.HIGHLIGHT,
3970
3983
  rect,
3984
+ flags,
3971
3985
  contents,
3972
3986
  segmentRects,
3973
3987
  color: color ?? "#FFFF00",
@@ -3997,12 +4011,14 @@ class PdfiumEngine {
3997
4011
  const color = this.getAnnotationColor(annotationPtr);
3998
4012
  const opacity = this.getAnnotationOpacity(annotationPtr);
3999
4013
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4014
+ const flags = this.getAnnotationFlags(annotationPtr);
4000
4015
  return {
4001
4016
  pageIndex: page.index,
4002
4017
  id: index,
4003
4018
  blendMode,
4004
4019
  type: PdfAnnotationSubtype.UNDERLINE,
4005
4020
  rect,
4021
+ flags,
4006
4022
  contents,
4007
4023
  segmentRects,
4008
4024
  color: color ?? "#FF0000",
@@ -4032,11 +4048,13 @@ class PdfiumEngine {
4032
4048
  const color = this.getAnnotationColor(annotationPtr);
4033
4049
  const opacity = this.getAnnotationOpacity(annotationPtr);
4034
4050
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4051
+ const flags = this.getAnnotationFlags(annotationPtr);
4035
4052
  return {
4036
4053
  pageIndex: page.index,
4037
4054
  id: index,
4038
4055
  blendMode,
4039
4056
  type: PdfAnnotationSubtype.STRIKEOUT,
4057
+ flags,
4040
4058
  rect,
4041
4059
  contents,
4042
4060
  segmentRects,
@@ -4067,12 +4085,14 @@ class PdfiumEngine {
4067
4085
  const color = this.getAnnotationColor(annotationPtr);
4068
4086
  const opacity = this.getAnnotationOpacity(annotationPtr);
4069
4087
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4088
+ const flags = this.getAnnotationFlags(annotationPtr);
4070
4089
  return {
4071
4090
  pageIndex: page.index,
4072
4091
  id: index,
4073
4092
  blendMode,
4074
4093
  type: PdfAnnotationSubtype.SQUIGGLY,
4075
4094
  rect,
4095
+ flags,
4076
4096
  contents,
4077
4097
  segmentRects,
4078
4098
  color: color ?? "#FF0000",
@@ -4097,11 +4117,13 @@ class PdfiumEngine {
4097
4117
  const author = this.getAnnotString(annotationPtr, "T");
4098
4118
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4099
4119
  const modified = pdfDateToDate(modifiedRaw);
4120
+ const flags = this.getAnnotationFlags(annotationPtr);
4100
4121
  return {
4101
4122
  pageIndex: page.index,
4102
4123
  id: index,
4103
4124
  type: PdfAnnotationSubtype.CARET,
4104
4125
  rect,
4126
+ flags,
4105
4127
  author,
4106
4128
  modified
4107
4129
  };
@@ -4123,23 +4145,15 @@ class PdfiumEngine {
4123
4145
  const author = this.getAnnotString(annotationPtr, "T");
4124
4146
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4125
4147
  const modified = pdfDateToDate(modifiedRaw);
4126
- const contents = [];
4127
- const objectCount = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr);
4128
- for (let i = 0; i < objectCount; i++) {
4129
- const annotationObjectPtr = this.pdfiumModule.FPDFAnnot_GetObject(annotationPtr, i);
4130
- const pageObj = this.readPdfPageObject(annotationObjectPtr);
4131
- if (pageObj) {
4132
- contents.push(pageObj);
4133
- }
4134
- }
4148
+ const flags = this.getAnnotationFlags(annotationPtr);
4135
4149
  return {
4136
4150
  pageIndex: page.index,
4137
4151
  id: index,
4138
4152
  type: PdfAnnotationSubtype.STAMP,
4139
4153
  rect,
4140
- contents,
4141
4154
  author,
4142
- modified
4155
+ modified,
4156
+ flags
4143
4157
  };
4144
4158
  }
4145
4159
  /**
@@ -4306,6 +4320,25 @@ class PdfiumEngine {
4306
4320
  this.free(matrixPtr);
4307
4321
  return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
4308
4322
  }
4323
+ /**
4324
+ * Read contents of a stamp annotation
4325
+ * @param annotationPtr - pointer to pdf annotation
4326
+ * @returns contents of the stamp annotation
4327
+ *
4328
+ * @private
4329
+ */
4330
+ readStampAnnotationContents(annotationPtr) {
4331
+ const contents = [];
4332
+ const objectCount = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr);
4333
+ for (let i = 0; i < objectCount; i++) {
4334
+ const annotationObjectPtr = this.pdfiumModule.FPDFAnnot_GetObject(annotationPtr, i);
4335
+ const pageObj = this.readPdfPageObject(annotationObjectPtr);
4336
+ if (pageObj) {
4337
+ contents.push(pageObj);
4338
+ }
4339
+ }
4340
+ return contents;
4341
+ }
4309
4342
  /**
4310
4343
  * Return the stroke-width declared in the annotation’s /Border or /BS entry.
4311
4344
  * Falls back to 1 pt when nothing is defined.
@@ -4453,9 +4486,11 @@ class PdfiumEngine {
4453
4486
  const author = this.getAnnotString(annotationPtr, "T");
4454
4487
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4455
4488
  const modified = pdfDateToDate(modifiedRaw);
4489
+ const flags = this.getAnnotationFlags(annotationPtr);
4456
4490
  return {
4457
4491
  pageIndex: page.index,
4458
4492
  id: index,
4493
+ flags,
4459
4494
  type,
4460
4495
  rect,
4461
4496
  author,
@@ -5567,4 +5602,4 @@ export {
5567
5602
  readArrayBuffer as c,
5568
5603
  readString as r
5569
5604
  };
5570
- //# sourceMappingURL=engine-O49988D4.js.map
5605
+ //# sourceMappingURL=engine-B11yoQGd.js.map