Reputation: 76557
Currently - I have a View that populates an Iframe with a PDF, and I am attempting to print the contents of the Iframe (the PDF) using Javascript.
Everything seems to be working as it should in nearly every browser with the exception of IE. I have tried several different methods and you can see my current one below:
Print View:
<script type='text/javascript'>
$(document).ready(function (){
//Grabs the Iframe
var ifr = document.getElementById("PDF");
//PDF is completely loaded. (.load() wasn't working properly with PDFs)
ifr.onreadystatechange = function () {
if (ifr.readyState == 'complete'){
ifr.contentWindow.focus();
ifr.contentWindow.print();
}
}
});
</script>
<html>
<body style='margin: 0; overflow: hidden;'>
<iframe src='URL' width="100%" height="100%" id="PDF" name="PDF"></iframe>
</body>
</html>
The above appears to work in IE, as it launches a print dialog box once the PDF has been loaded, however upon selecting a printing option, nothing happens.
The same result happens in Chrome and Firefox (print dialog etc.) however, the PDF is actually printed.
Upvotes: 3
Views: 3181
Reputation: 114367
The PDF plug-in has taken over the iframe so the print functionality has to come from the PDF, not the browser.
Upvotes: 2