Rasterex APINPM Package/docs/components/pdf/page-insert

Page Insert

Insert pages from another PDF into the current PDF with page-insert using the SDK.

Overview

The page-insert action imports pages from another PDF file into the current PDF. The parent provides a browser File object and identifies which source pages should be inserted.

The target location is defined by pageRange in the current PDF, while selectedPages identifies the pages to import from the source file.

  • Required fields: pageRange, file, and selectedPages.
  • The file value must be the source PDF chosen in the parent application.
  • Use this action when you are adding pages without replacing existing ones.

Example

Pick the source PDF from a file input, then invoke the insert operation with the selected source pages.

typescript
const sourceFile = fileInput.files?.[0];

if (sourceFile) {
  // Insert pages index 0 and 1 from source file at page index 2 in active document
  await viewer.documents.manipulatePages({
    action: "page-insert",
    pageRange: [[2]],
    file: sourceFile,
    selectedPages: [[0, 1]]
  });
}
Example

Vanilla TS Integration

Example showing how to insert pages programmatically:

typescript
import { createViewer } from "@rasterex/viewer";

const viewer = createViewer({
  container: "#viewer"
});

await viewer.mount();
await viewer.ready();

async function handleFileInsert(sourceFile: File, targetIndex: number): Promise<void> {
  try {
    await viewer.documents.manipulatePages({
      action: "page-insert",
      pageRange: [[targetIndex]],
      file: sourceFile,
      selectedPages: [[0]] // Insert the first page of the source file
    });
    console.log("Pages inserted successfully");
  } catch (error) {
    console.error("Insertion failed:", error);
  }
}
Vanilla TS Integration

Live Preview

Open the focused demo to test page insertion from another PDF file.

PDF Page Insert Demo

Focused live demo for page-insert.

Preview opens in a large modal for zoom-friendly review.