直接从JavaScript打印PDF我正在构建HTML格式的PDF列表。在列表中,我想要包含下载链接和打印按钮/链接。有没有办法在没有用户看到PDF或打开PDF查看器的情况下直接打开PDF的“打印”对话框?将PDF下载到隐藏的iframe并触发使用JavaScript打印的一些变体?
3 回答
BIG阳
TA贡献1859条经验 获得超6个赞
基于以下评论,它不再适用于现代浏览器
此问题演示了一种可能对您有所帮助的方法:静默打印嵌入式PDF
它使用<embed>标记将PDF嵌入到文档中:
<embed type="application/pdf" src="path_to_pdf_document.pdf" id="pdfDocument" width="100%" height="100%" />
然后.print()在加载PDF时在Javascript中调用元素上的方法:
function printDocument(documentId) {
var doc = document.getElementById(documentId);
//Wait until PDF is ready to print
if (typeof doc.print === 'undefined') {
setTimeout(function(){printDocument(documentId);}, 1000);
} else {
doc.print();
}}您可以将嵌入放置在隐藏的iframe中并从那里打印出来,为您提供无缝体验。
添加回答
举报
0/150
提交
取消
