Printing in servlets?
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
hi,
can I have the facility of printing documents from Servlets? I need to provide a PRINT option in HTMl pages generated from servlet?
How do I go about doing this? plz guide me
thnaking u in advance,
cheers
Aman
can I have the facility of printing documents from Servlets? I need to provide a PRINT option in HTMl pages generated from servlet?
How do I go about doing this? plz guide me
thnaking u in advance,
cheers
Aman
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It sounds like you want the client machine to be able to print. Servlets run on the server machine, so they can't use the client machine's printers - not only is the whole http protocol foreign to that process, but the server machine doesn't know anything about the client's printers anyway.
Making a client print using servlets is no different than it would be for any other way of producing web documents. You can return output in a custom format like PDF or MS-WORD, or you can return straight HTML - in either case, the user has to manually select "print" from the file menu (or you have to do something like setup a "print" button on the HTML that's tied to a Javascript that does printing).
You can take a more active role in printing by embedding a Java applet on the HTML page, but it would have to be signed, since Java's sandbox rules forbid applets from printing otherwise.
Making a client print using servlets is no different than it would be for any other way of producing web documents. You can return output in a custom format like PDF or MS-WORD, or you can return straight HTML - in either case, the user has to manually select "print" from the file menu (or you have to do something like setup a "print" button on the HTML that's tied to a Javascript that does printing).
You can take a more active role in printing by embedding a Java applet on the HTML page, but it would have to be signed, since Java's sandbox rules forbid applets from printing otherwise.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Maybe you can try embedding a javascript print function in the html thrown by the servlet.
Aman Rustogi
Greenhorn
Posts: 22
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
thx all!!
but the solution provided dusnt serve my purpose.
The javascript print option doesnt allow us to select the file to print and besides it isnt very reliable and also doesnt work in DOM!!
So I've designed my servlet in a manner in which it first displays a file dialog box enabling user to select the file and then submitting the data which will invoke another/same servlet, get an instance of PrinterJob, set the required attributes, have an inner class implementing Printable interface thus overriding Print(), draw the contents of the requested file to the Graphics object and then print the contents.
How does it sound? even i'm not sure of it, still working on it!
Thx all for ur support!
cheers
Aman
but the solution provided dusnt serve my purpose.
The javascript print option doesnt allow us to select the file to print and besides it isnt very reliable and also doesnt work in DOM!!
So I've designed my servlet in a manner in which it first displays a file dialog box enabling user to select the file and then submitting the data which will invoke another/same servlet, get an instance of PrinterJob, set the required attributes, have an inner class implementing Printable interface thus overriding Print(), draw the contents of the requested file to the Graphics object and then print the contents.
How does it sound? even i'm not sure of it, still working on it!
Thx all for ur support!
cheers

Aman
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Sounds like you're on the right track.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I see you know the print package very well,
so please can you e-mail some simple code or plain Instructions
how to print a plain java/swing component, since I can't get it
working,
It will be very helpfull,
[email protected]
so please can you e-mail some simple code or plain Instructions
how to print a plain java/swing component, since I can't get it
working,
It will be very helpfull,
[email protected]
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi Aman,
Can you mail to me how I can print through the servlets on the client side, if possible are there any other ways to do.
I am trying to generate reports that should be printer on the client who will press a button like Print Report on his machine
on clicking the button a servlet is invoked that will get the data from the database and it should throw it in a formatted format on the client's printer.
thanks,
p ramesh babu
maimailto:[email protected]
Can you mail to me how I can print through the servlets on the client side, if possible are there any other ways to do.
I am trying to generate reports that should be printer on the client who will press a button like Print Report on his machine
on clicking the button a servlet is invoked that will get the data from the database and it should throw it in a formatted format on the client's printer.
thanks,
p ramesh babu
maimailto:[email protected]
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Still servlet runs at server, and can access network printers connected to it. But you can't print on specific client printer. If you can do that, that over rides simple web security principle. In web client should initiate the action, and authorise use any local resources. Just selecting a file won't give you that permission. Any way check it. Even I am interested. if you succeed post your solution here. bye.
regards.
Raghavendra Holla.
regards.
Raghavendra Holla.
Aman Rustogi
Greenhorn
Posts: 22
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
Thanking u'll again for all replies and queries. I'm still in development stage of the code to print files to the printer. The sooner I'm thr' with it, I shall publish it here! Currently i'm encountering an error while drawing the contents of file to be printed to the graphics object using drawString (). Calling this function, crashes the HotSpot Virtual Machine. Working 'round for a feasible solution, shall keep u updated. I guess the problem is using post-script printer drivers or with data-format sent to the printer - not sure yet!
Raghavendra, as u rightly said that i cannot access/print to clients printer using servlets, but i need this option in my intranet/interner site which will be accessible to just ONE SINGLE USER!
cheers
Aman
Thanking u'll again for all replies and queries. I'm still in development stage of the code to print files to the printer. The sooner I'm thr' with it, I shall publish it here! Currently i'm encountering an error while drawing the contents of file to be printed to the graphics object using drawString (). Calling this function, crashes the HotSpot Virtual Machine. Working 'round for a feasible solution, shall keep u updated. I guess the problem is using post-script printer drivers or with data-format sent to the printer - not sure yet!
Raghavendra, as u rightly said that i cannot access/print to clients printer using servlets, but i need this option in my intranet/interner site which will be accessible to just ONE SINGLE USER!
cheers

Aman
| Replace the word "snake" with "danger noodle" in all tiny ads. The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











