@embedpdf/engines 2.1.2 → 2.2.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 (41) hide show
  1. package/dist/direct-engine-CGBAQS04.cjs +2 -0
  2. package/dist/direct-engine-CGBAQS04.cjs.map +1 -0
  3. package/dist/{direct-engine-CB3k-o0I.js → direct-engine-DGRkMlJ8.js} +120 -3
  4. package/dist/direct-engine-DGRkMlJ8.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 +20 -0
  10. package/dist/lib/orchestrator/remote-executor.d.ts +5 -0
  11. package/dist/lib/pdfium/engine.d.ts +51 -0
  12. package/dist/lib/pdfium/index.cjs +1 -1
  13. package/dist/lib/pdfium/index.js +3 -3
  14. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  15. package/dist/lib/pdfium/web/direct-engine.js +2 -2
  16. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  17. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  18. package/dist/lib/pdfium/web/worker-engine.js +22 -2
  19. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  20. package/dist/lib/webworker/engine.cjs +1 -1
  21. package/dist/lib/webworker/engine.cjs.map +1 -1
  22. package/dist/lib/webworker/engine.d.ts +30 -0
  23. package/dist/lib/webworker/engine.js +73 -0
  24. package/dist/lib/webworker/engine.js.map +1 -1
  25. package/dist/{pdf-engine-BVNF_Yo9.js → pdf-engine-ChjNHvQd.js} +61 -1
  26. package/dist/{pdf-engine-BVNF_Yo9.js.map → pdf-engine-ChjNHvQd.js.map} +1 -1
  27. package/dist/pdf-engine-DgNNP62W.cjs +2 -0
  28. package/dist/{pdf-engine-C3JeKij1.cjs.map → pdf-engine-DgNNP62W.cjs.map} +1 -1
  29. package/dist/preact/index.cjs +1 -1
  30. package/dist/preact/index.js +1 -1
  31. package/dist/react/index.cjs +1 -1
  32. package/dist/react/index.js +1 -1
  33. package/dist/svelte/index.cjs +1 -1
  34. package/dist/svelte/index.js +1 -1
  35. package/dist/vue/index.cjs +1 -1
  36. package/dist/vue/index.js +1 -1
  37. package/package.json +4 -4
  38. package/dist/direct-engine-BeZ18SKz.cjs +0 -2
  39. package/dist/direct-engine-BeZ18SKz.cjs.map +0 -1
  40. package/dist/direct-engine-CB3k-o0I.js.map +0 -1
  41. package/dist/pdf-engine-C3JeKij1.cjs +0 -2
@@ -1,6 +1,6 @@
1
1
  import { init } from "@embedpdf/pdfium";
2
2
  import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
- import { P as PdfEngine } from "./pdf-engine-BVNF_Yo9.js";
3
+ import { P as PdfEngine } from "./pdf-engine-ChjNHvQd.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-awZxztMA.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
6
6
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
@@ -1102,10 +1102,16 @@ class PdfiumNative {
1102
1102
  pages.push(page);
1103
1103
  }
1104
1104
  this.memoryManager.free(sizePtr);
1105
+ const isEncrypted = this.pdfiumModule.EPDF_IsEncrypted(docPtr);
1106
+ const isOwnerUnlocked = this.pdfiumModule.EPDF_IsOwnerUnlocked(docPtr);
1107
+ const permissions = this.pdfiumModule.FPDF_GetDocPermissions(docPtr);
1105
1108
  const pdfDoc = {
1106
1109
  id: file.id,
1107
1110
  pageCount,
1108
- pages
1111
+ pages,
1112
+ isEncrypted,
1113
+ isOwnerUnlocked,
1114
+ permissions
1109
1115
  };
1110
1116
  this.cache.setDocument(file.id, filePtr, docPtr);
1111
1117
  this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
@@ -2543,6 +2549,117 @@ class PdfiumNative {
2543
2549
  }
2544
2550
  }
2545
2551
  }
