Link to send pdf straight to printer dialog

别说谁变了你拦得住时间么 提交于 2020-01-04 15:26:11

问题


I've tried the following 2 methods..

<embed src="assets/pdf/mypdf.pdf" id="Pdf1" name="Pdf1" hidden="true">

<a class="print" onClick="document.Pdf1.printWithDialog();"></a>

<a onClick="document.getElementById('Pdf1').printWithDialog()" style="cursor:hand;">Print file</a>

Another attempt..

<script type="text/javascript">
function printPDF(pdfUrl) 
{
    var w = window.open(pdfUrl);
    w.print();
}
</script>

<a class="print" onClick="printPDF("assets/pdf/mypdf.pdf");">a</a>

None seem to work. Any solution so I can click a link and it sends the pdf to the print dialog? window.print just brings up the actual site in the dialog, not the pdf.

来源:https://stackoverflow.com/questions/13080180/link-to-send-pdf-straight-to-printer-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!