[英]Reliably render a PDF which opens a print dialog when loaded on a web page
I have a web page (SSL) that contains a barely visible iframe whose source is a PDF streamed from a Java servlet. 我有一个网页(SSL),其中包含几乎看不见的iframe,其来源是从Java servlet流式传输的PDF。 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.
几乎看不见的iframe的目的是渲染PDF,该PDF在加载页面后立即打开打印对话框。
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.
通常,在加载页面时,会正确显示“ PDF打印”对话框。 Occasionally, though, the PDF print dialog box is never rendered when the page loads.
但是,有时在页面加载时永远不会渲染PDF打印对话框。 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.
我知道这不是Java servlet中的问题,因为我可以从日志中验证PDF是否正确传输到调用页面。 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.
我需要找到一种方法来确保99.9999 .......%的可靠性,如果可能的话,在加载页面时始终打开PDF打印对话框。 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). 这需要适用于Internet Explorer(尤其是版本8)。
This is the JavaScript that opens the page that contains the PDF iframe: 这是JavaScript,可打开包含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: 这是包含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>
Are you OK with assuming that whoever is viewing your file is using Acrobat Reader or some other "javascript-enabled" PDF reader? 您是否可以确定正在查看文件的人员正在使用Acrobat Reader或其他“启用JavaScript的” PDF阅读器?
If that is the case, you could then modify your file and generate a PDF that automatically prints instead. 在这种情况下,您可以修改文件并生成自动打印的PDF。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.