使用JavaScript打开Chrome PDF查看器对话框
我正在尝试为用户提供使用Chrome本身将当前网页另存为PDF的选项,不需要其他浏览器支持,并且引入第3方系统也不可行.
I am trying to offer users the option to save the current webpage as a PDF using Chrome natively, no other browser support is required and introducing a 3rd party system is not a practical option.
当前,我必须手动指示用户打印预览中打开PDF"链接在打印对话框中的位置,并且仅提供以下按钮:
Currently I have to manually instruct the user where the "Open PDF in Preview" link is within the print dialogue and only offer the following button:
<a href="#" onclick="event.preventDefault(); window.print();">
PDF Preview
</a>
我想直接将用户跳转到PDF预览对话框以供他们保存,以下内容当然行不通,但与我想要实现的功能更加相似.
I would like to jump the user straight to the PDF preview dialogue for them to save, the following will of course not work, but is more similar to what I would like to achieve.
<a href="#" onclick="event.preventDefault(); window.print('pdf');">
PDF Preview
</a>
无法做到这一点.
Chrome当前符合HTML标准,因为打印"通常意味着以某种物理方式获取页面,无论是传统的打印文档还是PDF.如何选择执行此操作取决于浏览器供应商.
Chrome currently meets the HTML standard as "print" generically means obtaining the page in some physical way, be that a traditional printed document or a PDF. How it chooses to do this is up to the browser vendor.
此外,Chrome用户可以选择其默认打印操作为PDF或网络上的打印机.
Additionally Chrome users can select their default action for printing to be PDF or a printer on their network.
据此我推断Chrome不太可能让Web应用程序覆盖用户首选项.
From that I would infer that it's unlikely Chrome would let the web application override the user preference.
来源