Created
February 27, 2023 11:23
-
-
Save vipulyadav150/1a574e10ddc8d2e0d79699b8a7c91d9d to your computer and use it in GitHub Desktop.
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
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