UNPKG

5.56 kBMarkdownView Raw
1<p align="center">
2 <img src="https://user-images.githubusercontent.com/5600341/27505816-c8bc37aa-587f-11e7-9a86-08a2d081a8b9.png" height="280px">
3 <p align="center">React renderer for creating PDF files on the browser and server<p>
4 <p align="center">
5 <a href="https://www.npmjs.com/package/@react-pdf/renderer">
6 <img src="https://img.shields.io/npm/v/@react-pdf/renderer.svg" />
7 </a>
8 <a href="https://travis-ci.org/diegomura/react-pdf">
9 <img src="https://img.shields.io/travis/diegomura/react-pdf.svg" />
10 </a>
11 <a href="https://github.com/diegomura/react-pdf/blob/master/LICENSE">
12 <img src="https://img.shields.io/github/license/diegomura/react-pdf.svg" />
13 </a>
14 <a href="https://spectrum.chat/react-pdf">
15 <img src="https://withspectrum.github.io/badge/badge.svg" />
16 </a>
17 <a href="https://github.com/prettier/prettier">
18 <img src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg" />
19 </a>
20 <a href="https://app.fossa.com/projects/git%2Bgithub.com%2Ftaylorudell%2Freact-pdf?ref=badge_shield" alt="FOSSA Status"><img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftaylorudell%2Freact-pdf.svg?type=shield"/></a>
21 </p>
22</p>
23
24## How to install
25```sh
26yarn add @react-pdf/renderer
27```
28
29## How it works
30
31```jsx
32import React from 'react';
33import { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';
34
35// Create styles
36const styles = StyleSheet.create({
37 page: {
38 flexDirection: 'row',
39 backgroundColor: '#E4E4E4'
40 },
41 section: {
42 margin: 10,
43 padding: 10,
44 flexGrow: 1
45 }
46});
47
48// Create Document Component
49const MyDocument = () => (
50 <Document>
51 <Page size="A4" style={styles.page}>
52 <View style={styles.section}>
53 <Text>Section #1</Text>
54 </View>
55 <View style={styles.section}>
56 <Text>Section #2</Text>
57 </View>
58 </Page>
59 </Document>
60);
61```
62
63### `Web.` Render in DOM
64```jsx
65import React from 'react';
66import ReactDOM from 'react-dom';
67import { PDFViewer } from '@react-pdf/renderer';
68
69const App = () => (
70 <PDFViewer>
71 <MyDocument />
72 </PDFViewer>
73);
74
75ReactDOM.render(<App />, document.getElementById('root'));
76```
77
78### `Node.` Save in a file
79```jsx
80import React from 'react';
81import ReactPDF from '@react-pdf/renderer';
82
83ReactPDF.render(<MyDocument />, `${__dirname}/example.pdf`);
84```
85
86## Examples
87For each example, try opening `output.pdf` to see the result.
88
89<table>
90 <tbody>
91 <tr>
92 <td align="center" valign="top">
93 <img width="150" height="150" src="https://github.com/diegomura/react-pdf/blob/master/examples/text/thumb.png">
94 <br>
95 <a href="https://github.com/diegomura/react-pdf/tree/master/examples/text/">Text</a>
96 </td>
97 <td align="center" valign="top">
98 <img width="150" height="150" src="https://github.com/diegomura/react-pdf/blob/master/examples/images/thumb.png">
99 <br>
100 <a href="https://github.com/diegomura/react-pdf/tree/master/examples/images/">Images</a>
101 </td>
102 <td align="center" valign="top">
103 <img width="150" height="150" src="https://github.com/diegomura/react-pdf/blob/master/examples/resume/thumb.png">
104 <br>
105 <a href="https://github.com/diegomura/react-pdf/tree/master/examples/resume/">Resume</a>
106 </td>
107 <td align="center" valign="top">
108 <img width="150" height="150" src="https://github.com/diegomura/react-pdf/blob/master/examples/fractals/thumb.png">
109 <br>
110 <a href="https://github.com/diegomura/react-pdf/tree/master/examples/fractals/">Fractals</a>
111 </td>
112 </tr>
113 </tbody>
114</table>
115<table>
116 <tbody>
117 <tr>
118 <td align="center" valign="top">
119 <img width="150" height="150" src="https://github.com/diegomura/react-pdf/blob/master/examples/knobs/thumb.png">
120 <br>
121 <a href="https://github.com/diegomura/react-pdf/tree/master/examples/knobs/">Knobs</a>
122 </td>
123 <td align="center" valign="top">
124 <img width="150" height="150" src="https://github.com/diegomura/react-pdf/blob/master/examples/pageWrap/thumb.png">
125 <br>
126 <a href="https://github.com/diegomura/react-pdf/tree/master/examples/pageWrap/">Page wrap</a>
127 </td>
128 </tr>
129 </tbody>
130</table>
131
132To run the examples, first clone the project and install the dependencies:
133```sh
134git clone https://github.com/diegomura/react-pdf.git
135cd react-pdf
136yarn install
137```
138Then, run `yarn example -- <example-name>`
139```sh
140yarn example -- fractals
141```
142
143## Contributors
144
145This project exists thanks to all the people who contribute. [[Contribute]](CONTRIBUTING.md).
146<a href="https://github.com/diegomura/react-pdf/graphs/contributors"><img src="https://opencollective.com/react-pdf/contributors.svg?width=890" /></a>
147
148## Sponsors
149
150Thank you to all our sponsors! [[Become a sponsors](https://opencollective.com/react-pdf#sponsors)]
151
152<a href="https://opencollective.com/react-pdf#sponsors" target="_blank"><img src="https://opencollective.com/react-pdf/sponsors.svg?width=890"></a>
153
154## Backers
155
156Thank you to all our backers! [[Become a backer](https://opencollective.com/react-pdf#backer)]
157
158<a href="https://opencollective.com/react-pdf#backers" target="_blank"><img src="https://opencollective.com/react-pdf/backers.svg?width=890"></a>
159
160## License
161
162MIT © [Diego Muracciole](http://github.com/diegomura)
163
164[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ftaylorudell%2Freact-pdf.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Ftaylorudell%2Freact-pdf?ref=badge_large)
165
166---
167![](https://img.shields.io/npm/dt/@react-pdf/renderer.svg?style=flat)