| Author |
javax.print in ejb
|
new Graphics
Greenhorn
Joined: Nov 07, 2004
Posts: 2
|
|
I am writing something like this in my session bean, but PrintServiceLookup.lookupDefaultPrintService() cannot find any print service. When I write the code separately in the java file, it can get all the print service. So I guess it has to do with the ejb container. Can I use javax.print or java.awt api in ejb? Thanks & Regards ================================================= private DocPrintJob getPrintJobProperties() { PrintJob oPrintJob = null; JobAttributes oJobAttrib = null; PageAttributes oPageAttrib = null; Frame oFrame = null; Toolkit oToolkit = null; String sPrinterName = null; int iCopies = 0; DocPrintJob job=null; PrintService result = null; PrintRequestAttributeSet pras= null; //sPrinterName = "\\\\Stud\\HP LaserJet 5M"; sPrinterName = "HP5M"; iCopies = 1; if ((sPrinterName == null) || (iCopies == 0)) { } String sOrientation = "PORTRAIT"; pras = new HashPrintRequestAttributeSet(); PrintService[] defaultServices = PrintServiceLookup.lookupPrintServices(null, null); PrintService defaultServices1 = PrintServiceLookup.lookupDefaultPrintService(); if (defaultServices1 != null) { System.out.println("result1= " + defaultServices1.getName()); }//else: no PrintService available if (defaultServices != null) { int count = defaultServices.length; System.out.println("count = " + count); for (int i = 0; i < count; i++) { //for each PrintService System.out.println("result = " + defaultServices[i].getName()); if (defaultServices[i].getName().equalsIgnoreCase(sPrinterName)) { result = defaultServices[i]; break; } }//next PrintService }//else: no PrintService available try{ job = result.createPrintJob(); } catch(Exception e){ e.printStackTrace(); } return job; }
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
You can use the print service. But why you'd want to is another matter. The only printers you can get access to will be those visible to your application server machine, and not your client. AWT however you can't use. Again, why would you want to?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
new Graphics
Greenhorn
Joined: Nov 07, 2004
Posts: 2
|
|
Thanks. I want to do printing on the server side, that is, printing using session bean. I have tried crystal clear report engine, but it prints (using java.awt.printjob) in servlet engine; but i only want to do printing in ejb container. I am looking for solutions ... Any suggestion? Thanks & Regards
|
 |
 |
|
|
subject: javax.print in ejb
|
|
|