Skip to content

Instantly share code, notes, and snippets.

@dralletje
Last active February 10, 2018 14:07
Show Gist options
  • Save dralletje/e0e8f8dadb18d970c1c76a4ec9fe3fbf to your computer and use it in GitHub Desktop.
Save dralletje/e0e8f8dadb18d970c1c76a4ec9fe3fbf to your computer and use it in GitHub Desktop.
//let REPORT_TO_PDF_URL = 'http://localhost:5000'; // For testing locally
let REPORT_TO_PDF_URL = 'https://report-to-pdf.herokuapp.com';
let download_pdf_from_html = async ({ html_body, pdf_options, filename }) => {
let resp = await fetch(`${REPORT_TO_PDF_URL}/request_pdf_path`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ html_body, pdf_options, filename }),
});
let { pdf_path } = await resp.json();
window.location.href = `${REPORT_TO_PDF_URL}${pdf_path}`;
}
/*
download_pdf_from_html({
html_body: '<h1>Hey!</h1>',
pdf_options: { landscape: true },
filename: 'my-report.pdf',
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment