tags:

views:

157

answers:

3

Hi, I have an Enterprise Java web application that all of the business is migrated from client-server application. So I need to adapt all requirement including printing on every client (Using Dot Matrix / Plain text).

Printing requirement for client on separated client is they must get the report right away after the process is finished, let say print some system information. On Client-server is easy just for printing, but when I migrate to web apps, we used Server/applet service that embedded to the apps. So the applet will be initialized when the client open the browser.

It works, but too many issues. Sometime the applet is closed suddenly without action from client, so automatically the applet will be failed for checking the queued report from database. Is there any suggestion for this case?

I use Spring Framework as a business layer.

Thanks.

Regards,

Mr.K

+1  A: 

I had the same problem years ago.

This is what I did.

Since my processing was taking place on the server, I knew when the transaction was finished. So what I did was to send the print request directly from the server. The client printer was configured in the server and since it was used in the LAN it could be easily reached. That way I finished with all the problems I had with the applet, the tradeoff was they can only print in the office, but in my situation that was fine, not necessarily applies for you, give it a try.

UPDATE

In my case, the print was needed by different departments along the country.

Each department had an specific, unique printer for that task. So what I did was have that printer mounted in the server filesystem ( in Unix something like /Volumes/printers/EPSON-12345 , in Windows as x:\printers\EPSON-12345 ) When the user finished the transaction in the webapp I start in the server a print request. Java does not have any problem at all to print to a local printer and since a mapped printer is taken as local ( even though it is a remote one ) you don't need further authorizations or anything special.

Since I knew what the specific printers were mapped, and I knew what kind of transaction that was, I knew where to print.

Finally I use a property file to allow the printer to change from time to time and/or add more printers.

I don't quite remember the details but it was something like this in the server:

 ResourceBundle bundle = ResourceBundle.getBundle("printers");
 String serviceName    = bundle.getString("MEXICO.CITY.PRINTER");

 PrintService service = PrintService.find( serviceName );
 service.print( // document and etc );

But that was almost 4 yrs. ago so I don't remember exactly the details, but my program is still running :)

You can read more about the printing service in java here. It is way much simpler than what it look like.

OscarRyz
+.1 creative solution
Pierreten
@Pierreten: Was that a symbolic +1? :-o Yeah.. necessity is the mother of all inventions ( hence of creativity ) .
OscarRyz
hmm the case is almost same but how to configure the client printer by server and send the print request to the client?
Mr.K
A: 

Other ways to achieve a good result:

  • generate a PDF (using iText, or better JasperReports) on the server, and send it for download to the client, where he can print it.
  • have a print.css, and generate a web-page that is suitable for printing.
Bozho
A: 

If you do not want the client browser to orchestrate the printing (i.e. by sending a binary blob with a custom MIME-type which the user must set up to be sent to the printer), you must let your server do it.

This usually means that the user must have a default printer attached to their profile, and that the server knows how to send prints to that printer. Lots of fun :)

Thorbjørn Ravn Andersen