如何在打印机中打印标签

时间:2014-04-30 07:58:20

标签: java printing

我必须使用Java通过热敏打印机打印收据。 对于格式,我可以理解如何在手册上打印对齐中心,如下所示:

中心手册:

[Name] Select justification 
[Format] ASCII   ESC a n 
         Hex     1B 61 n 
         Decimal 27 97 n 
[Range] 0 ≤ n ≤ 2, 48 ≤ n ≤ 50 
[Description] Aligns all the data in one line to the specified position. 

 n selects the type of justification as follows: 
   n    Justification 
 0, 48 Left justification 
 1, 49 Centering 
 2, 50 Right justification 

所以下面的代码有效: 中心代码:

    private void printAlignCenter(){
        byte[] cmd = new byte[3];
        cmd[0] = 0x1B;
        cmd[1] = 0x61;
        cmd[2] = 0x01;
        wfComm.sndByte(cmd);
    }

现在,标签设置和标签手册: 标签手册:

[Name] Set horizontal tab positions 
[Format] ASCII   ESC D n1...nk NUL 
         Hex     1B 44 n1...nk 00 
         Decimal 27 68 n1...nk 0 

[Range] 1 ≤ n ≤ 255 
        0 ≤ k ≤ 32 

[Description] Sets horizontal tab positions. 
        ▪ n specifies the column number (counted from the beginning of the 
          line) for setting a horizontal tab position. 
        ▪ k indicates the total number of horizontal tab positions to be set. 

[Name] Horizontal tab 
[Format] ASCII HT 
         Hex 09 
         Decimal 10 
[Description] Moves the print position to the next horizontal tab position
[Notes] ▪ This command is ignored unless the next horizontal tab position 
          has been set. 

但下面的代码不起作用: 标签代码:

    private void printTabEnable(){
        byte[] cmd = new byte[3];
        cmd[0] = 0x1B;
        cmd[1] = 0x44;
        cmd[2] = 0x28;
    //     cmd[3] = 0x08;//08//10
    //     cmd[4] = 0x12;//12//20
            wfComm.sndByte(cmd);
    }

    private void printTab(){
        byte[] cmd = new byte[1];
        cmd[0] = 0x09;
        wfComm.sndByte(cmd);
    }

1 个答案:

答案 0 :(得分:0)

我认为,您缺少NUL字节来结束标签设置:

private void printTabEnable(){
    byte[] cmd = new byte[4];
    cmd[0] = 0x1B;
    cmd[1] = 0x44;
    cmd[2] = 0x28;
    cmd[3] = 0x00; // Terminates the tab setup
    wfComm.sndByte(cmd);
}