如何使用 html 打印按钮在 iframe 中打印此 url 的 pdf
我使用这些线程的答案尝试了两种解决方案:
我的 html 是一个 iframe,上面有 pdf url,我的 js 看起来像:
<embed
type="application/pdf"
src="the url that is above. too long to fit here"
id="pdfDocument"
width="100%"
height="100%" />
<button id="printButton" onclick="javascript:printPage()"
>
我的js:
function printPage(documentId) {
var doc = document.getElementById('pdfDocument');
//Wait until PDF is ready to print
if (typeof doc.print === 'undefined') {
setTimeout(function(){printPage(documentId);}, 1000);
} else {
doc.print();
}
}
我没有运气。按钮无响应。js一定有问题。他们有一个 printjs 库。也许这是一条更好的路线。任何建议表示赞赏。谢谢。