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/client

v0.1.3

Published

Client-side rendering support for pdfn - enables Recharts and other client components in PDFs

Readme

@pdfn/client

Client-side rendering support for pdfn templates with React hooks.

Overview

@pdfn/client enables PDF generation from templates that use React hooks (like Recharts, interactive components). Unlike server-side rendering with renderToStaticMarkup, client rendering executes hooks by running React in the browser via Puppeteer.

When to Use

Use @pdfn/client when your templates contain:

  • Charting libraries — Recharts, Victory, Chart.js with React wrappers
  • Components with hooksuseState, useEffect, useRef
  • Animation libraries — Framer Motion, React Spring
  • Any "use client" components

How It Works

Standard SSR (hooks skipped):
┌─────────────────────────────────────────────┐
│ renderToStaticMarkup(Template)              │
│   └── Recharts hooks skipped → empty divs   │
└─────────────────────────────────────────────┘

Client rendering (hooks execute):
┌─────────────────────────────────────────────┐
│ 1. Detect "use client" in template          │
│ 2. Bundle template with esbuild             │
│ 3. Generate HTML with embedded bundle       │
│ 4. Puppeteer loads HTML → React renders     │
│    (hooks execute, charts appear)           │
│ 5. Paged.js paginates → PDF                 │
└─────────────────────────────────────────────┘

Installation

@pdfn/client is included automatically when you install @pdfn/next or @pdfn/vite. You don't need to install it separately.

Usage

Automatic detection

When using @pdfn/next or @pdfn/vite, client components are detected automatically via the "use client" directive:

// pdfn-templates/report.tsx
"use client";

import { BarChart, Bar, XAxis, YAxis } from 'recharts';

export default function Report({ data }) {
  return (
    <Document>
      <Page size="A4">
        <BarChart width={600} height={300} data={data}>
          <XAxis dataKey="name" />
          <YAxis />
          <Bar dataKey="value" fill="#8884d8" />
        </BarChart>
      </Page>
    </Document>
  );
}

Manual Usage

import { bundleForClient, generateClientHtml, hasClientMarkers } from '@pdfn/client';

// Check if template needs client rendering
if (hasClientMarkers(element)) {
  // Bundle template for browser
  const bundle = await bundleForClient({
    templatePath: '/path/to/template.tsx',
    props: { data: [...] },
    cwd: process.cwd(),
  });

  // Generate HTML with embedded bundle
  const html = generateClientHtml({
    bundleCode: bundle,
    title: 'Report',
    css: compiledTailwindCss,
  });
}

Build-Time Bundling

For production, templates are pre-bundled at build time:

Next.js

// next.config.ts
import { withPdfn } from '@pdfn/next';

export default withPdfn({
  // Your Next.js config
});

Vite

// vite.config.ts
import { pdfn } from '@pdfn/vite';

export default {
  plugins: [pdfn()],
};

API

bundleForClient(options)

Bundles a template for client-side rendering.

const bundle = await bundleForClient({
  templatePath: string,    // Absolute path to template
  props?: object,          // Props to pass to template
  cwd?: string,            // Working directory
  debug?: boolean,         // Enable debug logging
});

generateClientHtml(options)

Generates HTML that loads and renders the bundled template.

const html = generateClientHtml({
  bundleCode: string,      // Output from bundleForClient
  title?: string,          // Document title
  css?: string,            // CSS to include
  pageSize?: string,       // e.g., "A4"
  orientation?: string,    // "portrait" or "landscape"
});

hasClientMarkers(element)

Checks if a React element tree contains client component markers.

const needsClientRendering = hasClientMarkers(<MyTemplate />);

Peer Dependencies

  • react ^18.0.0 || ^19.0.0
  • react-dom ^18.0.0 || ^19.0.0

License

MIT