admin管理员组文章数量:1332345
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 to print :
function printPDF(pdfUrl)
{
var w = window.open(pdfUrl);
w.print();
w.close();
}
HTML-Code :
<table>
<tr>
<td><input type="submit" value="Print"
name="Submit" id="printbtn"
onclick="printPDF('.pdf')" /></td>
</tr>
Now in MF it is ing like this :
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 e up.
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 .
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 to print :
function printPDF(pdfUrl)
{
var w = window.open(pdfUrl);
w.print();
w.close();
}
HTML-Code :
<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>
Now in MF it is ing like this :
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 e up.
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 .
Share Improve this question edited Dec 19, 2012 at 21:19 PointedEars 15k4 gold badges35 silver badges33 bronze badges asked Dec 19, 2012 at 8:34 The Dark KnightThe Dark Knight 5,58513 gold badges58 silver badges104 bronze badges 3-
Why not just put
window.print()
ononload
event of body of youriframe
page. – vusan Commented Dec 19, 2012 at 8:37 - I did not understand what you are telling me to do. onloading a body is a bad move also i think – The Dark Knight Commented Dec 19, 2012 at 8:40
- Related thread - stackoverflow./questions/687675/… – KV Prajapati Commented Dec 19, 2012 at 8:43
1 Answer
Reset to default 2Folks, 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();
}
So, if it is MSIE, then we can just use : window.print();
本文标签: javascriptHow to print a pdfStack Overflow
版权声明:本文标题:javascript - How to print a pdf? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742327778a2454071.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论