mirror of
https://github.com/frappe/books.git
synced 2024-11-14 01:14:03 +00:00
31 lines
733 B
JavaScript
31 lines
733 B
JavaScript
|
async function getPDF(doctype, name) {
|
||
|
const headers = {
|
||
|
'Accept': 'application/pdf',
|
||
|
'Content-Type': 'application/json'
|
||
|
}
|
||
|
|
||
|
const res = await fetch('/api/method/pdf', {
|
||
|
method: 'POST',
|
||
|
headers,
|
||
|
body: JSON.stringify({ doctype, name })
|
||
|
});
|
||
|
|
||
|
const blob = await res.blob();
|
||
|
showFile(blob);
|
||
|
}
|
||
|
|
||
|
|
||
|
function showFile(blob, filename='file.pdf') {
|
||
|
const newBlob = new Blob([blob], { type: "application/pdf" })
|
||
|
const data = window.URL.createObjectURL(newBlob);
|
||
|
const link = document.createElement('a');
|
||
|
link.href = data;
|
||
|
link.download = filename;
|
||
|
link.click();
|
||
|
setTimeout(() => window.URL.revokeObjectURL(data), 100);
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
getPDF
|
||
|
}
|