This is an example project you can use to generate PDFs with React. Start by checking the related talk slides here.
If you want to generate emails using React, check the react-emails repo.
To provide an example as starting point, this project generates a demo invoice.
To generate the example:
$ npm install
$ npm run build
$ node example/invoice.js
The result PDF will be saved in the /build/
directory. Here is how it looks like:
This project was bootstrapped with Create React App. See the development guide here.
To create the PDF, simply import the function (you may want to use it as a module) and call it with the data. It returns a promise that resolves when the generated PDF path.
// In case you use it as a module
// const createPDF = require('react-pdfs-example');
const createPDF = require('../server/createPDF');
const data = {
date: new Date().toISOString(),
number: 32149,
recipient: {
displayName: 'John White',
addressLine: 'CEO at Carddesign.con\nLondon, United Kingdom',
},
// more data...
};
createPDF(data)
.then((path) => {
// PDF has been generated with the config from the function
// generatePDF() inside server/createPDF.js.
// Returns the generated PDF path.
});
Built with ❤️ by Lang.ai