在android中打印时如何更改字体大小?

在android中打印时如何更改字体大小?,android,printing,bluetooth,Android,Printing,Bluetooth,我正在通过android手机将文本发送到蓝牙打印机。打印机和我的设备都通过蓝牙连接。 它运行良好,我在纸上得到了想要的文本 我的问题是: 打印机正在使用文本的默认字体大小。我想更改要打印的文本的字体大小 我怎样才能做到这一点 以下是我在bloutooth连接后打印文本的代码: private void connect_print(BluetoothDevice bluetoothDevicess) { // some code printData(); // some

我正在通过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(),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;
}
我想更改发送到打印机打印的文本的
字体大小
字体样式
。 请帮助我实现这一目标。 如果有人能推荐任何链接,我也会感谢他/她。
请帮助我找到此问题的解决方案

我不确定,但您可以通过设置字体样式的Java
span
方法来实现这一点

试着这样做:

int start=editbox.getSelectionStart();

int end=editbox.getSelectionEnd();

Spannable span=(Spannable)editbox.getText();

StyleSpan f = new StyleSpan( 
                        Typeface.createFromAsset(getAssets(),
                         "fonts/genbkbasr.ttf"));

span.setSpan(f, start,end, 0);
同样,您可以应用字体样式、字体颜色等

有关更多详细信息,请查看以下内容:


您好,您在我的回答中提到了同样的主题:

我已经在这个帖子里问了同样的问题,但是没有 但没有得到任何回应。我只得到一个答案,但对我没有帮助

让我们看看它是否对你有帮助。这里

如果你已经完成了,请在我的帖子里回答我。我会的 非常感谢你

现在我知道怎么做了,我必须应用反向工程技术,从市场上反编译一个.apk,在linux上使用dex2jar,下一次使用java反编译器打开jar。。。试试这个。。。写入此命令时:

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

如果您正在向方法发送字节[]数组,则可以在发送实际字节[]数组之前修改发送另一个字节[]数组的格式

字节[]数组的默认格式如下:

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

所以你可以试试这个:

这些行我将打印默认格式的文本,但如果您这样做:

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

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

out.write(format);

out.write(str.getBytes(),0,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, 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);
最后一个代码打印最大的文本大小。。。我希望这能帮助你

Pdta:对不起我的英语


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

请建议我在这种情况下应该怎么做?有人能告诉我我在这里要做什么吗?还没有得到任何答案,仍在寻找解决方案。有人能帮我吗?很长时间以来一直被否决,但仍然没有被否决的选民发表任何评论。无论如何,谢谢。抱歉,但这不是我问题的解决方案。无论如何,谢谢你的兴趣。嗨,纳伦德拉,非常感谢你的代码,我已经两天试图按照现有手册格式化一些文本,但没有成功。我有一个与此相关的问题,例如:我按照你的建议激活粗体模式,然后我写一行,然后我回到默认样式,我写另一行。打印机将根据最后发送的参数(默认样式)写入所有内容。您也有这个问题吗?默认样式是:
byte[]format={27,33,0}然后您应该在文本
输出之前将其发送到打印机。写入(格式)
String str=“我的消息”
out.write(str.getBytes(),0,str.getBytes().length)默认fontSize是什么,以及如何增加fontSize?
 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);