如何打印pdf? [英] How to print a pdf?
问题描述
我有一个pdf网址,嵌入在iframe的矩形区域中。我想点击一个按钮打印它。我的代码如下所示:
I have a pdf url, embedded in a rectangular area of an iframe. I am trying to print it on click of a button . My code looks like this :
要打印的JavaScript:
function printPDF(pdfUrl)
{
var w = window.open(pdfUrl);
w.print();
w.close();
}
HTML代码:
<table>
<tr>
<td><input type="submit" value="Print"
name="Submit" id="printbtn"
onclick="printPDF('http://www.irs.gov/pub/irs-pdf/fw4.pdf')" /></td>
</tr>
现在在MF中就是这样:
Now in MF it is coming like this :
问题,它在chrome和IE中无法正常工作。我有chrome 20和IE 8.在chrome中,打印窗口被加载到一个新选项卡中(这没关系)但是pdf没有在预览中加载。在IE中,pdf刚刚在新选项卡中打开,并且没有出现打印提示。
The problem , its not working properly in chrome and IE. I have chrome 20 and IE 8. In chrome the print window gets loaded in a new tab(which is ok) but pdf does not get loaded in preview. In IE the pdf just gets opened in a new tab and print prompt does not come up.
在任何人问我之前,pdf可能具有固有的打印功能。但我正在处理的pdfs需要一个打印按钮。人们,请帮助我。是否有解决方案,适用于所有3个浏览器。
Before any one asks me, pdf might have inherent print functionality. but the pdfs that i am processing need to have a print button. People, kindly help me out here. Is there a solution, which is applicable in all the 3 browsers .
推荐答案
伙计们,刚刚得到一个解决方案,适用于我。
Folks, just got a solution , which works fine for me .
function printPage(htmlPage)
{
var w = window.open("about:blank");
w.document.write(htmlPage);
if (navigator.appName == 'Microsoft Internet Explorer') window.print();
else w.print();
}
所以,如果它是MSIE,那么我们可以使用:window.print ();
So, if it is MSIE, then we can just use : window.print();
这篇关于如何打印pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!