Last active
February 26, 2020 19:47
-
-
Save leoberdu/9c99a7424d99f156687ad1cf11754b91 to your computer and use it in GitHub Desktop.
Automatic pop-up dialog box.
This file contains hidden or 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
<html> | |
<head> | |
<style> | |
html, body, iframe { | |
margin: 0; | |
padding: 0; | |
border: 0; | |
font-size: 100%; | |
font: inherit; | |
vertical-align: baseline; | |
} | |
html { | |
width: 100%; | |
height: 100%; | |
} | |
body { | |
line-height: 1; | |
width: inherit; | |
height: inherit; | |
} | |
</style> | |
</head> | |
<body> | |
<iframe src="" width="100%" height="100%"></iframe> | |
<script> | |
/** | |
* Load dynamic PDF files by QueryString 'print' param and open the print dialog box automatically. | |
* e.g., http://localhost:8000/?print=file.pdf | |
*/ | |
let iframe = document.getElementsByTagName('iframe')[0], | |
iframeWindow = iframe.contentWindow || iframe; | |
async function loadPDF() { | |
return await new Promise((resolve) => { | |
iframe.src = new URLSearchParams(window.location.search).get('print'); | |
iframe.onload = () => resolve(); | |
}); | |
} | |
loadPDF().then(() => { | |
iframe.focus(); | |
iframeWindow.print(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment