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

@pdfn/react

v1.1.2

Published

React framework for print-ready PDFs

Readme

@pdfn/react

Node.js SDK for pdfn. Generate PDFs from React components.

Installation

npm install @pdfn/react

Quick Start

import { pdfn, Document, Page } from '@pdfn/react';
import fs from 'fs';

const client = pdfn(); // Auto-reads PDFN_API_KEY env var

const { data, error } = await client.generate({
  react: (
    <Document>
      <Page size="A4">
        <h1>Hello World</h1>
      </Page>
    </Document>
  ),
});

if (error) {
  console.error(error.message);
  process.exit(1);
}

fs.writeFileSync('output.pdf', data.buffer);

Set your API key as an environment variable:

export PDFN_API_KEY=pdfn_live_...

Get your API key at console.pdfn.dev.

Local Development

No API key needed — just start the dev server:

npx pdfn dev
const client = pdfn(); // No PDFN_API_KEY set → uses localhost:3456

Examples

With Tailwind CSS

npm install @pdfn/tailwind
import { Tailwind } from '@pdfn/tailwind';

const { data } = await client.generate({
  react: (
    <Document>
      <Tailwind>
        <Page size="A4">
          <h1 className="text-2xl font-bold">Styled PDF</h1>
        </Page>
      </Tailwind>
    </Document>
  ),
});

With Page Numbers

import { Document, Page, PageNumber, TotalPages } from '@pdfn/react';

<Page
  size="A4"
  footer={
    <div>
      Page <PageNumber /> of <TotalPages />
    </div>
  }
>
  {/* content */}
</Page>

Error Handling

const { data, error } = await client.generate({ react: <Invoice /> });

if (error) {
  console.error(error.code);    // "authentication_error"
  console.error(error.message); // "Invalid API key."
  console.error(error.suggestion); // "Check your PDFN_API_KEY..."
  return;
}

fs.writeFileSync('invoice.pdf', data.buffer);

Error codes: configuration_error, validation_error, authentication_error, rate_limit_error, timeout_error, server_error, network_error, render_error

API Reference

pdfn()

pdfn()                              // Auto-reads PDFN_API_KEY, falls back to localhost
pdfn('pdfn_live_...')               // Explicit API key
pdfn({ apiKey, baseUrl, timeout })  // Custom config

client.generate()

const { data, error } = await client.generate({
  react: <Invoice />,
  standard: 'PDF/A-2b',  // Archival compliance
  timeout: 60000,
});

client.render()

const { data, error } = await client.render({ react: <Invoice /> });
// data.html = self-contained HTML string

Components

| Component | Description | |-----------|-------------| | <Document> | Root wrapper (title, fonts, metadata) | | <Page> | Page container (size, margins, header/footer) | | <PageNumber> | Current page number | | <TotalPages> | Total page count | | <PageBreak> | Force page break | | <NoBreak> | Keep content together | | <Thead> | Repeating table header |

Page Sizes

A4 · Letter · Legal · A3 · A5 · Tabloid · B4 · B5 · ['6in', '9in']

TypeScript

Full TypeScript support with exported types:

import type {
  PdfnClient,
  PdfnConfig,
  PdfnError,
  GenerateResponse,
  RenderResponse,
  DocumentProps,
  PageProps,
} from '@pdfn/react';

License

MIT