Overview of PDFx
main@react-pdf/renderer.repository·main·Indexed 22 days ago
https://github.com/akii09/pdfxA professional React PDF component library built on @react-pdf/renderer. PDFx uses a 'copy-and-own' model via a CLI (pdfx-cli) to scaffold pre-built components and templates (blocks) directly into a user's codebase, eliminating runtime dependencies. It includes a wide range of components such as tables, forms, and QR codes, supports server-side PDF generation with Node.js, and provides Model Context Protocol (MCP) configuration for AI agents.
@react-pdf/renderer.The theme system is designed to be local and transparent.
pdfx theme init creates a pdfx-theme.ts file in your local project.usePdfxTheme() hook.pdfx theme initPDFx uses a registry-based model similar to shadcn/ui. Instead of installing a monolithic npm package, you use the pdfx CLI to fetch component source code directly from the documentation website's registry.
When you run pdfx add <name>, the CLI fetches a JSON manifest from the HTTPS registry, which contains the source code for the component. The CLI then writes these files directly into your project. This means you own the code once it is added, and there are no runtime dependencies on a @pdfx/components package.
pdfx add <name>PDFx components are compatible with Node.js environments. You can use @react-pdf/renderer methods like renderToFile, renderToBuffer, or renderToStream to generate and save PDFs on the server (e.g., in Express or Next.js API routes).
import { renderToFile } from '@react-pdf/renderer';
import { Document, Page } from '@react-pdf/renderer';
import { Heading } from './src/components/pdfx/heading/pdfx-heading';
import { Text } from './src/components/pdfx/text/pdfx-text';
const doc = (
<Document>
<Page size="A4" style={{ padding: 40 }}>
<Heading level={1}>Monthly Report</Heading>
<Text>Generated server-side with PDFx.</Text>
</Page>
</Document>
);
// Write straight to disk:
await renderToFile(doc, './output.pdf');
// …or get a Buffer to return from an API route / attach to an email:
// const buffer = await renderToBuffer(doc);PDFx supports the Model Context Protocol (MCP), allowing AI IDEs or agents to access the PDFx registry for context about component structures. You can initialize this for specific clients like Cursor.
npx pdfx-cli@latest mcp init --client cursorBecause components are written directly into your project rather than being managed via package.json versions, you do not update them by bumping a package version. To update a component to the latest version from the registry, run the pdfx add command again using the --force flag.
pdfx add <name> --forceYou can add specific, individual PDFx components directly into your local codebase. This allows you to fully own and customize the component code within your project. Use the add command followed by the component name.
npx pdfx-cli@latest add badge
npx pdfx-cli@latest add table form qrcodeTo start using PDFx in your project, use the init command to set up the necessary configuration and project structure.
npx pdfx-cli@latest initPDFx provides a CLI to scaffold pre-built PDF components into your React project. This approach allows you to own the component code completely with no runtime dependency on the PDFx package.
npx pdfx-cli init to set up the necessary structure.npx pdfx-cli add <component-names> to copy specific components into your local ./components/pdfx directory. For example, to add heading, text, and badge, use:npx pdfx-cli add heading text badgenpx pdfx-cli init
npx pdfx-cli add heading text badgeInstead of individual components, you can add full, pre-designed templates (blocks) like invoices or reports using the block add command.
npx pdfx-cli@latest block add invoice-modern
npx pdfx-cli@latest block add report-financialIn version 0.6.0, fixes were introduced for DataTable, Table, and PdfList components regarding layout and width handling.
width props on TableCell or DataTable columns were ignored. The CLI now correctly respects width values in the following formats:100 for pt)"25%")"50px")bullet, numbered, checklist, icon, and multi-level).To apply these fixes to your existing installation, re-run the following commands:
pdfx add table
pdfx add data-table
pdfx add listThe PDFx registry provides a comprehensive set of components for building PDF documents. These components are exported from the main registry entrypoint and can be used to construct structured, styled layouts. Common component categories include:
Heading, Text, Link, Badge, KeyValue.Stack, Section, Divider, PageBreak, KeepTogether.Table, DataTable, PdfList, PdfCard, PdfGraph.PageHeader, PageFooter, PdfPageNumber, PdfWatermark.PdfForm, PdfSignatureBlock, PdfQRCode.PdfImage.All components accept props defined by their respective [ComponentName]Props types and generally adhere to the PDFComponentProps base type.