简体   繁体   English

打印将文件引用传递到javascript window.print()/使用javascript打印pdf

[英]Print pass a file reference to javascript window.print() / print a pdf using javascript

I just want to call the browser's print functionality, but rather than have it print the current page, I want it to print a specific document. 我只想调用浏览器的打印功能,而不是要它打印当前页面,而是要它打印特定的文档。 Is this possible? 这可能吗? I'm aware of how to use things like dom2pdf for dynamic pdf creation, and I'm aware of javascript's window.print() functionality, but I'm not aware of how to print a separate, pre-existing PDF document using javascript. 我知道如何使用诸如dom2pdf之类的东西来动态创建pdf,并且我知道javascript的window.print()功能,但是我不知道如何使用javascript打印单独的,预先存在的PDF文档。 。 Thanks! 谢谢!

If the PDF is on your server, you can open a new window that has the PDF loaded and call .print() on the window: 如果您的服务器上有PDF,则可以打开一个已加载PDF的新窗口,然后在该窗口上调用.print():

var page = window.open('/path/to/pdf');
page.print();

If you want it to be hidden, you can do the same thing with an iFrame. 如果希望将其隐藏,则可以使用iFrame执行相同的操作。 If it's not on your server, you're out of luck due to cross-domain issues. 如果它不在您的服务器上,则由于跨域问题,您很不走运。

No, it's not possible. 不,不可能。 You can only print things natively displayed by your browser. 您只能打印浏览器本地显示的内容。

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

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