File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Printing to a network printer from intranet servlet app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Printing to a network printer from intranet servlet app" Watch "Printing to a network printer from intranet servlet app" New topic
Author

Printing to a network printer from intranet servlet app

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Im working on a large intranet app for a local business that is built in servlets. Im cleaning out input data from a comma deliminated file & dumping into database tables based on certain criteria. Once that is done part of the data will be processed & dumped into an outgoing coma deliminated file for upload to a website but the balance of the data (that not acceptable for automatic processing needs to be printed out for one of their staff to look at. Ive glanced thru the java.awt.print package (I will admit with some minor confusion). Here's exactly what needs to happen:
I pull all the fields from ng table (one row at a time) & then I need to format them with the correct verbage for each piece of data (we are dealing with salesman here) Plus a header on each plain explaining why this data couldnt be processed automatically. NO TWO files will be the same unfortunately.
Secondly this project is running on a Linux server on this company's website. There are network printers available.
I could wimp out & just spit the stuff out to html & let them hit the print button but I know that's not the right way to handle this. Does anyone out there have any experience with this or, even better, some sample code? It would really help to look at another block of code & see what Im up against here. Thanks much in advance!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
HTML would probably be the easiest, but you might also consider a conversion to PDF so the users could use Acrobat to print. If you have not already done alot of work you might consider doing this with Cocoon, which has provision for PDF output.
http://big.faceless.org/index.jsp <- various Java libraries for creating PDF
Also see FOP - the Formatting Objects Project at Apache 0.20.3
http://xml.apache.org/fop/index.html

The only time I fooled around with java.awt.print the output was NOT pretty, and it was slow. It is really intended for use by desktop applications.
Bill
(whose Cocoon book comes out this week!)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Actually, you didn't say if the preferred printing app would be on the CLIENT or on the SERVER.
On the server, under Linux, it's trivial - just open a PrintStream on /dev/lpr or some other convenient Linux print queue. You can do raw monospaced text or PostScript output.
On the client, it's stickier. An Applet can't print unless it's signed. You can transmit the results back to the browser as HTML, which is OK for small reports (1-pagers) as long as the exact placement of items isn't critical. Otherwise you need to print a PDF, which means that you'd want some sort of PDF formatter. There are commercial ones and there are open-source ones like GnuJPDF or the XML-oriented Apache FOP.
Actually, if ALL your clients were Linux machines, you could probably send back PostScript, but I've learned that there's aways some joker who'll be running Windows. Like the Head of Accounting.


Customer surveys are for companies who didn't pay proper attention to begin with.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Sorry so long to get back here....been one &*(&(*& of a week! OUCH! I can go client or server on the print but because its a netwrok printer & they want these to come out in numeric order (the bid sheets that is) Im thinking .pdf & then load it into their browser & then they can just print it from there... Ill look at the pdf creation packages Bill suggested, no time to get cocoon set up right now (Server guy already wants me dead). If anyone else knows a pdf creation package that isnt going to make my head swim Id LOVE to hear about it. Thanks all!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing to a network printer from intranet servlet app