Skip to content

Instantly share code, notes, and snippets.

@WickyNilliams
Last active November 30, 2018 17:36
Show Gist options
  • Save WickyNilliams/839bba33fe0e55e4041fca62e3251cbb to your computer and use it in GitHub Desktop.
Save WickyNilliams/839bba33fe0e55e4041fca62e3251cbb to your computer and use it in GitHub Desktop.
@react-pdf/renderer without jsx
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"
);
{
"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