Skip to content

lang-ai/react-pdfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project is no longer being maintained


Generating PDFs with React

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.

Example

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:

PDF Preview

Development

This project was bootstrapped with Create React App. See the development guide here.

Creating the PDF

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

LangAI

Built with ❤️ by Lang.ai