Firefox versions 4 and up and also Safari, with Adobe Acrobat Reader, are conspiring not to print the PDF content of an iframe's contentwindow.
I have a HTML page with Javascript. There is an iFrame and an input type button on this page. The iFrame src tag points to a PDF.
I am using FireFox 7 here, so I get access to the window onafterprint event. (There's talk that FF6 has it too; and FF8 beta has it.) Also I am on Windows 7, 64 bit. The version of the Reader is "X", 10.1.1; the same happens with 8.3 and 9.4.
<html>
<body>
<input id="btnPrint1" type="button" onclick="printPdfFirefox()" value="print" />
<iframe id="ifrmPDF" src="twopage.pdf"></iframe>
<br><hr><br>
<input id="btnPrint2" type="button" onclick="printTextFirefox()" value="print" />
<iframe id="ifrmText" src="text.txt"></iframe>
<script>
function printPdfFirefox()
{
iframe = document.getElementById("ifrmPDF");
iframe.contentWindow.onafterprint = function (evt)
{
alert('i just printed something');
};
iframe.focus();
iframe.contentWindow.print();
}
function printTextFirefox()
{
iframe = document.getElementById("ifrmText");
iframe.contentWindow.onafterprint = function (evt)
{
alert('i just printed something');
};
iframe.focus();
iframe.contentWindow.print();
}
</script>
</body>
</html>
Firefox successfully loads the PDF into the iFrame. The input button then calls the print method of the iFrame, and (in FF7+) the (content)window fires the event.
What doesn't happen is printing. Reader X is refusing such calls from FF4+ (I verified earlier versions with a VM). Safari will print a blank page. I can verify that Reader does let FF 3.6 print. I can also verify that FF4+ and Safari have no problem with printing a text file.
[Chrome prints; but Chrome seems to be using an independent process and not your Reader.]
And I can print this PDF from other parts of the system; as long as I stick to serving it up as a full PDF and don't embed it in an iFrame.
I monkeyed with the security settings in Adobe Reader for a bit, but this was voodoo and didn't help. Is there some way of telling what Reader's thought process was, when it didn't print the document but also didn't raise an exception? I don't know how to get access to Reader X's properties, from external javascript. Nor the document's properties.
I would really like an answer to why this is going on. Thanks!