diff options
Diffstat (limited to 'src/shared')
| -rw-r--r-- | src/shared/download-pdf.ts | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/shared/download-pdf.ts b/src/shared/download-pdf.ts index e741942..bd8f815 100644 --- a/src/shared/download-pdf.ts +++ b/src/shared/download-pdf.ts @@ -1,23 +1,17 @@ -const autoPrintCode = ` -<script> - document.addEventListener("DOMContentLoaded", () => { - Promise.all(Array.from(document.images) - .filter(img => !img.complete) - .map(img => new Promise(resolve => { - img.onload = img.onerror = resolve; - }))).then(() => { - window.print(); - window.close(); - }); - }); -</script> -`; - export const downloadPDF = (content: string) => { const tab = window.open("about:blank", "_blank"); if (tab) { - tab.document.write(content + autoPrintCode); + tab.document.write(content); tab.document.close(); + tab.focus(); + Promise.all(Array.from(tab.document.images) + .filter(img => !img.complete) + .map(img => new Promise(resolve => { + img.onload = img.onerror = resolve; + }))).then(() => { + tab.print(); + tab.close(); + }); } }; |
