PDFreact-print-pdf
DocsBrowser-only alpha

Installation

Install react-print-pdf from npm.

Edit this page

react-print-pdf is published to npm as a stable release.

Install

npm install react-print-pdf

The 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 build

Run the demo app:

cd examples/demo
npm install
npm run dev

Open 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/starter

The 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.ready
  • FontFace
  • CanvasRenderingContext2D
  • fetch() for image/font bytes
  • URL.createObjectURL() for save/preview helpers

Modern Chromium, Firefox, and WebKit are covered by the test suite.

Runtime dependencies

The library uses:

DependencyRole
pdf-libPDF document creation and drawing
@pdf-lib/fontkitTTF/OTF parsing and font embedding
html-to-imageRaster 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";

On this page