This demo opens the same sample PDF three ways: a direct client import, a browser-only dynamic import, and a toolbar you render yourself. Each section below links to the live page and shows the code to create that example in your own app.
PdfEditor views and edits a PDF in the browser. Rendering uses PDF.js. Export uses pdf-lib and writes annotations into a new file. Annotations stay in memory until you export.
Text boxes, freehand ink, highlights, images, and signatures
Page thumbnails, blank pages, delete, and drag-to-reorder
In-document search, zoom, undo, and redo
Export that flattens edits into a downloadable PDF
How to create these examples
Install the package, import the stylesheet once, and give the editor a height. The root fills its parent, so a parent with no height collapses the page canvas. file accepts a URL string, URL, File, Blob, ArrayBuffer, or Uint8Array.
1. Install
Peer dependencies are React and React DOM 18 or later. This demo uses pnpm; the same package name works with npm.
Terminalbash
npm install react-web-pdf-editor
2. Quick start
Put the editor in a client component and render it from a route. The live page is /quick-start. Import react-web-pdf-editor/styles.css or the toolbar and pages have no layout.
import type { Metadata } from "next";
import { QuickStart } from "@/components/quick-start";
export const metadata: Metadata = {
title: "Quick start",
description:
"A client component that renders PdfEditor with a file URL and a document name.",
};
export default function QuickStartPage() {
return <QuickStart />;
}
3. Basic demo for Next.js
The editor talks to workers, canvas, and window while it renders. Load it with next/dynamic and ssr: false. The live page is /basic-demo.
Pass toolbar to draw your own bar. The callback receives ToolbarApi: document name, history, the active tool, zoom, page navigation, search, and export. The live page is /custom, and the full bar lives in components/custom-toolbar.tsx. Start from this smaller toolbar, then add the tools you need.