DocsReactGetting Started

Getting Started

Let’s build a basic, scrollable PDF viewer. This guide will walk you through the essential setup.

1. Installation

You’ll need a few packages to create a minimal viewer: the core library, the engine, and a few essential plugins.

npm install @embedpdf/core @embedpdf/engines @embedpdf/plugin-loader @embedpdf/plugin-viewport @embedpdf/plugin-scroll @embedpdf/plugin-render

2. Create Your Viewer Component

The core of your viewer will be the <EmbedPDF> component, which manages the engine and plugins.

Here is a minimal PDFViewer component that loads a document from a URL and renders it in a vertically scrollable viewport.

PDFViewer.tsx
import { createPluginRegistration } from '@embedpdf/core'; import { EmbedPDF } from '@embedpdf/core/react'; import { usePdfiumEngine } from '@embedpdf/engines/react'; // Import the essential plugins import { ViewportPluginPackage } from '@embedpdf/plugin-viewport'; import { Viewport } from '@embedpdf/plugin-viewport/react'; import { ScrollPluginPackage } from '@embedpdf/plugin-scroll'; import { Scroller } from '@embedpdf/plugin-scroll/react'; import { LoaderPluginPackage } from '@embedpdf/plugin-loader'; import { RenderPluginPackage } from '@embedpdf/plugin-render'; import { RenderLayer } from '@embedpdf/plugin-render/react'; // 1. Register the plugins you need const plugins = [ createPluginRegistration(LoaderPluginPackage, { loadingOptions: { type: 'url', pdfFile: { id: 'example-pdf', url: 'https://snippet.embedpdf.com/ebook.pdf', }, }, }), createPluginRegistration(ViewportPluginPackage), createPluginRegistration(ScrollPluginPackage), createPluginRegistration(RenderPluginPackage), ]; export const PDFViewer = () => { // 2. Initialize the engine with the React hook const { engine, isLoading } = usePdfiumEngine(); if (isLoading || !engine) { return <div>Loading PDF Engine...</div>; } // 3. Wrap your UI with the <EmbedPDF> provider return ( <div style={{ height: '500px' }}> <EmbedPDF engine={engine} plugins={plugins}> <Viewport style={{ backgroundColor: '#f1f3f5', }} > <Scroller renderPage={({ width, height, pageIndex }) => ( <div style={{ width, height }}> {/* The RenderLayer is responsible for drawing the page */} <RenderLayer pageIndex={pageIndex} /> </div> )} /> </Viewport> </EmbedPDF> </div> ); };

3. Render Your Component

Finally, add your new PDFViewer component to your main application file.

App.tsx
import { PDFViewer } from './PDFViewer'; function App() { return <PDFViewer />; } export default App;

Interactive Example

When you run the code above, it will produce a functional, scrollable PDF viewer like the one shown here:

Loading PDF Engine...

You now have a functional PDF viewer!

Next Steps

Last updated on August 14, 2025

Need Help?

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