Skip to content

Instantly share code, notes, and snippets.

@apexdodge
Created December 19, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apexdodge/659fe63a3c8ccbbeec56cbbbd24d328f to your computer and use it in GitHub Desktop.
Save apexdodge/659fe63a3c8ccbbeec56cbbbd24d328f to your computer and use it in GitHub Desktop.
HTML to PDF with ReactJS
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;
@aanbari1337
Copy link

the link (https://v2018.api2pdf.com/chrome/html)
is not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment