Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active September 22, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vielhuber/90736946a7bbeefe7aad to your computer and use it in GitHub Desktop.
Save vielhuber/90736946a7bbeefe7aad to your computer and use it in GitHub Desktop.
print a PDF via a simple link #js
<a href="file.pdf" class="print">Print file!</a>
function printPDF(url) {
$('#iFramePdf').remove();
$('body').append('<iframe id="iFramePdf" src="'+url+'" style="display:none;"></iframe>');
var getMyFrame = document.getElementById('iFramePdf');
getMyFrame.focus();
getMyFrame.contentWindow.print();
}
$(document).ready(function() {
$('.print').click(function() {
printPDF($(this).attr('href'));
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment