它工作正常,我在纸上得到了所需的文字.
我的问题是:
打印机采用文本的默认字体大小.我想更改要打印的文本的字体大小.
我怎么能实现这个?
这是我在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; }
我想更改发送到打印机进行打印的文本的字体大小和字体样式.
请帮助我实现这一目标.
如果有人可以建议任何链接,那么我将欣赏他/她.
帮我找到解决这个问题的方法
解决方法
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(),str.getBytes().length);
你正在向方法发送一个byte []数组,你可以修改格式发送另一个byte []数组,然后发送真实的byte []数组…
默认格式byte []数组是这样的:
byte[] arrayOfByte1 = { 27,33,0 };
所以你可以试试这个:
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:我正在尝试打印图像,你知道怎么做?