1/*
2Make sure to install the library
3with yarn
4yarn add @react-pdf/renderer
5with npm
6npm install @react-pdf/renderer --save
7*/
8
9import React from 'react';
10import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';
11
12// Create styles
13const styles = StyleSheet.create({
14 page: {
15 flexDirection: 'row',
16 backgroundColor: '#E4E4E4'
17 },
18 section: {
19 margin: 10,
20 padding: 10,
21 flexGrow: 1
22 }
23});
24
25// Create Document Component
26const MyDocument = () => (
27 <Document>
28 <Page size="A4" style={styles.page}>
29 <View style={styles.section}>
30 <Text>Section #1</Text>
31 </View>
32 <View style={styles.section}>
33 <Text>Section #2</Text>
34 </View>
35 </Page>
36 </Document>
37);
1var doc = new jsPDF();
2doc.fromHTML(ReactDOMServer.renderToStaticMarkup(this.render()));
3doc.save("myDocument.pdf");