File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Printing to a Printer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Printing to a Printer" Watch "Printing to a Printer" New topic
Author

Printing to a Printer

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 764
Does anyone know of a way to include a java applet in an HTML page (or any script for that matter) that can take a string (stored in the page) and send it directly to the clients default printer?
I would like to store a string in the page and use that (if its reasonable). Im using a CGI application (written in Perl) that generates HTML pages but I need to include some type of client-side script or so forth to handle the local stuff. I wanted to include a Print button on one of those pages for the user to be able to click and send the accumulated information (shopping cart contents) to the user's local default printer. I was wondering if Javascript and/or Java Applets would be totally out of the question or not for handling this? If it is then what would be a good alternative to using these languages? I realize that Javascript is about useless and Java applets (due to IO security) cant due much in the way of file maintenance and, especially, creating Print Jobs (at least that was my assumption). Any help would be greatly appreciated.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Rob,
Applets are probably not a viable consideration because of the "sandbox", that dirty little place that SecurityManagers force our poor little applets to run. The only way that you can get to local resources thru an applet is if there is policy file that grant's those permissions. In a corporate intranet, that wouldn't be a problem, but if you want your applet used by random surfers, you have a big problem.
Hope this helps
Michael Morris
SCJP2


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 764
Michael,
I thought that might be the case but it was very much desired by a customer of ours. I was wondering, however, if there was any type of workaround that I could use (i.e. calling a Visual Basic executable to do the work for me)? They should really think of renaming "sandbox" to "quicksand hole" . Thanks for your quick response.
Rob
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Rob,
ActiveX is probably your best bet here. It's pretty simple to create an ActiveX control in VB, so if you're comfortable with VB, that's what I'd do. You're still going to have to deal with popping up a window to install your control on the client's machine on the first occurance. That generally means getting a signed certificate from VeriSign if you want surfers to take you seriously.
If your application is targeted to a particular group (eg a single corporation), then applets may still be an option. You just have to make sure that all client machines have an appropriate permission entry in the system security file to allow your applet to access the local printer.
Hope this helps
Michael Morris
SCJP2
 
 
subject: Printing to a Printer
 
Threads others viewed
Print simple jpeg image using java
Change the Printer Orientation??
Printing to a Printer
Printing a text file to a printer
Printing to a Printer
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture