Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Created June 21, 2019 11:42
Show Gist options
  • Select an option

  • Save arn-ob/533b30eb9e1a6e2c55a7369fbf0c24f7 to your computer and use it in GitHub Desktop.

Select an option

Save arn-ob/533b30eb9e1a6e2c55a7369fbf0c24f7 to your computer and use it in GitHub Desktop.
Generate PDF with React
import React, { PureComponent } from 'react';
import { Button, } from 'antd';
import jsPDF from 'jspdf'
export default class pdfGenerate extends PureComponent {
constructor(props){
super(props)
this.state ={}
}
// JSpdf Generator For generating the PDF
jsPdfGenerator = () => {
// Example From https://parall.ax/products/jspdf
var doc = new jsPDF('p', 'pt');
doc.text(20, 20, 'This is the default font.')
doc.setFont('courier')
doc.setFontType('normal')
doc.text(20, 30, 'This is courier normal.')
doc.setFont('times')
doc.setFontType('italic')
doc.text(20, 40, 'This is times italic.')
doc.setFont('helvetica')
doc.setFontType('bold')
doc.text(20, 50, 'This is helvetica bold.')
doc.setFont('courier')
doc.setFontType('bolditalic')
doc.text(20, 60, 'This is courier bolditalic.')
// Save the Data
doc.save('Generated'.pdf')
}
render(){
return(
<Button onClick={this.jsPdfGenerator} type="primary"> Generate PDF </Button>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment