-1

如何使用 html 打印按钮在 iframe 中打印此 url 的 pdf

http://assessormap.co.la.ca.us/Geocortex/Essentials/REST/sites/PAIS/VirtualDirectory/AssessorMaps/ViewMap.html?val=8734-031

我使用这些线程的答案尝试了两种解决方案:

  1. 从 iframe 打印 pdf

  2. 直接从 JavaScript 打印 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 库。也许这是一条更好的路线。任何建议表示赞赏。谢谢。

4

1 回答 1

1

您拥有的 URL 未返回 PDF 文档。相反,它会返回一个嵌入了 PDF 的 HTML 文档。因此,您无法使用 iframe 或 Print.js 库正确打印文档。为此,您需要有一个返回实际 PDF 文档的 URL。

于 2019-04-02T13:52:44.127 回答