I'm trying to send some ZPL code to a Zebra TLP 2824 connected with USB from a Java application in Windows 7. I've tried different approaches but was not able to print yet. In the driver settings I activated passthrough mode and tried to install the printer with the generic / text-mode driver but nothing worked.
I always get unspecified Windows errors in the printing queue.
This is my code:
try {
PrintService psZebra = null;
String sPrinterName = null;
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i < services.length; i++) {
PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if (sPrinterName.toLowerCase().indexOf("generic") >= 0) {
psZebra = services[i];
System.out.println(psZebra);
break;
}
}
if (psZebra == null) {
System.out.println("Zebra printer not found.");
return;
}
DocPrintJob job = psZebra.createPrintJob();
String s = "${^XA^FO100,100^BY7^BCN,100,Y,N,N^FD123456^FS^XZ}$";
byte[] by = s.getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by, flavor, null);
job.print(doc, null);
} catch (PrintException e) {
e.printStackTrace();
}