Last active
November 30, 2018 17:36
-
-
Save WickyNilliams/839bba33fe0e55e4041fca62e3251cbb to your computer and use it in GitHub Desktop.
@react-pdf/renderer without jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const React = require("react"); | |
const { default: ReactPDF } = require("@react-pdf/renderer"); | |
const { | |
Page, | |
Text, | |
View, | |
Document, | |
StyleSheet | |
} = require("@react-pdf/renderer"); | |
// Create styles | |
const styles = StyleSheet.create({ | |
page: { | |
flexDirection: "row", | |
backgroundColor: "#E4E4E4" | |
}, | |
section: { | |
margin: 10, | |
padding: 10, | |
flexGrow: 1 | |
} | |
}); | |
const MyDocument = () => | |
React.createElement( | |
Document, | |
null, | |
React.createElement( | |
Page, | |
{ size: "A4", style: styles.page }, | |
React.createElement( | |
View, | |
{ style: styles.section }, | |
React.createElement(Text, null, "Section #1") | |
), | |
React.createElement( | |
View, | |
{ style: styles.section }, | |
React.createElement(Text, null, "Section #2") | |
) | |
) | |
); | |
ReactPDF.render( | |
React.createElement(MyDocument, null), | |
__dirname + "/example.pdf" | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "test-react-pdf", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "node ./index.js" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"@react-pdf/renderer": "^1.0.0-alpha.25", | |
"react": "^16.6.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment