• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

javax.print in ejb

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
new Graphics
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic