1.2.6 • Published 12 months ago

react2pdf v1.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

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

12 months ago

1.2.5

12 months ago

1.2.4

12 months ago

1.2.3

12 months ago

1.2.2

12 months ago

1.2.1

12 months ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.6.0

2 years ago

0.5.0

3 years ago

0.5.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago