问题描述
将一个静态HTML页面视为 test.html
,并且该页面的可打印版本已存储在 test.pdf
。当访问者告诉他们他们的浏览器时,如何指导浏览器加载和打印 test.pdf
而不是 test.html
浏览器打印?
Consider a static HTML page as test.html
, and a printable version of the page has been stored in test.pdf
. How can I guide browser to load and print test.pdf
instead of test.html
when visitors tell their browser to print?
如果无法在HTML页面中引入打印按钮(使用JavaScript)来执行此操作?
If it's not possible how can I introduce a print button (using JavaScript) within the HTML page to do so?
推荐答案
您不能强制浏览器打印与用户请求/查看不同的文件。这将是一个安全噩梦!
You cannot force the browser to print a different file than the user is requesting/viewing. That would be a security nightmare!
选项1(JS(根据要求)& HTML)
我建议在您的网站上创建一个打印版本
链接,以便将用户导向.pdf(在新窗口中打开PDF会更好) 。
I suggest creating a printable version
link on your site that will direct the user to the .pdf (opening the PDF in a new window would be preferable).
<!-- JS -->
<script type="text/javascript">
function LoadPrintableVersion() {
window.open("Test.pdf");
}
</script>
<!-- HTML -->
<span id="spanPrintableVersion" onclick="LoadPrintableVersion()">
Printable Version
</span>
选项2(纯html)
Option 2 (pure html)
<a href="test.pdf" target="_blank">Printable Version</a>
这篇关于我如何强制浏览器打印PDF版本的网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!