Javascript html: print() 嵌入文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10296783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html: print() embed file
提问by Rps
I am showing a pdf inside a html using:
我正在使用以下方法在 html 中显示 pdf:
<embed id="print" src="file.pdf" type="application/pdf" width="100%" height="100%">
I would like to create a button that prints that file.
我想创建一个打印该文件的按钮。
I thought it would be something like this; but it isn't working.
我以为会是这样;但它不起作用。
<button onClick="javascript:document.getElementById('print').print();">
Anybody an idea how I can call the print function on an embedded file?
有人知道如何在嵌入文件上调用打印函数吗?
回答by agarcian
<script type="text/javascript">
function printPDF(pdfUrl)
{
var w = window.open(pdfUrl);
w.print();
}
</script>
You can call this function printPDF("http://mywebsite.com/myfile.pdf")
你可以调用这个函数 printPDF("http://mywebsite.com/myfile.pdf")