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

@json-render/react-pdf

v0.13.0

Published

React PDF renderer for @json-render/core. JSON becomes PDF documents.

Readme

@json-render/react-pdf

React PDF renderer for @json-render/core. Generate PDF documents from JSON specs using @react-pdf/renderer.

Install

npm install @json-render/core @json-render/react-pdf

Quick Start

Render a spec to a PDF buffer

import { renderToBuffer } from "@json-render/react-pdf";
import type { Spec } from "@json-render/core";

const spec: Spec = {
  root: "doc",
  elements: {
    doc: { type: "Document", props: { title: "Invoice" }, children: ["page"] },
    page: {
      type: "Page",
      props: { size: "A4" },
      children: ["heading", "table"],
    },
    heading: {
      type: "Heading",
      props: { text: "Invoice #1234", level: "h1" },
      children: [],
    },
    table: {
      type: "Table",
      props: {
        columns: [
          { header: "Item", width: "60%" },
          { header: "Price", width: "40%", align: "right" },
        ],
        rows: [
          ["Widget A", "$10.00"],
          ["Widget B", "$25.00"],
        ],
      },
      children: [],
    },
  },
};

const buffer = await renderToBuffer(spec);

With a custom catalog

import { defineCatalog } from "@json-render/core";
import { schema, defineRegistry, renderToBuffer } from "@json-render/react-pdf";
import { standardComponentDefinitions } from "@json-render/react-pdf/catalog";
import { z } from "zod";

const catalog = defineCatalog(schema, {
  components: {
    ...standardComponentDefinitions,
    Badge: {
      props: z.object({
        label: z.string(),
        color: z.string().nullable(),
      }),
      slots: [],
      description: "A colored badge label",
    },
  },
  actions: {},
});

const { registry } = defineRegistry(catalog, {
  components: {
    Badge: ({ props }) => (
      <View style={{ backgroundColor: props.color ?? "#e5e7eb", padding: 4, borderRadius: 4 }}>
        <Text style={{ fontSize: 10 }}>{props.label}</Text>
      </View>
    ),
  },
});

const buffer = await renderToBuffer(spec, { registry });

Standard Components

Document Structure

| Component | Description | |-----------|-------------| | Document | Top-level PDF wrapper. Must be the root element. | | Page | A page with size (A4, LETTER, etc.), orientation, and margins. |

Layout

| Component | Description | |-----------|-------------| | View | Generic container with padding, margin, background, border. | | Row | Horizontal flex layout with gap, align, justify. | | Column | Vertical flex layout with gap, align, justify. |

Content

| Component | Description | |-----------|-------------| | Heading | h1-h4 heading text. | | Text | Body text with fontSize, color, weight, alignment. | | Image | Image from URL or base64. | | Link | Hyperlink with text and href. |

Data

| Component | Description | |-----------|-------------| | Table | Data table with typed columns and string rows. | | List | Ordered or unordered list. |

Decorative

| Component | Description | |-----------|-------------| | Divider | Horizontal line separator. | | Spacer | Empty vertical space. |

Page-Level

| Component | Description | |-----------|-------------| | PageNumber | Renders current page number and total pages. |

Server-Side APIs

import { renderToBuffer, renderToStream, renderToFile } from "@json-render/react-pdf";

// Render to an in-memory Buffer
const buffer = await renderToBuffer(spec);

// Render to a readable stream (pipe to HTTP response)
const stream = await renderToStream(spec);
stream.pipe(res);

// Render directly to a file
await renderToFile(spec, "./output.pdf");

All render functions accept an optional second argument with:

  • registry - Custom component registry (merged with standard components)
  • state - Initial state for $state / $cond dynamic prop resolution
  • handlers - Action handlers

External Store (Controlled Mode)

For full control over state, pass a StateStore to StateProvider, JSONUIProvider, or createRenderer. When store is provided, initialState and onStateChange are ignored and the store is the single source of truth:

import { createStateStore, type StateStore } from "@json-render/react-pdf";

const store = createStateStore({ invoice: { total: 100 } });

// Mutate from anywhere — components re-render automatically:
store.set("/invoice/total", 200);

Server-Safe Import

Import schema and catalog definitions without pulling in React:

import { schema, standardComponentDefinitions } from "@json-render/react-pdf/server";

License

Apache-2.0