aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes javax.print in ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "javax.print in ejb" Watch "javax.print in ejb" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: javax.print in ejb
 
Similar Threads
Event Listeners in Java Print Service API
help in java printing
How to get List of Client Printers
To print pdf file
help in java printing