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."));
});

Readme

Keywords

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