@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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PdfFunctions, PdfRuntimeMemory, PdfRuntimeModule, Ptr } from "@embedpdf/engine-runtime";
2
- import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageNetworkRenderFormat, PageObjectNumber, PageRaster, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
2
+ import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageNetworkRenderFormat, PageObjectNumber, PageRaster, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
3
3
  //#region src/runtime/lifecycle/bootstrap.d.ts
4
4
  /**
5
5
  * Initialize the thread-confined PDFium runtime for the calling thread. Each
@@ -580,6 +580,15 @@ declare class PagesInserter {
580
580
  private readonly session;
581
581
  constructor(runtime: PdfRuntimeModule, session: DocumentSession);
582
582
  insert(bytes: ArrayBuffer, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
583
+ /**
584
+ * Create `count` blank pages of `size` at `destIndex`. Same mutation
585
+ * contract as `insert`, but native creation (`FPDFPage_New`) instead of a
586
+ * deep copy: no source document, so none of the retain-until-close
587
+ * lifetime hazard above. Each page gets an empty content stream
588
+ * (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
589
+ * third-party viewers.
590
+ */
591
+ insertBlank(spec: PageInsertBlankSpec, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
583
592
  }
584
593
  //#endregion
585
594
  //#region src/features/pages/PagesFlattener.d.ts
@@ -1513,6 +1522,7 @@ declare class WorkerHost {
1513
1522
  private handleRedactionApply;
1514
1523
  private handlePagesExtract;
1515
1524
  private handlePagesInsert;
1525
+ private handlePagesInsertBlank;
1516
1526
  private handleAttachmentsList;
1517
1527
  private handleAttachmentsReadFile;
1518
1528
  private handleAttachmentsCreate;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageNetworkRenderFormat, PageObjectNumber, PageRaster, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
1
+ import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageNetworkRenderFormat, PageObjectNumber, PageRaster, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
2
2
  import { PdfFunctions, PdfRuntimeMemory, PdfRuntimeModule, Ptr } from "@embedpdf/engine-runtime";
3
3
  //#region src/runtime/lifecycle/bootstrap.d.ts
4
4
  /**
@@ -580,6 +580,15 @@ declare class PagesInserter {
580
580
  private readonly session;
581
581
  constructor(runtime: PdfRuntimeModule, session: DocumentSession);
582
582
  insert(bytes: ArrayBuffer, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
583
+ /**
584
+ * Create `count` blank pages of `size` at `destIndex`. Same mutation
585
+ * contract as `insert`, but native creation (`FPDFPage_New`) instead of a
586
+ * deep copy: no source document, so none of the retain-until-close
587
+ * lifetime hazard above. Each page gets an empty content stream
588
+ * (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
589
+ * third-party viewers.
590
+ */
591
+ insertBlank(spec: PageInsertBlankSpec, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
583
592
  }
584
593
  //#endregion
585
594
  //#region src/features/pages/PagesFlattener.d.ts
@@ -1513,6 +1522,7 @@ declare class WorkerHost {
1513
1522
  private handleRedactionApply;
1514
1523
  private handlePagesExtract;
1515
1524
  private handlePagesInsert;
1525
+ private handlePagesInsertBlank;
1516
1526
  private handleAttachmentsList;
1517
1527
  private handleAttachmentsReadFile;
1518
1528
  private handleAttachmentsCreate;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AbortError, EMPTY_TRANSFER, EngineError, EngineErrorCode, NO_ANNOTATION_FLAGS, PDF_SUBTYPE_TO_CODE, PdfAnnotationSubtypeCode, UNKNOWN_WEAK_ANNOTATION_STATE, appearanceImpactOf, buildPageTextLayout, buildSnippet, charMapViolation, charRangeForTextOffsets, foldOptionsFor, foldText, invalidatesWeakIndexRefs, isValidPageObjectNumber, knownWeakAnnotationState, matchLiteral, matchRegex, normalizePdfRect, pdfQuadBounds, revisionTokensEqual, serializeError, shiftsExistingAnnotationIndices, sniffBinaryMetadata, subtypeFromCode, textSegmentsForRange, validateSearchQuery, wirePack } from "@embedpdf/engine-core/runtime";
1
+ import { AbortError, EMPTY_TRANSFER, EngineError, EngineErrorCode, NO_ANNOTATION_FLAGS, PAGE_INSERT_BLANK_MAX_COUNT, PDF_SUBTYPE_TO_CODE, PdfAnnotationSubtypeCode, UNKNOWN_WEAK_ANNOTATION_STATE, appearanceImpactOf, buildPageTextLayout, buildSnippet, charMapViolation, charRangeForTextOffsets, foldOptionsFor, foldText, invalidatesWeakIndexRefs, isValidPageObjectNumber, knownWeakAnnotationState, matchLiteral, matchRegex, normalizePdfRect, pdfQuadBounds, revisionTokensEqual, serializeError, shiftsExistingAnnotationIndices, sniffBinaryMetadata, subtypeFromCode, textSegmentsForRange, validateSearchQuery, wirePack } from "@embedpdf/engine-core/runtime";
2
2
  import { NULL_PTR } from "@embedpdf/engine-runtime";
3
3
  //#region src/runtime/lifecycle/bootstrap.ts
4
4
  const initialized = /* @__PURE__ */ new WeakSet();
@@ -1726,6 +1726,42 @@ var PagesInserter = class {
1726
1726
  cache: null
1727
1727
  };
1728
1728
  }
