简体   繁体   中英

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. 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:

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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