Scroll Plugin

The Scroll Plugin is a foundational plugin responsible for page layout, virtualization, and navigation. It provides the essential <Scroller /> component, which intelligently renders only the visible pages to ensure high performance, and the useScroll composable for building page navigation controls.

Installation

This plugin depends on the Viewport plugin. You must install both packages.

npm install @embedpdf/plugin-scroll @embedpdf/plugin-viewport

Registration

Import ScrollPluginPackage and its Viewport dependency, and add them to the plugins array.

import { createPluginRegistration } from '@embedpdf/core' // ... other imports import { ViewportPluginPackage } from '@embedpdf/plugin-viewport/svelte' import { ScrollPluginPackage, ScrollStrategy } from '@embedpdf/plugin-scroll/svelte' const plugins = [ // ... other essential plugins createPluginRegistration(LoaderPluginPackage, { /* ... */ }), createPluginRegistration(RenderPluginPackage), // Register dependencies first createPluginRegistration(ViewportPluginPackage), // Register and configure the scroll plugin createPluginRegistration(ScrollPluginPackage, { strategy: ScrollStrategy.Vertical, // or Horizontal initialPage: 1, }), ]

Usage

The plugin provides the <Scroller /> component for rendering pages and the useScroll composable for navigation.

The <Scroller /> and Snippets

The <Scroller /> component is the heart of the layout system. It must be placed inside a <Viewport />.

Crucially, the <Scroller /> does not render pages itself. Instead, it calculates which pages should be visible and uses your provided snippet to render each one. This gives you complete control over the content of each page placeholder.

<script lang="ts"> import { RenderLayer } from '@embedpdf/plugin-render/svelte'; import { Scroller, type RenderPageProps } from '@embedpdf/plugin-scroll/svelte'; import { Viewport } from '@embedpdf/plugin-viewport/svelte'; </script> {#snippet RenderPageSnippet(page: RenderPageProps)} <div style:width={`${page.width}px`} style:height={`${page.height}px`} style:position="relative"> <RenderLayer pageIndex={page.pageIndex} scale={page.scale} /> </div> {/snippet} <Viewport> <Scroller {RenderPageSnippet} /> </Viewport>

The useScroll composable provides everything you need to build a page navigation UI. It returns an object with a provides property for action methods and a state property with reactive data like the current page number.

<script lang="ts"> import { useScroll } from '@embedpdf/plugin-scroll/svelte'; const scroll = useScroll(); </script> {#if scroll.provides} <div> <span>Page {scroll.state.currentPage} of {scroll.state.totalPages}</span> <button onclick={() => scroll.provides?.scrollToNextPage()}>Next</button> </div> {/if}

Live Example

This example features a complete page navigation component that allows jumping to a specific page and moving forward or backward.

API Reference

Configuration (ScrollPluginConfig)

OptionTypeDescription
strategyScrollStrategySets the scroll direction. Can be ScrollStrategy.Vertical or ScrollStrategy.Horizontal.
Default: ScrollStrategy.Vertical
pageGapnumberThe space in pixels between pages or spreads.
Default: 10
initialPagenumberThe 1-based page number to scroll to when a document first loads.
bufferSizenumberThe number of pages to render outside the visible area for a smoother scrolling experience.
Default: 2

Component: <Scroller />

The virtualized container that lays out pages.

PropTypeDescription
RenderPageSnippetSnippet<RenderPageProps>(Required) A snippet that defines how to render each page. It receives a RenderPageProps object with layout data like pageIndex, width, height, and scale.

Composable: useScroll()

A convenience composable for building page navigation UIs.

Returns

An object with the following properties:

PropertyTypeDescription
providesScrollCapability | nullAn object with methods to control scrolling and navigation. null if the plugin is not ready.
stateobjectA reactive object containing the current scroll state.

state Properties

PropertyTypeDescription
currentPagenumberThe current page number that is most visible in the viewport.
totalPagesnumberThe total number of pages in the document.

provides Methods (ScrollCapability)

MethodDescription
scrollToPage(options)Scrolls to a specific page. The options object takes a pageNumber and optional behavior: 'smooth'.
scrollToNextPage()Scrolls to the next page or spread.
scrollToPreviousPage()Scrolls to the previous page or spread.
Last updated on October 22, 2025

Need Help?

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