Skip to content

Instantly share code, notes, and snippets.

@vipulyadav150
Created February 27, 2023 11:23
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 vipulyadav150/1a574e10ddc8d2e0d79699b8a7c91d9d to your computer and use it in GitHub Desktop.
Save vipulyadav150/1a574e10ddc8d2e0d79699b8a7c91d9d to your computer and use it in GitHub Desktop.
function saveAspdf() {
var pdf = new jsPDF('p', 'pt', 'a4');
$("#button-pdf").attr('hidden', 'true')
pdf.addHTML($("#mainContainer"), 0, -20, { allowTaint: true, useCORS: true, pagesplit: false }, function () {
pdf.save('{{downloaded_file_name}}.pdf');
downloadFile($(".screening-report-url").attr("href"));
$("#button-pdf").removeAttr('hidden', 'true')
});
}
function downloadFile(url) {
fetch(url, { method: 'get', mode: 'no-cors', referrerPolicy: 'no-referrer' })
.then(res => res.blob())
.then(res => {
const aElement = document.createElement('a');
aElement.setAttribute('download', "screening_report.pdf");
const href = URL.createObjectURL(res);
aElement.href = href;
aElement.setAttribute('href', href);
aElement.click();
URL.revokeObjectURL(href);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment