Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在android中打印时更改字体大小?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我通过我的 android手机将文本发送到蓝牙打印机.打印机和我的设备都通过蓝牙连接.
它工作正常,我在纸上得到了所需的文字.

我的问题是:

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

我怎么能实现这个?

这是我在bloutooth连接后打印文本的代码

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 = "\n";
    try {
        out.write(str.getBytes(),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(),newline.getBytes().length);
    } catch (IOException E) {        
        Log.i("Log","Unable to write the new line::");
        e.printStackTrace();
        flagcheck = false;
    }
    flagcheck = true;
}

我想更改发送到打印机进行打印的文本的字体大小和字体样式.
请帮助我实现这一目标.
如果有人可以建议任何链接,那么我将欣赏他/她.
我找解决这个问题的方法

解决方法

嗨,你写下我对同一主题的回答:

现在我知道如何做到这一点,我不得不应用逆向生成并从市场反编译.apk,在linux上使用dex2jar,然后用java反编译器打开jar …试试这个…当你写这个命令:

你正在向方法发送一个byte []数组,你可以修改格式发送另一个byte []数组,然后发送真实的byte []数组…

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

所以你可以试试这个:

byte[] format = { 27,0 };

out.write(format);

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

这些行我将打印认格式文本,但是你这样做:

byte[] format = { 27,0 };

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

out.write(format);

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

它将以粗体样式打印文本…你可以试试这个oter格式数组:

// 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]));

太多你可以把它组合起来,那么如果你喜欢小而粗体的文本,请取消注释这些数组对象,例如:

byte[] format = { 27,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(),str.getBytes().length);

最后一个代码打印出最大的文本大小…我希望这可以帮助你…

Pdta:对不起我的英语

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

大佬总结

以上是大佬教程为你收集整理的如何在android中打印时更改字体大小?全部内容,希望文章能够帮你解决如何在android中打印时更改字体大小?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。