Capture Plugin

The Capture Plugin provides a “snapshot” tool, allowing users to select a rectangular area (a marquee) on any page and export that specific section as a high-resolution image.

Installation

This plugin depends on the Render and Interaction Manager plugins. You must install all three packages.

npm install @embedpdf/plugin-capture @embedpdf/plugin-render @embedpdf/plugin-interaction-manager

Registration

Import CapturePluginPackage and its dependencies, then add them to the plugins array. The dependencies should be registered before the capture plugin.

import { createPluginRegistration } from '@embedpdf/core' // ... other imports import { RenderPluginPackage } from '@embedpdf/plugin-render/vue' import { InteractionManagerPluginPackage } from '@embedpdf/plugin-interaction-manager/vue' import { CapturePluginPackage } from '@embedpdf/plugin-capture/vue' const plugins = [ // ... other essential plugins createPluginRegistration(DocumentManagerPluginPackage, { /* ... */ }), createPluginRegistration(ViewportPluginPackage), createPluginRegistration(ScrollPluginPackage), // Register dependencies first createPluginRegistration(RenderPluginPackage), createPluginRegistration(InteractionManagerPluginPackage), // Register and configure the capture plugin createPluginRegistration(CapturePluginPackage, { scale: 2.0, // Render captured image at 2x resolution imageType: 'image/png', withAnnotations: true, }), ]

Usage

The plugin works by combining a UI component to draw the selection area, a composable to control the capture mode, and an event listener to handle the final image.

1. Add the <MarqueeCapture /> Component

To enable the visual selection tool, place the <MarqueeCapture /> component inside the <Scroller />’s default slot. It must be a child of <PagePointerProvider> to correctly handle mouse or touch interactions.

<script setup lang="ts"> import { PagePointerProvider } from '@embedpdf/plugin-interaction-manager/vue'; import { MarqueeCapture } from '@embedpdf/plugin-capture/vue'; </script> <template> <Scroller :document-id="activeDocumentId"> <template #default="{ page }"> <PagePointerProvider :document-id="activeDocumentId" :page-index="page.pageIndex"> <RenderLayer :document-id="activeDocumentId" :page-index="page.pageIndex" /> <MarqueeCapture :document-id="activeDocumentId" :page-index="page.pageIndex" /> </PagePointerProvider> </template> </Scroller> </template>

2. Build a Toolbar Button

Use the useCapture composable to get access to the plugin’s methods for a specific document. The toggleMarqueeCapture() method activates and deactivates the selection mode.

<script setup lang="ts"> import { useCapture } from '@embedpdf/plugin-capture/vue'; const props = defineProps<{ documentId: string }>(); const { provides: capture, state } = useCapture(() => props.documentId); const isActive = computed(() => state.value.isMarqueeCaptureActive); </script> <template> <button @click="capture?.toggleMarqueeCapture()"> {{ isActive ? 'Cancel' : 'Capture Area' }} </button> </template>

3. Handle the Captured Image

After the user selects an area, the plugin fires an event with the resulting image data. You must listen for this event using the onCaptureArea method to receive the Blob. From there, you can display the image or trigger a download.

<script setup lang="ts"> import { ref, onMounted, onUnmounted, computed } from 'vue'; import { useCapture, type CaptureAreaEvent } from '@embedpdf/plugin-capture/vue'; const props = defineProps<{ documentId: string }>(); const { provides: capture } = useCapture(() => props.documentId); const imageUrl = ref<string | null>(null); let unsubscribe: (() => void) | undefined; onMounted(() => { if (!capture.value) return; unsubscribe = capture.value.onCaptureArea((result: CaptureAreaEvent) => { const newUrl = URL.createObjectURL(result.blob); imageUrl.value = newUrl; }); }); onUnmounted(() => { unsubscribe?.(); if (imageUrl.value) URL.revokeObjectURL(imageUrl.value); }); </script> <template> <p v-if="!imageUrl">Select an area to capture.</p> <img v-else :src="imageUrl" alt="Captured PDF area" /> </template>

Live Example

Click the “Capture Area” button, then click and drag a rectangle over the PDF. The selected area will appear below as an image, with a button to download it.

API Reference

Configuration (CapturePluginConfig)

OptionTypeDescription
scalenumberThe resolution multiplier for the captured image. A value of 2 means 2x resolution. Default: 1
imageTypestringThe image format, e.g., 'image/png', 'image/jpeg'. Default: 'image/png'
withAnnotationsbooleanIf true, annotations will be included in the captured image. Default: false

Component: <MarqueeCapture />

The component that renders the visual selection rectangle.

PropTypeDescription
documentIdstring(Required) The ID of the document.
pageIndexnumber(Required) The page index this component is rendered on.
classstringOptional CSS class for custom styling of the marquee.
strokestringThe color of the marquee’s border.
fillstringThe background color of the marquee.

Composable: useCapture(documentId)

Connects your component to the capture plugin’s state and functions for a specific document.

Parameters

ParameterTypeDescription
documentId() => stringA getter function that returns the document ID to track.

Returns

PropertyTypeDescription
stateRef<CaptureState>A ref object containing the current state, such as isMarqueeCaptureActive.
providesRef<CaptureScope | null>A ref object with methods to interact with the plugin, or null if not ready.

CaptureScope Methods

MethodDescription
toggleMarqueeCapture()Toggles the marquee selection mode on or off.
onCaptureArea(callback)Subscribes to the capture event. The callback receives a CaptureAreaEvent object when an area is successfully captured.
captureArea(pageIndex, rect)Programmatically captures a specified rectangular area on a page.

Event: CaptureAreaEvent

The object passed to the onCaptureArea callback after a successful capture.

PropertyTypeDescription
pageIndexnumberThe index of the page where the capture occurred.
rectRectAn object describing the position and size of the captured area in PDF points.
blobBlobThe captured image data as a Blob object.
imageTypestringThe MIME type of the captured image (e.g., 'image/png').
scalenumberThe resolution scale factor used for the capture.
Last updated on December 5, 2025

Need Help?

Join our community for support, discussions, and to contribute to EmbedPDF's development.