diegomura/react-pdf

Create PDF files using React

README

React renderer for creating PDF files on the browser and server


Lost?


This package is used to _create_ PDFs using React. If you wish to _display_ existing PDFs, you may be looking for react-pdf.

How to install

  1. ```sh
  2. yarn add @react-pdf/renderer
  3. ```

How it works


  1. ``` js
  2. import React from 'react';
  3. import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';

  4. // Create styles
  5. const styles = StyleSheet.create({
  6.   page: {
  7.     flexDirection: 'row',
  8.     backgroundColor: '#E4E4E4'
  9.   },
  10.   section: {
  11.     margin: 10,
  12.     padding: 10,
  13.     flexGrow: 1
  14.   }
  15. });

  16. // Create Document Component
  17. const MyDocument = () => (
  18.   <Document>
  19.     <Page size="A4" style={styles.page}>
  20.       <View style={styles.section}>
  21.         <Text>Section #1</Text>
  22.       </View>
  23.       <View style={styles.section}>
  24.         <Text>Section #2</Text>
  25.       </View>
  26.     </Page>
  27.   </Document>
  28. );
  29. ```

Web. Render in DOM

  1. ``` js
  2. import React from 'react';
  3. import ReactDOM from 'react-dom';
  4. import { PDFViewer } from '@react-pdf/renderer';

  5. const App = () => (
  6.   <PDFViewer>
  7.     <MyDocument />
  8.   </PDFViewer>
  9. );

  10. ReactDOM.render(<App />, document.getElementById('root'));
  11. ```

Node. Save in a file

  1. ``` js
  2. import React from 'react';
  3. import ReactPDF from '@react-pdf/renderer';

  4. ReactPDF.render(<MyDocument />, `${__dirname}/example.pdf`);
  5. ```

Contributors


This project exists thanks to all the people who contribute. Looking to contribute? Please check our [[contribute]](https://github.com/diegomura/react-pdf/blob/master/.github/CONTRIBUTING.md) document for more details about how to setup a development environment and submitting code.


Sponsors


Thank you to all our sponsors! [Become a sponsors]


Backers


Thank you to all our backers! [Become a backer]


License


FOSSA Status

undefined