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-document-manager @embedpdf/plugin-viewport @embedpdf/plugin-scroll @embedpdf/plugin-render2. 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 { Viewport, ViewportPluginPackage } from '@embedpdf/plugin-viewport/react';
import { Scroller, ScrollPluginPackage } from '@embedpdf/plugin-scroll/react';
import {
DocumentContent,
DocumentManagerPluginPackage,
} from '@embedpdf/plugin-document-manager/react';
import { RenderLayer, RenderPluginPackage } from '@embedpdf/plugin-render/react';
// 1. Register the plugins you need
const plugins = [
createPluginRegistration(DocumentManagerPluginPackage, {
initialDocuments: [{ 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}>
{({ activeDocumentId }) =>
activeDocumentId && (
<DocumentContent documentId={activeDocumentId}>
{({ isLoaded }) =>
isLoaded && (
<Viewport
documentId={activeDocumentId}
style={{
backgroundColor: '#f1f3f5',
}}
>
<Scroller
documentId={activeDocumentId}
renderPage={({ width, height, pageIndex }) => (
<div style={{ width, height }}>
{/* The RenderLayer is responsible for drawing the page */}
<RenderLayer
documentId={activeDocumentId}
pageIndex={pageIndex}
/>
</div>
)}
/>
</Viewport>
)
}
</DocumentContent>
)
}
</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:
You now have a functional PDF viewer!
Next Steps
- Discover how to add more features by Understanding Plugins.
Last updated on December 5, 2025
Need Help?
Join our community for support, discussions, and to contribute to EmbedPDF's development.