I have few values in my react state array that I'm passing through props to the current component. But instead of displaying as they are currently displayed in the code below, I would like to use a PDF template that's in my file system.
So my expected outcome is to be able to draw the given data from the state (text or images) on a copy of the original PDF at a given (x,y) coordinates and be able to email the new PDF or save it to the Local storage devices. Given below is my existing code which only displays the data in a container.
export class FormReview extends Component{
constructor(props) {
super(props);
this.state = {value:0};
}
/*methods used to navigate between multistep forms*/
continue = e => {
e.preventDefault();
this.props.nextStep();
}
back = e => {
e.preventDefault();
this.props.prevStep();
}
render() {
const {values} = this.props;
return(
<MuiThemeProvider>
<React.Fragment>
<AppBar title="Review Submission"/>
<div>
<Grid container spacing={2} style={{padding:50}}>
<Grid item xs={1}/>
<Grid item xs={10}>
<Paper>
<Grid item xs={12} sm container>
<Grid item xs container direction="column">
<Grid item xs style={{textAlign:'left', padding:20}}>
<Container style={{ height:'500', backgroundColor:'#A9A9A9', overflow: 'scroll'}}>
<List>
<ListItem
primaryText='Student Name'
secondaryText={values.stu_name}/>
<ListItem
primaryText='Flight Registration'
secondaryText={values.rego}/>
<ListItem
primaryText='Date'
secondaryText={values.fl_date}/>
<ListItem
primaryText='Hours'
secondaryText={values.fl_clock}/>
<ListItem
primaryText='Completed?'
secondaryText={values.pfk_bool}/>
<ListItem
primaryText='next?'
secondaryText={values.nextLesson_bool}/>
/*formRating contains performance ratings of students depending on the lesson undertaken*/
{values.formRating.map(
item =>
<Grid container>
<Grid item xs={2} style={{marginTop:20, marginRight:0}}>{item.condId} </Grid>
<Grid item xs={6} style={{marginTop:20}}>{item.condition} </Grid>
<Grid item xs={4} style={{marginTop:10}}>{item.rate}</Grid>
</Grid>)}</List>
</Container>
<Grid item xs={12}>
<RaisedButton label="Email & Save" secondary={true} onClick={this.continue} fullWidth='true' style={{marginTop:20, height:60}}/>
<ButtonGroup variant="contained" style={{marginTop:20}} fullWidth >
<Button>Save Only</Button>
<Button>Cancel</Button>
</ButtonGroup>
</Grid>
</Grid >
</Grid>
</Grid>
</Paper>
</Grid>
<Grid item xs={1}/>
</Grid>
</div>
</React.Fragment>
</MuiThemeProvider>
)
}
}
export default FormReview
What's expected is a NEW PDF to be displayed in the container which is based on the template PDF (in local file system) with the data drawn on it at given coordinates. This new documents should be able to be emailed or saved to the local storage as per user preference.
I'm a total beginner to React.
Use pdf-lib.js to modify the content of pdfs in react. You can modify existing pdfs, add new pages, remove pages , draw text & images etc.
Check out this link: https://github.com/Hopding/pdf-lib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With