@react-pdf/render vs @react-pdf/renderer
React PDF Generation Libraries
@react-pdf/render@react-pdf/rendererSimilar Packages:

React PDF Generation Libraries

React PDF generation libraries are designed to facilitate the creation of PDF documents directly from React components. They allow developers to define the layout and content of a PDF using familiar React syntax, enabling a seamless integration of PDF generation into React applications. These libraries typically provide features such as styling, layout control, and the ability to include images and text, making it easier to produce high-quality, customizable PDF files for various use cases, such as reports, invoices, and downloadable content.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@react-pdf/render016,77099.5 kB3179 days agoMIT
@react-pdf/renderer016,770320 kB3179 days agoMIT

Feature Comparison: @react-pdf/render vs @react-pdf/renderer

Rendering Capabilities

  • @react-pdf/render:

    @react-pdf/render is optimized for straightforward PDF rendering from React components. It allows developers to quickly convert simple React components into PDF documents, making it suitable for basic use cases where complex layouts are not required.

  • @react-pdf/renderer:

    @react-pdf/renderer provides advanced rendering capabilities, allowing for detailed control over the layout and design of PDF documents. It supports a wide range of styling options, including custom fonts, colors, and positioning, making it ideal for creating visually rich and complex PDF files.

Styling and Layout

  • @react-pdf/render:

    This package offers basic styling options, enabling developers to apply simple styles to their PDF content. However, it may lack the depth needed for more intricate designs.

  • @react-pdf/renderer:

    @react-pdf/renderer excels in styling and layout control, providing a rich set of features for defining styles, margins, padding, and responsive layouts. It supports CSS-like styling, making it easier to create visually appealing documents.

Complex Document Support

  • @react-pdf/render:

    @react-pdf/render is best suited for generating simpler documents and may struggle with more complex document structures that require advanced features.

  • @react-pdf/renderer:

    @react-pdf/renderer is designed to handle complex documents, including multi-page layouts, tables, and nested components. It is ideal for applications that require detailed document structures.

Performance

  • @react-pdf/render:

    Performance is generally good for simple documents, but it may face challenges when rendering larger or more complex PDFs due to its limited optimization features.

  • @react-pdf/renderer:

    @react-pdf/renderer is optimized for performance, especially when dealing with larger documents. It employs efficient rendering techniques to minimize memory usage and improve rendering speed.

Community and Support

  • @react-pdf/render:

    This package has a smaller community and fewer resources available for troubleshooting and support compared to its counterpart.

  • @react-pdf/renderer:

    @react-pdf/renderer benefits from a larger community and more extensive documentation, providing better support and resources for developers facing challenges.

How to Choose: @react-pdf/render vs @react-pdf/renderer

  • @react-pdf/render:

    Choose @react-pdf/render if you need a more straightforward solution that focuses on rendering PDF documents from React components without the need for additional features like document manipulation or complex layouts. It is ideal for simple use cases where you want to quickly convert React components to PDF.

  • @react-pdf/renderer:

    Choose @react-pdf/renderer if you require a more comprehensive solution that offers extensive features for styling and layout control. This package provides a rich API for creating complex PDF documents, including support for advanced styling, text formatting, and layout capabilities, making it suitable for applications that demand high-quality, customizable PDF outputs.

README for @react-pdf/render

@react-pdf/render

React-pdf render engine

Installation

yarn add @react-pdf/render

How it works

import render from '@react-pdf/render';
import primitives from '@react-pdf/primitives';

const view = {
  type: primitives.View,
  style: {
    backgroundColor: 'red',
    borderTopLeftRadius: 5,
    borderTopRightRadius: 10,
    borderBottomLeftRadius: 0,
    borderBottomRightRadius: 15,
    borderTopColor: 'yellow',
    borderLeftColor: 'green',
    borderBottomColor: 'black',
    borderRightColor: 'purple',
  },
  box: {
    left: 20,
    top: 20,
    width: 100,
    height: 80,
    borderTopWidth: 3,
    borderLeftWidth: 2,
    borderBottomWidth: 1,
    borderRightWidth: 4,
  },
};

const doc = {
  type: primitives.Document,
  children: [
    {
      type: primitives.Page,
      box: { width: 400, height: 600 },
      children: [view],
    },
  ],
};

// Provide your own context
const ctx = createContext();

render.default(ctx, doc);

This library exports a render function that takes two arguments:

  • ctx: This is the target context where the document is going to be rendered. React-pdf currently uses a pdfkit document as context, but it can target any other type of structure as long as it signature matches pdfkit API. In the future this will enable rendering documents into muliple formats in addition to PDF.
  • node: Document root node. A node is a nested structure that defines a single element in a document. They are defined by it's type and arguments.

Node structure

A node represents a single element inside a document. It's mainly defined by it's type (mandatory) field in addition to other values to define where that element is positioned inside the document (box), how it looks (style), how it should behave (params) and what sub-nodes it contains (children).

The root node must always be of type DOCUMENT, containing as many PAGE nodes as desired inside it's children field.

Bare in mind this package does not handle any type of node positioning, inheritance, style transformations or any other layout related logic. It's role is limited to render exactly the node it get's into the provided context. Take this into account when definig styles as paddingTop, paddingLeft and so on instead of the shortcut padding. For layout or styles transformation this project provides separate packages.

node.type

Mandatory field specifiying the type of the particular node. The full list of types can be found and imported from @react-pdf/primitives

node.box

Defines bounding box where a particular node is located inside a document

  • left
  • top
  • width
  • height
  • paddingTop
  • paddingLeft
  • paddingBottom
  • paddingRight
  • marginTop
  • marginLeft
  • marginBottom
  • marginRight
  • borderTopWidth
  • borderLeftWidth
  • borderBottomWidth
  • borderRightWidth

node.style

Defines how the node looks like. There are some types of nodes that expect special style values, but generally all support:

  • color
  • opacity
  • overflow
  • backgroundColor
  • borderTopLeftRadius
  • borderTopRightRadius
  • borderBottomLeftRadius
  • borderBottomRightRadius
  • borderTopColor
  • borderLeftColor
  • borderBottomColor
  • borderRightColor
  • others...

node.props

Specific node params needed to render correctly ot behave like certain way. Specially needed for SVG nodes

PDF example

import fs from 'fs';
import render from '@react-pdf/render';
import pdfkit from '@react-pdf/pdfkit';

const PDFDocument = pdfkit.default;

const ctx = new PDFDocument({ autoFirstPage: false });

const doc = {}; // See above

render.default(ctx, doc);

const stream = fs.createWriteStream('./test.pdf');

ctx.pipe(stream);

License

MIT