我有一个与Java和热敏打印机通信的应用程序
使用Star tsp 100打印机使热敏打印机以条形码/强调/不同尺寸打印收据等.
我可以让程序打印出我喜欢的东西,但打印机很慢.我相信原因是我使用非优选的方式/方法发送字节命令.
public static void Command(byte[] bytes) throws Exception{
//The bytes array is the argument, consisting of a byte[] array such as
//byte[] Emphasis = {0x1B, 0x45}; //Which gives the text boldness.
//And Command(Emphasis); To execute the command with this method.
DocPrintJob job = PrintServiceLookup.lookupDefaultPrintService().createPrintJob();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);
}
当我想打印一个字符串我使用这种方法.
public void PrintString(String s) throws Exception{
DocPrintJob job = PrintServiceLookup.lookupDefaultPrintService().createPrintJob();
System.out.println(job + "
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
byte[] b = s.getBytes("CP437");
Doc doc = new SimpleDoc(b, flavor, null);
job.print(doc, null);
}
因此,只要文本具有相同的样式,我就会使用此方法打印大量字符串(等等不需要其他命令).所以打印收据的代码看起来有点像这样.
PrintClass P = new PrintClass();
String Greating = "Hello";
P.Command(P.Emphasis);
P.Command(P.DoubleSize);
P.Command(P.Underline);
P.PrintString(Greating);
P.Command(P.CancelEmphasis);
P.Command(P.ResetSize);
P.Command(P.CancelUnderline);
String body = GenerateReceiptBody();
P.PrintString(body);
P.Command(P.Halfsize);
String footer = Constants.getFooter();
P.PrintString(footer);
P.Command(P.Cut);
收据按照我想要的方式打印,但这是一个非常缓慢的过程.
在发送POS / ESC命令时,我绝不是专家.然而,我觉得必须有一个更好/更快的方法来做到这一点,因为许多应用程序可以打印不同大小/条形码/样式/徽标的收据,而不需要花费10-20秒.
当收据打印机到达收据的主要部分或“正文”,其中所有东西都具有相同的尺寸/样式然后它很快就会进入,这让我相信这对我来说很慢的原因是因为我正在创建/执行如此多的个人“打印工作”.
那么有没有更快的方式将ESC / POS命令作为字节命令发送到Thermal打印机?在这种情况下,热敏打印机是Star tsp 100,但我不认为这对答案有任何影响.
任何答案都将非常感激.如果这是一个简单的问题,我很抱歉,因为我仍然在学习如何编码.