Created
June 24, 2019 11:03
-
-
Save Karnak19/110d04a7852549c23200d900e69cc0d0 to your computer and use it in GitHub Desktop.
React-PDF props
This file contains hidden or 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
| import React from "react"; | |
| import { PDFViewer } from "@react-pdf/renderer"; | |
| import "./App.css"; | |
| import MyDocument from "./MyDocument"; | |
| const datas = { | |
| name: "Basile", | |
| lastName: "Vernouillet", | |
| job: "React Node Trainer", | |
| company: "Wild Code School" | |
| }; | |
| function App() { | |
| return ( | |
| <div className="App"> | |
| <PDFViewer> | |
| <MyDocument {...datas} /> | |
| </PDFViewer> | |
| </div> | |
| ); | |
| } | |
| export default App; |
This file contains hidden or 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
| import React from "react"; | |
| import { Page, Text, View, Document, 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 = ({ name, lastName, job, company }) => ( | |
| <Document> | |
| <Page size="A4" style={styles.page}> | |
| <View style={styles.section}> | |
| <Text>{name}</Text> | |
| <Text>{lastName}</Text> | |
| </View> | |
| <View style={styles.section}> | |
| <Text>{job}</Text> | |
| <Text>{company}</Text> | |
| </View> | |
| </Page> | |
| </Document> | |
| ); | |
| export default MyDocument; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment