react2pdf
TypeScript icon, indicating that this package has built-in type declarations

1.2.6 • Public • Published

npm version npm version

⚛️ React2Pdf 📄

React2Pdf is a library that allows you to generate pdf from React components in NodeJS.

Install

Install with npm:

$ npm i --save react2pdf

Usage

Import :

import React2Pdf from "react2pdf";

const options = {}
const reactToPdf = new React2Pdf(options);

For options check this section

Generate a pdf and save it to a file :

    // Generate pdf
    const reactToPdf = new React2Pdf();
    reactToPdf.addPage(<h1>Hello world</h1>)
    const pdfStream = await reactToPdf.render("./examples/pdfExample", "a4");

Generate a pdf with express :

import Router from "express";
import React from "react";
import React2Pdf from "react2pdf";

const router = Router();

router.get("/pdf", async (req, res) => {
    const reactToPdf = new React2Pdf();
	reactToPdf.addPage(
		<h1 style={{ height: "200px", background: "blue" }}>
			Hello world !
		</h1>
	);
	const pdfStream = await reactToPdf.renderToStream("a4");
	res.contentType("application/pdf");
	pdfStream.pipe(res);
	stream.on("end", () => console.log("Done streaming, response sent."));
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.66latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.66
1.2.50
1.2.40
1.2.30
1.2.20
1.2.10
1.2.01
1.1.00
1.0.00
0.6.00
0.5.10
0.5.00
0.4.00
0.3.00
0.2.00
0.1.00

Package Sidebar

Install

npm i react2pdf

Weekly Downloads

7

Version

1.2.6

License

MIT

Unpacked Size

4.02 MB

Total Files

11

Last publish

Collaborators

  • wawa27
  • matryxxx02