@embedpdf/engine-services 3.0.0-next.8 → 3.0.0-next.9

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.
package/dist/index.cjs CHANGED
@@ -1727,6 +1727,42 @@ var PagesInserter = class {
1727
1727
  cache: null
1728
1728
  };
1729
1729
  }
1730
+ /**
1731
+ * Create `count` blank pages of `size` at `destIndex`. Same mutation
1732
+ * contract as `insert`, but native creation (`FPDFPage_New`) instead of a
1733
+ * deep copy: no source document, so none of the retain-until-close
1734
+ * lifetime hazard above. Each page gets an empty content stream
1735
+ * (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
1736
+ * third-party viewers.
1737
+ */
1738
+ insertBlank(spec, destIndex, signal) {
1739
+ throwIfAborted(signal);
1740
+ const { size } = spec;
1741
+ const count = spec.count ?? 1;
1742
+ if (!Number.isFinite(size?.width) || !Number.isFinite(size?.height) || size.width <= 0 || size.height <= 0) throw new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.InvalidArg, `pages.insertBlank size must have positive finite dimensions, got ${size?.width}x${size?.height}`);
1743
+ if (!Number.isInteger(count) || count < 1 || count > _embedpdf_engine_core_runtime.PAGE_INSERT_BLANK_MAX_COUNT) throw new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.InvalidArg, `pages.insertBlank count ${count} out of range [1, ${_embedpdf_engine_core_runtime.PAGE_INSERT_BLANK_MAX_COUNT}]`);
1744
+ const { fn } = this.runtime;
1745
+ const destPtr = this.session.requireDocPtr();
1746
+ const beforeCount = fn.FPDF_GetPageCount(destPtr);
1747
+ const at = destIndex ?? beforeCount;
1748
+ if (!Number.isInteger(at) || at < 0 || at > beforeCount) throw new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.InvalidArg, `pages.insertBlank destIndex ${at} out of range [0, ${beforeCount}]`);
1749
+ for (let i = 0; i < count; i++) {
1750
+ const pagePtr = fn.FPDFPage_New(destPtr, at + i, size.width, size.height);
1751
+ if (!pagePtr) {
1752
+ for (let j = 0; j < i; j++) fn.FPDFPage_Delete(destPtr, at);
1753
+ throw new _embedpdf_engine_core_runtime.EngineError(_embedpdf_engine_core_runtime.EngineErrorCode.Unknown, `FPDFPage_New rejected page ${i + 1}/${count} at index ${at + i}`);
1754
+ }
1755
+ fn.FPDFPage_GenerateContent(pagePtr);
1756
+ fn.FPDF_ClosePage(pagePtr);
1757
+ }
1758
+ this.session.refreshPageRegistry();
1759
+ const layout = new PagesReader(this.runtime, this.session).read(signal);
1760
+ return {
1761
+ insertedPageObjectNumbers: layout.pages.slice(at, at + count).map((page) => page.pageObjectNumber),
1762
+ layout,
1763
+ cache: null
1764
+ };
1765
+ }
1730
1766
  };
1731
1767
  //#endregion
1732
1768
  //#region src/features/annotations/internal/read/annotationReadContext.ts
@@ -9387,6 +9423,9 @@ var WorkerHost = class {
9387
9423
  case "pages.insert":
9388
9424
  resultPack = this.handlePagesInsert(msg, ctrl.signal);
9389
9425
  break;
9426
+ case "pages.insertBlank":
9427
+ resultPack = this.handlePagesInsertBlank(msg, ctrl.signal);
9428
+ break;
9390
9429
  case "attachments.list":
9391
9430
  resultPack = this.handleAttachmentsList(msg, ctrl.signal);
9392
9431
  break;
@@ -9679,6 +9718,17 @@ var WorkerHost = class {
9679
9718
  result
9680
9719
  }, req.artifactPath);
9681
9720
  }
9721
+ handlePagesInsertBlank(req, signal) {
9722
+ const session = this.requireSession(req);
9723
+ const result = new PagesInserter(this.runtime, session).insertBlank({
9724
+ size: req.size,
9725
+ count: req.count
9726
+ }, req.destIndex, signal);
9727
+ return this.finishMutation(session, {
9728
+ tag: "pages.insertBlank",
9729
+ result
9730
+ }, req.artifactPath);
9731
+ }
9682
9732
  handleAttachmentsList(req, signal) {
9683
9733
  const session = this.requireSession(req);
9684
9734
  return (0, _embedpdf_engine_core_runtime.wirePack)({