Created
December 19, 2018 20:01
-
-
Save apexdodge/659fe63a3c8ccbbeec56cbbbd24d328f to your computer and use it in GitHub Desktop.
HTML to PDF with ReactJS
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
import React, { Component } from 'react'; | |
class HtmlToPdf extends Component { | |
convertHtmlToPdf(e) { | |
fetch('https://v2018.api2pdf.com/chrome/html', { | |
method: 'post', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': 'YOUR-API-KEY' //Get your API key from https://portal.api2pdf.com | |
}, | |
body: JSON.stringify({html: '<p>hello world from reactjs</p>', inlinePdf: true, fileName: 'test.pdf' }) | |
}).then(res=>res.json()) | |
.then(res => console.log(res.pdf)); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<button onClick={this.convertHtmlToPdf.bind(this)}>Generate Pdf</button> | |
</div> | |
); | |
} | |
} | |
export default HtmlToPdf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the link (https://v2018.api2pdf.com/chrome/html)
is not working