Skip to content

Instantly share code, notes, and snippets.

@leoberdu
Created February 26, 2020 19:28
Show Gist options
  • Save leoberdu/4888896becd108dd6ec2acfd416d1ecb to your computer and use it in GitHub Desktop.
Save leoberdu/4888896becd108dd6ec2acfd416d1ecb to your computer and use it in GitHub Desktop.
<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>
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 = (e) => {
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