简体   繁体   English

使用蓝牙打印机问题打印HTML文件

[英]print the HTML files using a bluetooth printer issue

I have used the code for printing as given below 我已经使用了如下打印代码

btn_print.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Thread t = new Thread() {
                public void run() {
                    try {
                        OutputStream os = mBluetoothSocket
                                .getOutputStream();
                        String BILL ="\n"+ oEditText.getText().toString();


                        os.write(BILL.getBytes());

                        Spanned ni = Html.fromHtml("<html><body>You scored <b>192</b> points.</body</html>");
                        System.out.println("*******ni****"+ni);

                        os.write(ni.toString().getBytes());


                        // This is printer specific code you can comment
                        // ==== > Start

                        // Setting height
                        int gs = 29;
                        os.write(intToByteArray(gs));
                        int h = 104;
                        os.write(intToByteArray(h));
                        int n = 162;
                        os.write(intToByteArray(n));

                        // Setting Width
                        int gs_width = 29;
                        os.write(intToByteArray(gs_width));
                        int w = 119;
                        os.write(intToByteArray(w));
                        int n_width = 2;
                        os.write(intToByteArray(n_width));

                        // Print BarCode
                        int gs1 = 29;
                        os.write(intToByteArray(gs1));
                        int k = 107;
                        os.write(intToByteArray(k));
                        int m = 73;
                        os.write(intToByteArray(m));

                        String barCodeVal = "ASDFC028060000005";// "HELLO12345678912345012";
                        System.out.println("Barcode Length : "
                                + barCodeVal.length());
                        int n1 = barCodeVal.length();
                        os.write(intToByteArray(n1));

                        for (int i = 0; i < barCodeVal.length(); i++) {
                            os.write((barCodeVal.charAt(i) + "").getBytes());
                        }
                        // printer specific code you can comment ==== > End
                    } catch (Exception e) {
                        Log.e("Main", "Exe ", e);
                    }
                }
            };
            t.start();
        }
    });

and the i got the output as 和我得到的输出为

You Scored 192 points 您得分192分

the correct output i want is 我想要的正确输出是

You Scored 192 points 您得分192

That is 192 should be bold.Any one help me to solve this issue 那应该是192的粗体。任何人都可以帮助我解决这个问题

Please modify this line: 请修改此行:

Spanned ni = Html.fromHtml("<html><body>You scored <b>192</b> points.</body</html>");

to

Spanned ni = Html.fromHtml("You scored <b>192</b> points.");

I wonder why are you providing <html> , <body> tags inside Html.fromHtml 我不知道为什么要在Html.fromHtml提供<html><body>标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM