I have a web page (SSL) that contains a barely visible iframe whose source is a PDF streamed from a Java servlet. The purpose of the barely visible iframe is to render a PDF which opens a print dialog box right away when the page is loaded.
This process is working in a sporadic manner. More often than not, when the page is loaded, the PDF print dialog box comes up correctly. Occasionally, though, the PDF print dialog box is never rendered when the page loads. I know it's not an issue in the Java servlet as I can verify from the logs that the PDF is streamed correctly to the calling page. I need to find a way to make it 99.9999.......% reliable if at all possible that the PDF print dialog ALWAYS opens when the page is loaded. So, I'm looking for any tips on how to ensure that this will happen.
This needs to work for Internet Explorer (version 8 in particular).
This is the JavaScript that opens the page that contains the PDF iframe:
function openPrintCheckWindow(){
pc=window.open("/print_check.jsp", "pc", "toolbar=no,scrollbars=no,resizable=no");
pc.resizeTo(1000,700);
pc.moveTo(80,80);
}
Here's the source for the page that contains the PDF iframe:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
<style>
#createpdf {
position:absolute;
top:0;
right:0;
}
.micr {
font-family: "MICR Encoding", sans-serif;
font-size: 0.2in;
}
</style>
<script type="text/javascript">
function doAlert(msg){
if(msg.length>0){
alert(msg);
}
}
//doesn't block the load event
function createIframe(){
var i = document.createElement("iframe");
i.src = "/PrintCheckServlet";
i.width = "2px";
i.height = "2px";
document.getElementById("createpdf").appendChild(i);
};
// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", createIframe, false);
else if (window.attachEvent)
window.attachEvent("onload", createIframe);
else
window.onload = createIframe;
</script>
</HEAD>
<BODY BGCOLOR="#DFD9D0" TEXT="#000066" onLoad="doAlert('')">
<FORM METHOD="POST" TARGET="main_window" ACTION="ControllerServlet">
<P ALIGN="LEFT">
<INPUT TYPE="BUTTON" NAME="CLOSE" VALUE="Close"
onClick="this.form.submit();window.close();window.opener.focus();window=null;">
<br />
<H3 id="print_message">A print dialog box will show momentarily</H3>
</P>
<div id="createpdf"></div>
</FORM>
</BODY>
</HTML>