在iframe中打印pdf网址

问题描述 投票:-1回答:1

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

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

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

  1. Print pdf from iframe
  2. Print PDF directly from JavaScript

我的html是上面的pdf网址的iframe,我的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库。也许这是一条更好的路线。任何建议赞赏。谢谢。

javascript html pdf printing printjs
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.