[英]Printer Line break not works properly using Java
這是我用來使用java打印字符串的代碼
String string2 = " RECEIPT \n==============\nHeader2\nHeader 3\nLine 4 Goes Here\nLine 5 Goes Here\n============";
InputStream is = new ByteArrayInputStream(string2.getBytes());
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE ;
// Find the default service
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
System.out.println(service);
// Create the print job
DocPrintJob job = service.createPrintJob();
Doc doc= new SimpleDoc(is, flavor, null);
PrintJobWatcher pjDone = new PrintJobWatcher(job);
// Print it
job.print(doc, null);
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
它像在紙上打印一樣。
RECEIPT
==============
Header2
Header 3
Line 4 Goes Here
Line 5 Goes Here
當使用沒有字符串的inputStream時,也會發生同樣的情況。 任何建議。 並且需要解釋此DocFlavor的工作方式。
您必須使用\\r\\n
而不是\\r
。
有兩個ASCII代碼\\n
“換行”。 它告訴打印機移至下一行。 和\\r
“回車”將其移動到行首。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.