I have problem with cutting paper. I have Epson TM-T20 Receipt, and trying to cut paper after printing is done. I found somewhere that this is code for cutting byte[] bytes = { 27, 100, 3 }
, but it's not working.
Below is code I'm using for printing.
public static void printer(String printerData, Boolean bill) throws IOException {
try {
PrintService[] printServices = PrinterJob.lookupPrintServices();
String testData = printerData + "\r";
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] bytes = { 27, 100, 3 }; //Code for cutting
outputStream.write(testData.getBytes(Charset.forName("UTF-8")));
outputStream.write(bytes);
InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(service);
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);
PrintJobWatcher pjDone = new PrintJobWatcher(job);
job.print(doc, null);
pjDone.waitForDone();
is.close();
} catch (PrintException e) {
Writer fw = new OutputStreamWriter(new FileOutputStream("log.txt", true), StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter writer = new PrintWriter(bw);
e.printStackTrace(writer);
writer.close();
} catch (IOException e) {
Writer fw = new OutputStreamWriter(new FileOutputStream("log.txt", true), StandardCharsets.UTF_8);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter writer = new PrintWriter(bw);
e.printStackTrace(writer);
writer.close();
}
}