如何更改字体大小,而在打印的Andr​​oid?而在、字体大小、如何更改、oid

2023-09-07 10:13:51 作者:遇见你用光了所有的运气

我通过我的Andr​​oid手机发送文本到蓝牙打印机。无论是打印机和我的设备通过蓝牙连接。 它的正常工作和我收到的文件所需的文本。

我的问题是:

打印机走的是文本的默认的 字体大小 的。我要改变的是要打印的文本的字体大小。

我怎样才能做到这一点?

下面是我的$ C $打印bloutooth连接后的文字C:

 私人无效connect_print(BluetoothDevice类bluetoothDevicess){
    //一些code
    printData();
    //一些code
}
 

的printData()方法

 私人无效printData(){
    // TODO自动生成方法存根
    字符串str =新的String(这是发送到打印机的文字);
    字符串换行符=\ N的;
    尝试 {
        out.write(str.getBytes(),0,str.getBytes()的长度。);
        Log.i(日志,一线印);
    }赶上(IOException异常E){
        Toast.makeText(BluetoothDemo.this,抓1,Toast.LENGTH_LONG).show();
        e.printStackTrace();
        Log.i(日志,无法写入);
        flagCheck = FALSE;
    }
    尝试 {
        out.write(newline.getBytes(),0,newline.getBytes()的长度。);
    }赶上(IOException异常E){
        Log.i(日志,无法写入新行::);
        e.printStackTrace();
        flagCheck = FALSE;
    }
    flagCheck = TRUE;
}
 

我想改变字体大小字体样式文本被发送到打印机打印。 请帮我实现这一目标。 如果任何人都可以提出任何链接,然后嫌我将AP preciate他/她。 帮助我找到了解决这个问题的

解决方案

你写我的同一主题这样的回答:

  

我已经要求在此线程这里同样的问题,但是很   尚未有任何回应。得到的答案只有一个,但它并没有帮助我。

     

让看它是否帮助你。此处

     

如果你用它做,那么请回答我在我的线程。我会   绝对AP preciate你。

现在我知道如何做到这一点,我不得不运用反向ingeneering,并从市场反编译的.apk文件,使用dex2jar在Linux和明年开罐的Java反编译器......请尝试......当U写这个命令:的

  

out.write(str.getBytes(),0,str.getBytes()的长度。);

U的发送到方法的byte []数组,U可以修改的格式发送另一byte []数组之前发出真正的byte []数组...

默认格式byte []数组是这样的:

  

字节[] arrayOfByte1 = {27,33,0};

,这样你们可以试试这个:

  

 字节[]格式= {27,33,0};

out.write(格式);

out.write(str.getBytes(),0,str.getBytes()的长度。);
 

这些行我会打印ü默认格式的文本,但UFü做到这一点:

 字节[]格式= {27,33,0};

格式[2] =((字节)(0x8中| arrayOfByte1 [2]));

out.write(格式);

out.write(str.getBytes(),0,str.getBytes()的长度。);
 

这将在大胆的风格打印文本...... U可以试试这个oter格式数组:

  //粗体
            格式[2] =((字节)(0x8中| arrayOfByte1 [2]));

            // 高度
            格式[2] =((字节)(为0x10 | arrayOfByte1 [2]));

            // 宽度
            格式[2] =((字节)(0x20的| arrayOfByte1 [2]));

            // 强调
            格式[2] =((字节)(0x80的| arrayOfByte1 [2]));

            // 小
            格式[2] =((字节)(为0x1 | arrayOfByte1 [2]));
 

太ü可以结合起来,那么如果u像小和大胆的文字,取消这些阵列asignements,例如:

 字节[]格式= {27,33,0};

    //粗体
格式[2] =((字节)(0x8中| arrayOfByte1 [2]));
// 高度
格式[2] =((字节)(为0x10 | arrayOfByte1 [2]));
// 宽度
格式[2] =((字节)(0x20的| arrayOfByte1 [2]));
// 强调
//格式[2] =((字节)(0x80的| arrayOfByte1 [2]));
// 小
//格式[2] =((字节)(为0x1 | arrayOfByte1 [2]));
    out.write(格式);
    out.write(str.getBytes(),0,str.getBytes()的长度。);
 

