npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-export-doc

v0.1.1

Published

A simple way to export React components as downloadable PDF files.

Readme

react-export-doc

A simple way to export React components as downloadable PDF files.

npm license

react-export-doc lets you render normal React components and export them as a multi-page, A4-sized PDF — with automatic page breaks, continuous page numbering, and shared headers/footers.

Features

  • 🖨️ Export any React component to a downloadable PDF
  • 📄 Automatic A4 page splitting (respects break-inside: avoid)
  • 🔢 Continuous page numbering across multiple documents
  • 🧩 Shared headers/footers via render props
  • ⚛️ Works with React 18+ and Next.js App Router (ships with "use client")

Installation

npm install react-export-doc

react and react-dom (>=18) are peer dependencies, so make sure they are installed in your project.

Quick Start

1. Wrap your app with ReactDocProvider

// app/layout.tsx (Next.js App Router)
import { ReactDocProvider } from 'react-export-doc';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <ReactDocProvider>{children}</ReactDocProvider>
      </body>
    </html>
  );
}

2. Define the document you want to export

import { Document, DocumentGroup } from 'react-export-doc';

export function MyDocument() {
  return (
    <DocumentGroup>
      <Document>
        <h1>Invoice</h1>
        <p>Thanks for your purchase!</p>
      </Document>
    </DocumentGroup>
  );
}

3. Trigger the export with useExportDoc

'use client';

import { useExportDoc } from 'react-export-doc';
import { MyDocument } from './MyDocument';

export function ExportButton() {
  const { exportPDF } = useExportDoc();

  return <button onClick={() => exportPDF(<MyDocument />, { filename: 'invoice.pdf' })}>Export PDF</button>;
}

API

<ReactDocProvider>

Provides the export context. Must wrap any component that uses useExportDoc.

| Prop | Type | Description | | ---------- | ----------- | ---------------- | | children | ReactNode | Your application |

useExportDoc()

Returns an object with the export function. Must be used inside ReactDocProvider.

const { exportPDF } = useExportDoc();

exportPDF(component: ReactNode, options: { filename: string }): Promise<void>;

<DocumentGroup>

Groups multiple Documents so their page numbers are continuous and lets you apply shared headers/footers.

| Prop | Type | Description | | -------------- | ---------------------------------------- | ---------------------------- | | children | ReactNode | One or more <Document> | | renderHeader | (currentPage, totalPages) => ReactNode | Header applied to every page | | renderFooter | (currentPage, totalPages) => ReactNode | Footer applied to every page |

<Document>

Renders content and automatically splits it into A4 pages.

| Prop | Type | Description | | -------------- | ---------------------------------------- | --------------------------------------------------------------- | | children | ReactNode | The content to paginate | | pageTopItems | ReactNode | Element repeated at the top of every page (e.g. a table header) | | renderHeader | (currentPage, totalPages) => ReactNode | Overrides the group header for this document | | renderFooter | (currentPage, totalPages) => ReactNode | Overrides the group footer for this document |

Helper components

<Header title> and <Footer currentPage totalPages> are optional presentational components you can use inside renderHeader / renderFooter.

Example

<DocumentGroup
  renderHeader={(page, total) => <Header title="Monthly Report" currentPage={page} totalPages={total} />}
  renderFooter={(page, total) => <Footer currentPage={page} totalPages={total} />}
>
  <Document>{/* page 1..n */}</Document>
  <Document>{/* continues numbering */}</Document>
</DocumentGroup>

Requirements

  • React 18 or later
  • A browser environment (PDF generation relies on the DOM via html2canvas-pro and jsPDF)

License

MIT © hyoni0817