1729
+ /**
1730
+ * Create `count` blank pages of `size` at `destIndex`. Same mutation
1731
+ * contract as `insert`, but native creation (`FPDFPage_New`) instead of a
1732
+ * deep copy: no source document, so none of the retain-until-close
1733
+ * lifetime hazard above. Each page gets an empty content stream
1734
+ * (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
1735
+ * third-party viewers.
1736
+ */
1737
+ insertBlank(spec, destIndex, signal) {
1738
+ throwIfAborted(signal);
1739
+ const { size } = spec;
1740
+ const count = spec.count ?? 1;
1741
+ if (!Number.isFinite(size?.width) || !Number.isFinite(size?.height) || size.width <= 0 || size.height <= 0) throw new EngineError(EngineErrorCode.InvalidArg, `pages.insertBlank size must have positive finite dimensions, got ${size?.width}x${size?.height}`);
1742
+ if (!Number.isInteger(count) || count < 1 || count > PAGE_INSERT_BLANK_MAX_COUNT) throw new EngineError(EngineErrorCode.InvalidArg, `pages.insertBlank count ${count} out of range [1, ${PAGE_INSERT_BLANK_MAX_COUNT}]`);
1743
+ const { fn } = this.runtime;
1744
+ const destPtr = this.session.requireDocPtr();
1745
+ const beforeCount = fn.FPDF_GetPageCount(destPtr);
1746
+ const at = destIndex ?? beforeCount;
1747
+ if (!Number.isInteger(at) || at < 0 || at > beforeCount) throw new EngineError(EngineErrorCode.InvalidArg, `pages.insertBlank destIndex ${at} out of range [0, ${beforeCount}]`);
1748
+ for (let i = 0; i < count; i++) {
1749
+ const pagePtr = fn.FPDFPage_New(destPtr, at + i, size.width, size.height);
1750
+ if (!pagePtr) {
1751
+ for (let j = 0; j < i; j++) fn.FPDFPage_Delete(destPtr, at);
1752
+ throw new EngineError(EngineErrorCode.Unknown, `FPDFPage_New rejected page ${i + 1}/${count} at index ${at + i}`);
1753
+ }
1754
+ fn.FPDFPage_GenerateContent(pagePtr);
1755
+ fn.FPDF_ClosePage(pagePtr);
1756
+ }
1757
+ this.session.refreshPageRegistry();
1758
+ const layout = new PagesReader(this.runtime, this.session).read(signal);
1759
+ return {
1760
+ insertedPageObjectNumbers: layout.pages.slice(at, at + count).map((page) => page.pageObjectNumber),
1761
+ layout,
1762
+ cache: null
1763
+ };
1764
+ }
1729
1765
  };
1730
1766
  //#endregion
1731
1767
  //#region src/features/annotations/internal/read/annotationReadContext.ts
@@ -9386,6 +9422,9 @@ var WorkerHost = class {
9386
9422
  case "pages.insert":
9387
9423
  resultPack = this.handlePagesInsert(msg, ctrl.signal);
9388
9424
  break;
9425
+ case "pages.insertBlank":
9426
+ resultPack = this.handlePagesInsertBlank(msg, ctrl.signal);
9427
+ break;
9389
9428
  case "attachments.list":
9390
9429
  resultPack = this.handleAttachmentsList(msg, ctrl.signal);
9391
9430
  break;
@@ -9678,6 +9717,17 @@ var WorkerHost = class {
9678
9717
  result
9679
9718
  }, req.artifactPath);
9680
9719
  }
9720
+ handlePagesInsertBlank(req, signal) {
9721
+ const session = this.requireSession(req);
9722
+ const result = new PagesInserter(this.runtime, session).insertBlank({
9723
+ size: req.size,
9724
+ count: req.count
9725
+ }, req.destIndex, signal);
9726
+ return this.finishMutation(session, {
9727
+ tag: "pages.insertBlank",
9728
+ result
9729
+ }, req.artifactPath);
9730
+ }
9681
9731
  handleAttachmentsList(req, signal) {
9682
9732
  const session = this.requireSession(req);
9683
9733
  return wirePack({