2552
+ /**
2553
+ * Sets AES-256 encryption on a document.
2554
+ * Must be called before saveAsCopy() for encryption to take effect.
2555
+ *
2556
+ * @param doc - Document to encrypt
2557
+ * @param userPassword - Password to open document (empty = no open password)
2558
+ * @param ownerPassword - Password to change permissions (required)
2559
+ * @param allowedFlags - OR'd PdfPermissionFlag values indicating allowed actions
2560
+ * @returns true on success, false if already encrypted or invalid params
2561
+ *
2562
+ * @public
2563
+ */
2564
+ setDocumentEncryption(doc, userPassword, ownerPassword, allowedFlags) {
2565
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "setDocumentEncryption", doc, allowedFlags);
2566
+ const ctx = this.cache.getContext(doc.id);
2567
+ if (!ctx) {
2568
+ return PdfTaskHelper.reject({
2569
+ code: PdfErrorCode.DocNotOpen,
2570
+ message: "document does not open"
2571
+ });
2572
+ }
2573
+ const result = this.pdfiumModule.EPDF_SetEncryption(
2574
+ ctx.docPtr,
2575
+ userPassword,
2576
+ ownerPassword,
2577
+ allowedFlags
2578
+ );
2579
+ return PdfTaskHelper.resolve(result);
2580
+ }
2581
+ /**
2582
+ * Marks document for encryption removal on save.
2583
+ * When saveAsCopy is called, the document will be saved without encryption.
2584
+ *
2585
+ * @param doc - Document to remove encryption from
2586
+ * @returns true on success
2587
+ *
2588
+ * @public
2589
+ */
2590
+ removeEncryption(doc) {
2591
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "removeEncryption", doc);
2592
+ const ctx = this.cache.getContext(doc.id);
2593
+ if (!ctx) {
2594
+ return PdfTaskHelper.reject({
2595
+ code: PdfErrorCode.DocNotOpen,
2596
+ message: "document does not open"
2597
+ });
2598
+ }
2599
+ const result = this.pdfiumModule.EPDF_RemoveEncryption(ctx.docPtr);
2600
+ return PdfTaskHelper.resolve(result);
2601
+ }
2602
+ /**
2603
+ * Attempts to unlock owner permissions for an already-opened encrypted document.
2604
+ *
2605
+ * @param doc - Document to unlock
2606
+ * @param ownerPassword - The owner password
2607
+ * @returns true on success, false on failure
2608
+ *
2609
+ * @public
2610
+ */
2611
+ unlockOwnerPermissions(doc, ownerPassword) {
2612
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "unlockOwnerPermissions", doc.id);
2613
+ const ctx = this.cache.getContext(doc.id);
2614
+ if (!ctx) {
2615
+ return PdfTaskHelper.reject({
2616
+ code: PdfErrorCode.DocNotOpen,
2617
+ message: "document does not open"
2618
+ });
2619
+ }
2620
+ const success = this.pdfiumModule.EPDF_UnlockOwnerPermissions(ctx.docPtr, ownerPassword);
2621
+ return PdfTaskHelper.resolve(success);
2622
+ }
2623
+ /**
2624
+ * Check if a document is encrypted.
2625
+ *
2626
+ * @param doc - Document to check
2627
+ * @returns true if the document is encrypted
2628
+ *
2629
+ * @public
2630
+ */
2631
+ isEncrypted(doc) {
2632
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "isEncrypted", doc.id);
2633
+ const ctx = this.cache.getContext(doc.id);
2634
+ if (!ctx) {
2635
+ return PdfTaskHelper.reject({
2636
+ code: PdfErrorCode.DocNotOpen,
2637
+ message: "document does not open"
2638
+ });
2639
+ }
2640
+ const result = this.pdfiumModule.EPDF_IsEncrypted(ctx.docPtr);
2641
+ return PdfTaskHelper.resolve(result);
2642
+ }
2643
+ /**
2644
+ * Check if owner permissions are currently unlocked.
2645
+ *
2646
+ * @param doc - Document to check
2647
+ * @returns true if owner permissions are unlocked
2648
+ *
2649
+ * @public
2650
+ */
2651
+ isOwnerUnlocked(doc) {
2652
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "isOwnerUnlocked", doc.id);
2653
+ const ctx = this.cache.getContext(doc.id);
2654
+ if (!ctx) {
2655
+ return PdfTaskHelper.reject({
2656
+ code: PdfErrorCode.DocNotOpen,
2657
+ message: "document does not open"
2658
+ });
2659
+ }
2660
+ const result = this.pdfiumModule.EPDF_IsOwnerUnlocked(ctx.docPtr);
2661
+ return PdfTaskHelper.resolve(result);
2662
+ }
2546
2663
  /**
2547
2664
  * {@inheritDoc @embedpdf/models!PdfEngine.saveAsCopy}
2548
2665
  *
@@ -7305,4 +7422,4 @@ export {
7305
7422
  isValidCustomKey as i,
7306
7423
  readString as r
7307
7424
  };
7308
- //# sourceMappingURL=direct-engine-CB3k-o0I.js.map
7425
+ //# sourceMappingURL=direct-engine-DGRkMlJ8.js.map