Javascript 以编程方式调用 Chrome 对话框打印的“另存为 PDF”功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22096749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript call programmatically the "Save as PDF" feature of Chrome dialog print
提问by suuuzi
Google Chrome have the option "Save as PDF" when you enter the Print dialog or window.print(). The user need to choice this option in dialog to save the page as pdf.
当您进入“打印”对话框或 window.print() 时,Google Chrome 具有“另存为 PDF”选项。用户需要在对话框中选择此选项才能将页面另存为 pdf。
Can I call some funcion or pass an argument to window.print() in chrome to "print" the page as a pdf without the print dialog appears?
我可以调用一些函数或将参数传递给 chrome 中的 window.print() 以将页面“打印”为 pdf 而不出现打印对话框吗?
Any ideas?
有任何想法吗?
回答by achhatre
Unfortunately there isn't any param you could pass to window.print(); and force it to print pdf unless there is a pdf driver plugin already present on the client's browser. There are plugins for firefox and IE (JS Print Setup and MeadCo Script respectively).
不幸的是,没有任何参数可以传递给 window.print(); 并强制它打印 pdf,除非客户端浏览器上已经存在 pdf 驱动程序插件。有适用于 firefox 和 IE 的插件(分别是 JS Print Setup 和 MeadCo Script)。
You may want to look at MrRio/jsPDF, a tool to generate pdf files at client-side JS.
你可能想看看MrRio/jsPDF,一个在客户端 JS 生成 pdf 文件的工具。