Installation
Install react-print-pdf from npm.
react-print-pdf is published to npm as a stable release.
Install
npm install react-print-pdfThe current stable version is 0.2.0. Earlier prereleases (0.1.0-alpha.0, 0.2.0-beta.*) are still available under the alpha and beta dist-tags for projects that pinned to them, but new code should target latest.
Peer dependencies
The package targets browser apps using React 18 or React 19:
{
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
}
}Try the repository locally
If you want to hack on the library itself or run the demo:
git clone https://github.com/hempun10/react-print-pdf.git
cd react-print-pdf
npm install
npm run buildRun the demo app:
cd examples/demo
npm install
npm run devOpen the local URL, choose a fixture, and click Export PDF.
Try it without cloning
A minimal starter ships under examples/starter. Open it in StackBlitz directly off the GitHub path:
https://stackblitz.com/github/hempun10/react-print-pdf/tree/main/examples/starterThe starter is a standard Vite + React + react-print-pdf app: one Invoice component and one Export PDF button. Replace Invoice.tsx with your own document to evaluate the library against real content.
Browser requirements
The exporter runs in the browser because it depends on real layout information:
getComputedStyle()getBoundingClientRect()Range.getClientRects()document.fonts.readyFontFaceCanvasRenderingContext2Dfetch()for image/font bytesURL.createObjectURL()for save/preview helpers
Modern Chromium, Firefox, and WebKit are covered by the test suite.
Runtime dependencies
The library uses:
| Dependency | Role |
|---|---|
pdf-lib | PDF document creation and drawing |
@pdf-lib/fontkit | TTF/OTF parsing and font embedding |
html-to-image | Raster fallback for browser-only effects |
The library entry is around 10 kB gzipped; the full bundle (with pdf-lib + fontkit + html-to-image) is around 440 kB gzipped.
TypeScript
Types ship with the package. The public API is intentionally narrow:
import {
exportToPDF,
registerFont,
PageBreak,
PRINT_REPEAT_ATTR,
PdfExportError,
isPdfExportError,
// React DX layer
usePDFExport,
Printable,
ExportButton,
PRINTABLE_ATTR,
type ExportOptions,
type PDFExportResult,
type PdfExportErrorCode,
type UsePDFExportOptions,
type UsePDFExportReturn,
type PrintableProps,
type ExportButtonProps,
} from "react-print-pdf";