在android中打印时如何更改字体大小? [英] How to change the font size while printing in android?

查看:69
本文介绍了在android中打印时如何更改字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过我的 android 手机将文本发送到蓝牙打印机.打印机和我的设备都通过蓝牙连接.它工作正常,我在纸上得到了所需的文本.

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.

我的问题是:

打印机采用文本的默认字体大小.我想更改要打印的文本的字体大小.

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
}

printData() 方法

private void printData() {
    // TODO Auto-generated method stub
    String str = new String("This is the text sending to the printer");
    String newline = "
";
    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.

现在我知道该怎么做了,我不得不应用反向工程并从市场上反编译一个 .apk,在 linux 上使用 dex2jar,然后用 java 反编译器打开下一个 jar ......试试这个......当你写这个命令:

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...

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

The default format byte[] array is this:

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

所以你可以试试这个:

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:对不起我的英语

Pdta: sorry for my english

Pdta2:我正在尝试打印图像,你知道怎么做吗??

这篇关于在android中打印时如何更改字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