这最后code打印阙最大的文本大小......我希望这能帮助ü...

PDTA:对不起,我的英语

Pdta2:我想打印图像,你知道如何??

I am sending the text to the bluetooth printer via my android cell. Both the printer and my device are connected via the bluetooth. It's Working fine and I am getting the desired text on the paper.

My question is:

The printer is taking the default font size of the text. I want to change the font size of the text which is to be printed.

How can i achieve this??

Here is my code of printing the text after the bloutooth connectivity:

private void connect_print(BluetoothDevice bluetoothDevicess)  {
    // some code
    printData();
    // some code
}

The printData() method

private void printData() {
    // TODO Auto-generated method stub
    String str = new String("This is the text sending to the printer");
    String newline = "\n";
    try {
        out.write(str.getBytes(),0,str.getBytes().length);
        Log.i("Log", "One line printed");
    } catch (IOException e) {
        Toast.makeText(BluetoothDemo.this, "catch 1", Toast.LENGTH_LONG).show();
        e.printStackTrace();
        Log.i("Log", "unable to write ");
        flagCheck = false;
    }
    try {
        out.write(newline.getBytes(),0,newline.getBytes().length);
    } catch (IOException e) {        
        Log.i("Log", "Unable to write the new line::");
        e.printStackTrace();
        flagCheck = false;
    }
    flagCheck = true;
}

I want to change the font size and the font style of the text which is sending to the printer to print. Please help me to achieve this. If anyone can suggest any link then too i will appreciate him/her. Help me to find the solution to this problem

解决方案

Hi you write on my answer of the same theme this:

I have already asked the same question in this thread HERE, but didnt yet got any response. Got only one answer but it was not helped me.

Let see whether it help you. HERE

If you have done with it then please answer me in my thread. I will definitely appreciate you.

Now I konw how to do it, i had to apply reverse ingeneering and decompile an .apk from the market, using dex2jar on linux and next opening jar with java decompiler... Try this... when u write this command:

out.write(str.getBytes(),0,str.getBytes().length);

U are sending to the method an byte[] array, u can modify format sending another byte[] array before send the real byte[] array...

The default format byte[] array is this:

byte[] arrayOfByte1 = { 27, 33, 0 };

So u can try this:

byte[] format = { 27, 33, 0 };

out.write(format);

out.write(str.getBytes(),0,str.getBytes().length);

These lines i'll print u the default format text, but uf u do it:

 byte[] format = { 27, 33, 0 };

format[2] = ((byte)(0x8 | arrayOfByte1[2]));

out.write(format);

out.write(str.getBytes(),0,str.getBytes().length);

It will print text in bold style... U can try this oter format arrays:

            // Bold
            format[2] = ((byte)(0x8 | arrayOfByte1[2]));

            // Height
            format[2] = ((byte)(0x10 | arrayOfByte1[2]));

            // Width
            format[2] = ((byte) (0x20 | arrayOfByte1[2]));

            // Underline
            format[2] = ((byte)(0x80 | arrayOfByte1[2]));

            // Small
            format[2] = ((byte)(0x1 | arrayOfByte1[2]));

Too u can combine it, then if u like little and bold text, uncomment these array asignements, for example:

 byte[] format = { 27, 33, 0 };

    // Bold
format[2] = ((byte)(0x8 | arrayOfByte1[2]));
// Height
format[2] = ((byte)(0x10 | arrayOfByte1[2]));
// Width
format[2] = ((byte) (0x20 | arrayOfByte1[2]));
// Underline
// format[2] = ((byte)(0x80 | arrayOfByte1[2]));
// Small
// format[2] = ((byte)(0x1 | arrayOfByte1[2]));
    out.write(format);
    out.write(str.getBytes(),0,str.getBytes().length);

This last code prints que biggest text size... I hope this can helps u...

Pdta: sorry for my english

Pdta2: I'm trying to print images, u know how??