I have an iframe which needs point directly to a PDF file (not a page with a PDF):
This seems to be working:
<style type="text/css" media="print">
body *{display:none}
iframe{display:block}
</style>
So then just the pdf is displayed?
You can use directly window print option. use onclick option
onclick="javascript:window.print();"
I have struggled a bit to find a solution that works for both IE and Chrome. This works for me:
$(function() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
var trident = ua.indexOf('Trident/');
var edge = ua.indexOf('Edge/');
var url = '/url/to/file.pdf';
var pdf ='';
var style = 'position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden;';
if(msie > 0 || trident > 0 || edge > 0){
pdf = '<object data="' + url + '" name="print_frame" id="print_frame" style="' + style + '" type="application/pdf">';
}
else{
pdf ='<iframe src="' + url + '" name="print_frame" id="print_frame" style="' + style + '"></iframe>';
}
$(document.body).append(pdf);
setTimeout(function(){
window.frames["print_frame"].focus();
window.frames["print_frame"].print();
},2000);
});
...cheers.
As suggested in this answer for a similar question, you could do this:
window.frames.pdfFrame.print();
This should solve your problem.
Option 1:
I haven't tested this but I found another answer here: https://stackoverflow.com/a/4096547/2528978
Assuming that you could use the following:
<style type="text/css" media="print">
body *{display:none}
iframe{display:block}
</style>
So then just the pdf is displayed?
Option 2:
Make a hyperlink to the pdf file that says "Print me"
<a href='Path/To/PDF'>Print Me</a>
Hope this helps...
-Andrew