Skip to content

Instantly share code, notes, and snippets.

@miguel-leon
Created December 8, 2016 15:07
Show Gist options
  • Save miguel-leon/d0a24f4c638211cb7c90314708355a50 to your computer and use it in GitHub Desktop.
Save miguel-leon/d0a24f4c638211cb7c90314708355a50 to your computer and use it in GitHub Desktop.
Send a pdf embedded to print
function printPdf(url) {
var frame = document.createElement('iframe');
frame.setAttribute('style', 'display:none;');
frame.setAttribute('src', url);
var element = document.body.appendChild(frame);
element.addEventListener('load', function () {
element.contentWindow.print();
document.addEventListener('focus', focusEventListener, true);
});
function focusEventListener() {
document.body.removeChild(element);
document.removeEventListener('focus', focusEventListener, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment