aspose file tools*
The moose likes Servlets and the fly likes Client side printing from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Client side printing from Servlet" Watch "Client side printing from Servlet" New topic
Author

Client side printing from Servlet

Girish Vasmatkar
Ranch Hand

Joined: Apr 24, 2008
Posts: 201
Not sure if it is the right forum because it involves different pieces of technology, but still here I go...

I have a button (Print ) on my web page, which if clicked, calls a servlet, which in turn does some server stuff and generated a byte array representing PDF data. The byte array is properly generated and no problem what so ever and I am able to send the data back to the browser.

I want to somehow open that data in adobe along with a print dialog (for that byte array), which MUST appear on client side and not on the server.

I tried java print API and as expected it opens up the print dialog on the server and not on the browser. I also tried some client side specific stuff, details are as follows -



First, I tried using a static pdf which is there on the file system, and teh problem with this is that with some adobe versions or IE version the "printWithDialog" does not seem to work. I get a java script error saying that the function is not available.I am not sure whether there is really an issue with adobe version or IE version, but I have experienced it.
So, on click of the button, I am not calling servlet directly, rather calling this HTML, so that pdf opens up with a print dialog.

In the real scenario, I would put my servlet's path in the data attribute of object tag. My questions are -

1. Am I right when I say that printWithDialog function is not reliable ?
2. Is there a way to somehow send some response headers or something so that browser reads it and open up a print dialog (that way printWithDialog won't be used).
3. is it possible to use print API and still be able to invoke the print dialog on client side (insane question, I know).
4. java Web Start - does it come into picture, in this case ?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
First off, why does the print dialog need to be popped open automatically at all? What if the user does not want to print the document? Maybe she wants to view it, or save it to disk. If she really wants to print it, then clicking the print button is not a big deal, is it?

1. Am I right when I say that printWithDialog function is not reliable ?

Yes. A quick search indicates that it is related to Adobe Reader - which may or may not be the piece of software used to display the PDF (there are numerous other options to display PDFs that do not involve the Adobe Reader - which is, after all, frequently found vulnerable to attacks).

3. is it possible to use print API and still be able to invoke the print dialog on client side

No

4. java Web Start - does it come into picture, in this case ?

No


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client side printing from Servlet