潇潇雨雨
不确定你是否能够解决它,但这里有一个例子final byte[] VALIDATION_MODE = new byte[]{27, 'c', '0', 4}; // Print in validation modefinal byte[] PAPER_FULL_CUT = {0x1d,0x56,0x00}; // Full cut paperfinal byte[] PAPER_PART_CUT = {0x1d,0x56,0x01}; // Partial cut paperpublic void print(String receiptContent, String printerName) throws IOException { DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; DocPrintJob docPrintJob = selectedPrinter(printerName).createPrintJob(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(VALIDATION_MODE); outputStream.write(receiptContent.getBytes()); outputStream.close(); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); Doc doc = new SimpleDoc(inputStream, flavor, null); try { docPrintJob.print(doc, null); } catch (PrintException e) { System.out.println("Error:" + e.getMessage()); } System.out.println("Print Job Finished"); }