Skip to content
πŸ“„ Create PDF files using React
JavaScript
Branch: master
Clone or download

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml May 24, 2019
examples Implementing Go-to functionality (#746) Nov 6, 2019
src Allow image src to be function that returns a promise resolving in a … Nov 22, 2019
tests Implementing Go-to functionality (#746) Nov 6, 2019
.babelrc Upgrade dependencies (#509) Feb 26, 2019
.eslintignore Fix core and dom packages (#170) Jan 18, 2018
.eslintrc Fetch headers (#485) Feb 17, 2019
.gitattributes Create .gitattributes May 6, 2017
.gitignore Implementing Go-to functionality (#746) Nov 6, 2019
.prettierignore Refactor dom bindings project (#176) Jan 19, 2018
.prettierrc Add precompiled yoga (#142) Sep 12, 2017
.travis.yml schedulePassiveEffects is not a function (#673) Aug 2, 2019
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Jun 19, 2017
CONTRIBUTING.md Fix the link to point to an existing page on github (#154) Oct 25, 2017
LICENSE Fix license recognition (#49) May 20, 2017
README.md Add license scan report and status (#653) Jun 28, 2019
index.d.ts Adds Orphan & widow protection props to index.d.ts (#712) Oct 4, 2019
jest.config.js Fetch headers (#485) Feb 17, 2019
package.json v1.6.8 Nov 11, 2019
rollup.config.js Update textkit (#554) Apr 9, 2019
yarn.lock Implementing Go-to functionality (#746) Nov 6, 2019

README.md

React renderer for creating PDF files on the browser and server

How to install

yarn add @react-pdf/renderer

How it works

import React from 'react';
import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';

// Create styles
const styles = StyleSheet.create({
  page: {
    flexDirection: 'row',
    backgroundColor: '#E4E4E4'
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1
  }
});

// Create Document Component
const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </Page>
  </Document>
);

Web. Render in DOM

import React from 'react';
import ReactDOM from 'react-dom';
import { PDFViewer } from '@react-pdf/renderer';

const App = () => (
  <PDFViewer>
    <MyDocument />
  </PDFViewer>
);

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

Node. Save in a file

import React from 'react';
import ReactPDF from '@react-pdf/renderer';

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

Examples

For each example, try opening output.pdf to see the result.


Text

Images

Resume

Fractals

Knobs

Page wrap

To run the examples, first clone the project and install the dependencies:

git clone https://github.com/diegomura/react-pdf.git
cd react-pdf
yarn install

Then, run yarn example -- <example-name>

yarn example -- fractals

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Sponsors

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

Backers

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

License

MIT Β© Diego Muracciole

FOSSA Status


You can’t perform that action at this time.