Developer Desk
Developer Desk

Reputation: 2344

Printing a pdf file stored on server to client side printer

I am generating PDFs file dynamically in my application using Apache PDFBox library. I have jsp page which is having Print button.When user click on that print button i want to generate PDF file and at the same time show pdf file on browser and apply window.print() method. How can i achieve this in my jsp page?

Upvotes: 0

Views: 3206

Answers (2)

pundit
pundit

Reputation: 312

There is an alternate solution to this. That is show the pdf in a div in your html and print that div.

For how to show pdf in a html div you can look Display Adobe pdf inside a div

For printing a div or any other html element there are jquery plugins available. I have used print.js that will print a html div, it will also maintain your css.

So when user clicks the print button first show the pdf in a div and then call the print function to print that div.

Upvotes: 1

AurA
AurA

Reputation: 12363

Create a pdf link on your page and the link should be mapped to the actual location the PDF exists on your server.

The browser actually handles what to do with the pdf (based on your browser settings) .... whether to download it or open it via plugin. The bottomline is you cannot control it via server side code.

In either of the case you cannot apply window.print() because that is only applicable to browser window and not pdf plugin functionality or if it gets downloaded then he has to manually open it.

Upvotes: 2

Related Questions