在ClientSide浏览器中打印PDF而不打开PDF [英] Print PDF at ClientSide Browser without Opening PDF
问题描述
我希望在用户点击特定链接时在客户端打印PDF。但是,PDF不应该打开,打印应该被触发。它可能不是静默打印,一个操作系统弹出窗口要求打印机使用可以来。我的PDF阅读器应该是Adobe Reader。
我发现了很多链接尝试,但发现他们依赖于正在使用的浏览器。我尝试这个代码片成功打印在Chrome,但我认为chrome有自己的PDF渲染器。
< script> function iprint (ptarget){
ptarget.focus();
ptarget.print();
}
< / script>< body>
< iframe name =theiframeid =theiframewidth =500height =200src =http://192.168.108.105:8081/PDfTest/Excel.pdfstyle =display :none>
< / iframe>
< input type =buttonvalue =print iframeonclick =iprint(theiframe); />
< / body>
也尝试过这段代码,但打开PDF,然后输出:
< html>
< script language =javascript>
timerID = setTimeout(exPDF.print();,1000);
< / script>
< body>
< object id =exPDFtype =application / pdfdata =111.pdfwidth =100%height =500/>
< / body>
< / html>
解决方案您打开PDF是否可以,但用户不可见?如果是这样,您可以使用< object style =display:none; ...
。这种方式PDF有机会打开(用户不知道),然后似乎神奇地打印pdf。
希望这有助于!
I wish to print a PDF at client side when a user clicks a particular link. However, the PDF should not open and print should be fired. It may not be silent printing, a OS popup asking the printer to use can come. My PDF Reader shall be Adobe Reader.
I found a lot of links to try to however found they are dependent on Browser being used. I tried this code piece to successfully print in Chrome but i think chrome has its own PDF Renderer.
<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>
Also tried this code piece , but this opens the PDF and then prints:
<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>
Would appreciate any help.
解决方案 Are you okay with opening the PDF, but in a way that is invisible to the user? If so, you could set visibility of the object tag with something like <object style="display: none;" ...
. This way the PDF has a chance to open (unbeknownst to the user) and then seemingly magically print the pdf.
Hope this helps!
这篇关于在ClientSide浏览器中打印PDF而不打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!