Render Plugin
The Render Plugin is the visual heart of the PDF viewer. It is responsible for taking the raw PDF data from the core engine and “painting” it onto the screen. It supports high-fidelity rendering of text, images, vector graphics, and form widgets.
This plugin works seamlessly in multi-document environments, allowing you to render pages from different documents simultaneously using specific documentId references.
Installation
The plugin is available as a separate NPM package and is essential for any visual viewer.
npm install @embedpdf/plugin-renderRegistration
Import RenderPluginPackage and add it to the plugins array. You can configure global defaults for form and annotation rendering here.
import { createPluginRegistration } from '@embedpdf/core'
// ... other imports
import { RenderPluginPackage } from '@embedpdf/plugin-render/vue'
const plugins = [
// ... other essential plugins
createPluginRegistration(DocumentManagerPluginPackage, { /* ... */ }),
createPluginRegistration(ViewportPluginPackage),
createPluginRegistration(ScrollPluginPackage),
// Register the render plugin
createPluginRegistration(RenderPluginPackage, {
// Optional: Draw form widget visuals (checkboxes, text content)
// Note: This is for display only, not interaction.
withForms: true,
// Optional: Burn annotations into the render (usually handled by AnnotationPlugin instead)
withAnnotations: false,
}),
]Usage
The plugin allows you to render pages declaratively via the <RenderLayer /> component or imperatively via the useRenderCapability composable (e.g., for exporting images).
Primary Usage: The <RenderLayer /> Component
This is the standard way to display a page. Place the <RenderLayer /> component inside the default scoped slot of your <Scroller />.
You must provide the documentId to tell the renderer which document the page belongs to. The component automatically detects the current scale and refresh version from the document state.
<template>
<Scroller :document-id="activeDocumentId">
<template #default="{ page }">
<div :style="{ position: 'relative' }">
<RenderLayer
:document-id="activeDocumentId"
:page-index="page.pageIndex"
/>
</div>
</template>
</Scroller>
</template>Advanced Usage: On-Demand Rendering
For tasks like generating thumbnails, creating snapshots, or exporting pages as images, use the useRenderCapability composable.
Because multiple documents may be open, you must scope your request using .forDocument(id).
<script setup lang="ts">
import { useRenderCapability } from '@embedpdf/plugin-render/vue';
const props = defineProps<{ documentId: string }>();
const { provides: renderPlugin } = useRenderCapability();
const exportPage = () => {
// 1. Scope the renderer to the specific document
const renderer = renderPlugin.value?.forDocument(props.documentId);
// 2. Request a render
const task = renderer?.renderPage({
pageIndex: 0,
options: { scaleFactor: 2.0, imageType: 'image/png' }
});
task?.wait(blob => {
// ... handle the image blob (e.g., download it)
});
};
</script>
<template>
<button @click="exportPage">Export Page 1</button>
</template>Live Example
This example shows a PDF viewer with a custom “Export” toolbar. It uses the RenderPlugin to take a high-resolution snapshot of the first page, including annotations, and triggers a download.
API Reference
Configuration (RenderPluginConfig)
| Option | Type | Description |
|---|---|---|
withForms | boolean | If true, the visual appearance of form widgets (checkboxes, filled input text) will be drawn onto the page image. This does not create interactive elements. Default: false |
withAnnotations | boolean | If true, annotations will be baked into the page image. Default: false |
Component: <RenderLayer />
The component that renders a single PDF page.
| Prop | Type | Description |
|---|---|---|
documentId | string | (Required) The ID of the document this page belongs to. |
pageIndex | number | (Required) The 0-based index of the page to render. |
scale | number | Optional scale override. If omitted, uses the document’s current zoom level. |
dpr | number | The device pixel ratio to use. Default: window.devicePixelRatio |
Composable: useRenderCapability()
Access the rendering API.
Returns
| Property | Type | Description |
|---|---|---|
provides | Ref<RenderCapability | null> | The render API object. |
RenderCapability Methods
| Method | Description |
|---|---|
forDocument(id) | Returns a RenderScope for the specified document ID. |
RenderScope Methods (Returned by forDocument)
| Method | Description |
|---|---|
renderPage(options) | Renders a full page to a Blob. options: { pageIndex, options: PdfRenderPageOptions }. |
renderPageRect(options) | Renders a sub-region of a page. options: { pageIndex, rect, options: PdfRenderPageOptions }. |
PdfRenderPageOptions
| Option | Type | Description |
|---|---|---|
scaleFactor | number | The scale to render at. Default: 1.0. |
withAnnotations | boolean | Include annotations in render. Default: Plugin config value. |
withForms | boolean | Include form visuals in render. Default: Plugin config value. |
imageType | string | Output format: 'image/webp', 'image/jpeg', 'image/png'. |
imageQuality | number | 0 to 1 quality for lossy formats. |
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.