Last active
September 22, 2017 23:11
-
-
Save vielhuber/90736946a7bbeefe7aad to your computer and use it in GitHub Desktop.
print a PDF via a simple link #js
This file contains 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
<a href="file.pdf" class="print">Print file!</a> |
This file contains 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
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