• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Client side printing from Servlet

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic