ラベルプリンター Brother TD-4000 で ESC/P コマンドの使用を開始しようとしています。プリンターの適切なソフトウェアである P-touch Editor 5.1 をテストしました。複数のラベルを作成できます。プリンターは正常に動作しますが、Java コードから独自のラベルを作成しようとすると、プリンターが動作しません。まったく、反応しません。私は EZPL を使用して他のラベル プリンターを使用してきましたが、この方法で問題はありませんでした。私は今何を試すことができますか?
私のコードは非常に単純です。
public class PrintESC_P {
public static void main(String[] args) {
PrintService printService = null;
String printerName = "Brother TD-4000";
HashAttributeSet attributeSet = new HashAttributeSet();
attributeSet.add(new PrinterName(printerName, null));
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet);
if (services.length == 0) {
throw new IllegalArgumentException("Printer not found.");
} else if (services.length > 1) {
System.out.println("Found more than one printer. Only the first printer will be used.");
}
printService = services[0];
System.out.println("Printer found: "+printService.getName());
try {
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
String _ESC_P_Code = "ESC i a 00h\r\n" +
"ESC @\r\n" +
"ESC i L 01h\r\n" +
"ESC ( C 02h 00h FCh 02h\r\n" +
"ESC $ 2Bh 00h\r\n" +
"ESC ( V 02h 00h 6Dh 01h\r\n" +
"ESC k 0bh\r\n" +
"ESC X 00h 64h 00h\r\n" +
"PRINTER TEST\r\n" +
"ESC i C\r\n" +
"FF\r\n";
SimpleDoc doc = new SimpleDoc(_ESC_P_Code.getBytes(), flavor, null);
DocPrintJob job = printService.createPrintJob();
job.print(doc, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
前もって感謝します!