简体   繁体   English

Javascript:模拟PDF打印

[英]Javascript: Simulate PDF Print

I have an embedded PDF in my HTML. 我的HTML中有嵌入式PDF。

<object id="myPDF" type="application/pdf" data="visual.pdf" style="width:500px; height:500px"></object>

This works perfectly, and the file is displayed on the page, along with the basic features such as "print", "save", etc. 这完美地工作,文件显示在页面上,以及“打印”,“保存”等基本功能。

Is there any way of providing <input type="button" /> whose onclick function will invoke the "print" functionality of the embedded PDF? 有没有办法提供<input type="button" />其onclick函数将调用嵌入式PDF的“打印”功能? The reason for this is because I want to hide the tag, and just provide a link or a button which will print the hidden document. 这是因为我想隐藏标签,只提供一个链接或按钮来打印隐藏文档。

put an iframe in html page. 在html页面中放置一个iframe。

include your pdf inside iframe. 在iframe中包含你的pdf。

Then which ever button click you want to show PDFs 然后按钮点击你想要显示PDF

onclick='window.open ("yourpdf.html","mywindow");'

after loading this page call window.print(); 加载此页面后调用window.print();

I would imagine that you could call some functions on the PDF reader with Javascript. 我想你可以用Javascript调用PDF阅读器上的一些函数。 However, please don't do this. 但是,请不要这样做。 Not everyone uses Adobe's Acrobat Reader to read PDFs. 不是每个人都使用Adobe的Acrobat Reader来阅读PDF。 Other readers won't support your code. 其他读者不支持您的代码。 Because of this, it isn't possible. 因此,这是不可能的。

Furthermore, it isn't advisable to use the <object> tag. 此外,不建议使用<object>标记。 It is best to leave it up to the user, and give a simple link to the PDF. 最好将其留给用户,并提供PDF的简单链接。 Then it will work for anyone with a compatible reader. 然后它适用于任何拥有兼容阅读器的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM