• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing to a network printer from intranet servlet app

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!)
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic