Java 如何在打印机中打印制表符

Java 如何在打印机中打印制表符,java,printing,Java,Printing,我必须用Java通过热敏打印机打印收据。 对于格式,我可以理解如何在手册的基础上打印align center,如下所示: 中心手册: 所以下面的代码是有效的: 中心代码: 现在,选项卡设置和选项卡手册: 选项卡手册: 但下面的代码不起作用: 选项卡代码: 我认为,您缺少结束制表符设置的NUL字节: private void printTabEnable(){ byte[] cmd = new byte[4]; cmd[0] = 0x1B; cmd[1] = 0x44;

我必须用Java通过热敏打印机打印收据。 对于格式,我可以理解如何在手册的基础上打印align center,如下所示:

中心手册:

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

现在,选项卡设置和选项卡手册: 选项卡手册:

但下面的代码不起作用: 选项卡代码:


我认为,您缺少结束制表符设置的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);
}
    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);
    }
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);
}