2011-03-31 150 views
3

我希望在用户点击特定链接时在客户端打印PDF。但是,PDF不应该打开并打印。它可能不是静音打印,要求打印机使用的操作系统弹出窗口可以来。我的PDF阅读器应为Adobe Reader。 我发现了很多链接,试图发现它们依赖于正在使用的浏览器。我试过这段代码能够在Chrome中成功打印,但我认为chrome有自己的PDF渲染器。在客户端浏览器打印PDF而不打开PDF

<script>function iprint(ptarget){ 
     ptarget.focus(); 
     ptarget.print(); 
     } 
</script><body> 
<iframe name="theiframe" id="theiframe" width="500" height="200" src="http://192.168.108.105:8081/PDfTest/Excel.pdf" style="display:none"> 
</iframe> 
    <input type="button" value="print iframe" onclick="iprint(theiframe);" /> 
</body> 

也试过这个代码块,但这打开PDF,然后打印:

<html> 
<script language="javascript"> 
timerID = setTimeout("exPDF.print();", 1000); 
</script> 
<body> 
<object id="exPDF" type="application/pdf" data="111.pdf" width="100%" height="500"/> 
</body> 
</html> 

希望得到任何帮助。

回答

0

你可以打开PDF,但以一种对用户不可见的方式?如果是这样,您可以使用类似<object style="display: none;" ...的东西来设置对象标签的可见性。通过这种方式,PDF有机会打开(用户不知道),然后看似神奇地打印PDF。

希望这会有所帮助!

相关问题