0

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!

0

2 Answers 2

2

No, it's not possible. You can only print things natively displayed by your browser.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

3 Comments

That may require that the browser has the pdf reader installed as a plugin instead of as a standalone application, probably.
Yes, a pdf reader needs to be installed, but the .print() call works just fine.
I tried this (granted on a local server running MAMP) and it crashed my browser tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.