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;
}