I'm trying to send a PDF/DOC/ODT file to a printer connected in LAN using javax.print, but it doesn't even send the job to the print queue. I've tried to print the file "normally" (using Adobe Reader /Open Office) and works perfectly, so the printer is well connected. I've also tried to send it to a virtual printer (PDFCreator) from code and it worked.
Here is the code I'm using:
public Boolean Imprimir (String filePath){
Boolean correct = true;
FileInputStream psStream = null;
try {
psStream = new FileInputStream(filePath);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
correct = false;
}
if (psStream != null) {
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
PrintService myPrinter = null;
for (int i = 0; i < services.length; i++){
String svcName = services[i].toString();
if (svcName.contains("Xerox")){
myPrinter = services[i];
break;
}
}
if (myPrinter != null) {
DocPrintJob job = myPrinter.createPrintJob();
try{
job.print(myDoc, aset);
}
catch(PrintException ex){
ex.printStackTrace();
correct = false;
}
} else {
System.out.println("No printer services found");
correct = false;
}
}
else{
correct = false;
}
return correct;
}
The printer is connected using LPR protocol.
Thanks in advance
Edit: I've also tried using jLpr, as suggested in other posts (Java printing directly to a Postscript network printer). It didn't work either, no error messages though, the job doesn't appear in the printer's queue.