package com.icod.yk_printer_test;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;

import com.szsicod.print.escpos.PrinterAPI;
import com.szsicod.print.log.Logger;
import com.szsicod.print.utils.BitmapUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

/**
 * Created by crf on 2018/9/3.
 */
public class BillActivity extends Activity {
    private Button mBtnPrintWithSpace;
    private Button mBtnPrintWithRe;
    private Button mBtnPrintWithAb;
    private static Thread mRunThread;
    private RadioGroup mRbtype;
    private boolean is58;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bill_activity);

        mRbtype = (RadioGroup) findViewById(R.id.rg_type);
       findViewById(R.id.btn_print_with_test).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        PrinterAPI.getInstance().setAlignMode(1);
                        InputStream open = getAssets().open("2barcode.gif");
                        Bitmap bitmap = BitmapFactory.decodeStream(open);
                        InputStream open1 = getAssets().open("支付宝 (1).bmp");
                        Bitmap bitmap1 = BitmapFactory.decodeStream(open1);
                        InputStream open2 = getAssets().open("支付宝 (2).bmp");
                        Bitmap bitmap2 = BitmapFactory.decodeStream(open2);
                        InputStream open3 = getAssets().open("3fresh_test.png");
                        Bitmap bitmap3 = BitmapFactory.decodeStream(open3);
                        bitmap3=BitmapUtils.reSizeByWidth(bitmap3,576);
                        //  PrinterAPI.getInstance().printRasterBitmap(bitmap,false,10000);
                        PrinterAPI.getInstance().printString("收银员演示打印样单\n");
                        PrinterAPI.getInstance().printRasterBitmap(bitmap,true,10000,false,false);
                        ;

                        printBillWithTab();



            /* PrinterAPI.getInstance().printString("-----------------------------------------------\n" +
                    "收银员：自助          收银号：Z33\n" +
                    "消费时间：2019-01-03 14:54:39\n" +
                    "-----------------------------------------------\n" +
                    "品名\t\t\t数量\t\t金额(元)\n" +
                    "-----------------------------------------------\n" +
                    "三得利乌龙茶\t\t1\t\t4.5\n" +
                    "统一绿茶\t\t1\t\t3.5\n" +
                    "雪碧零卡\t\t1\t\t3.0\n" +
                    "可口可乐零度\t\t1\t\t3.0\n" +
                    "-----------------------------------------------\n" +
                    "累计金额：\t\t\t\t40.80\n" +
                    "实际收款：\t\t\t\t0.00\n" +
                    "此单消费仅为功能演示，非真实交易\n" +
                    "地址：荣华南路2号大族广场购物中心1F\n" +
                    "电话：4006068768\n" +
                    "带*号的商品是已享受满减优惠的商品\n" +
                    "此小票为购物凭证，请妥善保管。如需开具发票请在\n" +
                    "购物90天内，通过APP进入“发票中心”开具电子发票\n" +
                    "谢谢光临！\n" +
                    "欢迎您下载我们的APP，新用户注册即获取80元新人大\n" +
                    "礼包\n" +
                    "合并开具发票分类码：C3840F5906****2FDF51E456\n");*/

                        PrinterAPI.getInstance().printRasterBitmap(bitmap2,true,10000,false,false);
                        PrinterAPI.getInstance().printFeed();
                        PrinterAPI.getInstance().setAlignMode(0);
                        PrinterAPI.getInstance().printRasterBitmap(bitmap1,true,10000,false,false);
                        PrinterAPI.getInstance().printFeed();
                        PrinterAPI.getInstance().printRasterBitmap(bitmap3,true,10000,false,false);
                        PrinterAPI.getInstance().printFeed();
                        PrinterAPI.getInstance().printQRCode("15555444",6,false);
                        PrinterAPI.getInstance().cutPaper(66,0);
                        if (!bitmap.isRecycled())bitmap.recycle();
                        if (!bitmap1.isRecycled())bitmap1.recycle();
                        if (!bitmap2.isRecycled())bitmap2.recycle();
                        if (!bitmap3.isRecycled())bitmap3.recycle();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }).start();





    }
});
        mBtnPrintWithSpace = (Button) findViewById(R.id.btn_print_with_space);
        mBtnPrintWithRe = (Button) findViewById(R.id.btn_print_with_re);
        mBtnPrintWithAb = (Button) findViewById(R.id.btn_print_with_ab);
        mRbtype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.cb_print_58) {
                    is58 = true;
                } else {
                    is58 = false;
                }
                Logger.i("纸宽58", is58);

            }
        });
        mRbtype.check(R.id.cb_print_58);

        mBtnPrintWithSpace.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mRunThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        printBillWithTab();
                        PrinterAPI.getInstance().cutPaper(66,0);

                    }
                });
                mRunThread.start();


            }
        });
        mBtnPrintWithRe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mRunThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        PrinterAPI instance = PrinterAPI.getInstance();
                        //居中
                        instance.setAlignMode(1);
                        //字体放大
                        instance.setCharSize(1, 1);

                        try {
                            instance.printString("客户联");
                            instance.printFeed();
                            //恢复默认字体大小
                            instance.setCharSize(0, 0);
                            instance.printString("如需发票,请当日凭客户联开具");
                            instance.printFeed();//换行
                            instance.printString("深圳研科数码有限公司");
                            instance.printFeed();
                            instance.printString("电话:13389804314");
                            instance.printFeed();

                            if (is58) {
                                instance.setAlignMode(0);//左对齐
                                instance.printString("账单编号 : 60743");
                                //超过不管用或者固件不支持 相对于当前的打印位置...一个空格==12 一个汉字两个空格
                                instance.setRelativePosition(36,0);
                                instance.printString("重印");
                                instance.printFeed();
                                instance.setAlignMode(0);//左对齐
                                instance.printString("日期 : 2018-11-11");
                                instance.setRelativePosition(12,0);
                                instance.printString("18:28");
                                instance.printFeed();
                                instance.printString("收银员 : 五五开");
                                instance.setRelativePosition(12,0);
                                instance.printString("台号:32");
                                instance.printFeed();
                                //需要32个
                                instance.printString
                                        ("--------------------------------");

                                instance.printAndFeedPaper(10);//进纸
                                instance.printString("菜品名称");
                                instance.setRelativePosition(144,0);

                                instance.printString("数量");
                                instance.setRelativePosition(48,0);
                                instance.printString("金额");
                                instance.printAndFeedPaper(10);//进纸
                                instance.printString
                                        ("--------------------------------");
                                instance.printFeed();
                                instance.printString("稻小厨免茶芥");
                                instance.setRelativePosition(132,0);
                                instance.printString("1");
                                instance.setRelativePosition(60,0);
                                instance.printString("0.0");

                                instance.printString("原只鲍鱼烧卖");
                                instance.setRelativePosition(132,0);
                                instance.printString("1");
                                instance.setRelativePosition(48,0);
                                instance.printString("13.0");

                                instance.printString("黑丸");
                                instance.setRelativePosition(228,0);
                                instance.printString("1");
                                instance.setRelativePosition(60,0);
                                instance.printString("8.0");

                                instance.printString("红米脆虾肠");
                                instance.setRelativePosition(156,0);
                                instance.printString("1");
                                instance.setRelativePosition(48,0);
                                instance.printString("23.0");
                                instance.printString("猫王榴莲酥");
                                instance.setRelativePosition(156,0);
                                instance.printString("1");
                                instance.setRelativePosition(48,0);
                                instance.printString("21.0");

                                instance.printString("干笋流沙包");
                                instance.setRelativePosition(156,0);
                                instance.printString("1");
                                instance.setRelativePosition(48,0);
                                instance.printString("16.0");


                                instance.setAlignMode(2);//zuo对齐
                                instance.printString("============");
                                instance.printFeed();
                                instance.setAlignMode(0);
                                instance.printString("(3)点心优惠5折");
                                instance.setRelativePosition(168,0);
                                instance.printString("40.0");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("点菜总额:");
                                instance.setRelativePosition(228,0);
                                instance.printString("81.5");
                                instance.printString("折扣总计:");
                                instance.setRelativePosition(216,0);
                                instance.printString("-40.0");
                                instance.printString("-------------");
                                instance.printFeed();
                                instance.setCharSize(1, 1);

                                instance.printString("总收额:RMB:");
                                //打印人民币符号
                                instance.setInterCharSet(8);
                                instance.sendOrder(new byte[]{(byte) 0x5c});
                                instance.setInterCharSet(0);//恢复默认
                                instance.printString("41.5");
                                instance.printFeed();
                                instance.setCharSize(0, 0);
                                instance.printString("--------------");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("支付宝");
                                instance.setRelativePosition(60,0);
                                instance.printString("41.5");
                                instance.setRelativePosition(66,0);
                                instance.printString("00");
                                instance.setRelativePosition(66,0);
                                instance.printString("41.5");
                                instance.printString("找零");
                                instance.setRelativePosition(56,1);
                                instance.printString("00");
                                instance.printFeed();
                                instance.printString
                                        ("-------------------------------");
                                instance.printFeed();
                                instance.printString("地址:中国深圳");
                                instance.printFeed();
                                instance.cutPaper(66,0);

                            } else {
                                instance.setAlignMode(0);//左对齐
                                instance.printString("账单编号 : 60743");
                                //超过不管用或者固件不支持 相对于当前的打印位置...一个空格==12 一个汉字两个空格
                                instance.setRelativePosition(72,0);
                                instance.printString("重印");
                                instance.printFeed();
                                instance.setAlignMode(0);//左对齐
                                instance.printString("日期 : 2018-11-11");
                                instance.setRelativePosition(24,0);
                                instance.printString("18:28");
                                instance.printFeed();
                                instance.printString("收银员 : 五五开");
                                instance.setRelativePosition(24,0);
                                instance.printString("台号:32");
                                instance.printFeed();
                                //需要48个
                                instance.printString
                                        ("------------------------------------------------");

                                instance.printAndFeedPaper(10);//进纸
                                instance.printString("菜品名称");
                                instance.setRelativePosition(56,1);

                                instance.printString("数量");
                                instance.setRelativePosition(72,0);
                                instance.printString("金额");
                                instance.printAndFeedPaper(10);//进纸
                                instance.printString
                                        ("------------------------------------------------");
                                instance.printFeed();
                                instance.printString("稻小厨免茶芥");
                                instance.setRelativePosition(44,1);
                                instance.printString("1");
                                instance.setRelativePosition(84,0);
                                instance.printString("0.0");

                                instance.printString("原只鲍鱼烧卖");
                                instance.setRelativePosition(44,1);
                                instance.printString("1");
                                instance.setRelativePosition(72,0);
                                instance.printString("13.0");

                                instance.printString("黑丸");
                                instance.setRelativePosition(140,1);
                                instance.printString("1");
                                instance.setRelativePosition(84,0);
                                instance.printString("8.0");

                                instance.printString("红米脆虾肠");
                                instance.setRelativePosition(68,1);
                                instance.printString("1");
                                instance.setRelativePosition(72,0);
                                instance.printString("23.0");
                                instance.printString("猫王榴莲酥");
                                instance.setRelativePosition(68,1);
                                instance.printString("1");
                                instance.setRelativePosition(72,0);
                                instance.printString("21.0");

                                instance.printString("干笋流沙包");
                                instance.setRelativePosition(68, 1);
                                instance.printString("1");
                                instance.setRelativePosition(72, 0);
                                instance.printString("16.0");


                                instance.setAlignMode(2);//走对齐
                                instance.printString("========================");
                                instance.printFeed();
                                instance.setAlignMode(0);
                                instance.printString("(3)点心优惠5折");
                                instance.setRelativePosition(104,1);
                                instance.printString("40.0");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("点菜总额:");
                                instance.setRelativePosition(164,1);
                                instance.printString("81.5");
                                instance.printString("折扣总计:");
                                instance.setRelativePosition(152,1);
                                instance.printString("-40.0");
                                instance.printString("--------------------------");
                                instance.printFeed();
                                instance.setCharSize(1, 1);

                                instance.printString("总收额: RMB: ");
                                //打印人民币符号
                                instance.setInterCharSet(8);
                                instance.sendOrder(new byte[]{(byte) 0x5c});
                                instance.setInterCharSet(0);//恢复默认
                                instance.printString("41.5");
                                instance.printFeed();
                                instance.setCharSize(0, 0);
                                instance.printString("--------------------------");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("支付宝");
                                instance.setRelativePosition(120,0);
                                instance.printString("41.5");
                                instance.setRelativePosition(132,0);
                                instance.printString("00");
                                instance.setRelativePosition(132,0);
                                instance.printString("41.5");
                                instance.printString("找零");
                                instance.setRelativePosition(248,1);
                                instance.printString("00");
                                instance.printFeed();
                                instance.printString
                                        ("------------------------------------------------");
                                instance.printFeed();
                                instance.printString("地址:中国深圳");
                                instance.printFeed();
                                instance.cutPaper(66,0);
                            }
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }

                    }
                });
                mRunThread.start();
            }
        });
        mBtnPrintWithAb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mRunThread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        PrinterAPI instance = PrinterAPI.getInstance();
                        //居中
                        instance.setAlignMode(1);
                        //字体放大
                        instance.setCharSize(1, 1);

                        try {
                            instance.printString("客户联");
                            instance.printFeed();
                            //恢复默认字体大小
                            instance.setCharSize(0, 0);
                            instance.printString("如需发票,请当日凭客户联开具");
                            instance.printFeed();//换行
                            instance.printString("深圳研科数码有限公司");
                            instance.printFeed();
                            instance.printString("电话:13389804314");
                            instance.printFeed();

                            if (is58) {
                                instance.setAlignMode(0);//左对齐
                                instance.printString("账单编号 : 60743");
                                //超过不管用或者固件不支持 相对于一行开始的打印位置,一个空格==12
                                instance.setAbsolutePosition(228,0);
                                instance.printString("重印");
                                instance.printFeed();
                                instance.setAlignMode(0);//左对齐
                                instance.printString("日期 : 2018-11-11");
                                instance.setAbsolutePosition(216,0);
                                instance.printString("18:28");
                                instance.printFeed();
                                instance.printString("收银员 : 五五开");
                                instance.setAbsolutePosition(156,0);
                                instance.printString("台号:32");
                                instance.printFeed();
                                //需要32个
                                instance.printString("--------------------------------");

                                instance.printAndFeedPaper(10);//进纸
                                instance.printString("菜品名称");
                                instance.setAbsolutePosition(252,0);

                                instance.printString("数量");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("金额");
                                instance.printAndFeedPaper(10);//进纸
                                //需要32个
                                instance.printString("--------------------------------");
                                instance.printFeed();
                                instance.printString("稻小厨免茶芥");
                                instance.setAbsolutePosition(20,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(90,1);
                                instance.printString("0.0");

                                instance.printString("原只鲍鱼烧卖");
                                instance.setAbsolutePosition(20,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("13.0");

                                instance.printString("黑丸");
                                instance.setAbsolutePosition(20,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(90,1);
                                instance.printString("8.0");

                                instance.printString("红米脆虾肠");
                                instance.setAbsolutePosition(20,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("23.0");
                                instance.printString("猫王榴莲酥");
                                instance.setAbsolutePosition(20,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("21.0");

                                instance.printString("干笋流沙包");
                                instance.setAbsolutePosition(20,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("16.0");


                                instance.setAlignMode(2);//走对齐
                                instance.printString("============");
                                instance.printFeed();
                                instance.setAlignMode(0);
                                instance.printString("(3)点心优惠5折");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("40.0");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("点菜总额:");
                                instance.setAbsolutePosition(78,1);
                                instance.printString("81.5");
                                instance.printString("折扣总计:");
                                instance.setAbsolutePosition(66,1);
                                instance.printString("-40.0");
                                instance.printString("--------------");
                                instance.printFeed();
                                instance.setCharSize(1, 1);

                                instance.printString("总收额:RMB:");
                                //打印人民币符号
                                instance.setInterCharSet(8);
                                instance.sendOrder(new byte[]{(byte) 0x5c});
                                instance.setInterCharSet(0);//恢复默认
                                instance.printString("41.5");
                                instance.printFeed();
                                instance.setCharSize(0, 0);
                                instance.printString("---------------");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("支付宝");
                                instance.setRelativePosition(60,0);
                                instance.printString("41.5");
                                instance.setRelativePosition(72,0);
                                instance.printString("00");
                                instance.setRelativePosition(60,0);
                                instance.printString("41.5");
                                instance.printString("找零");
                                instance.setAbsolutePosition(102,1);
                                instance.printString("00");
                                instance.printFeed();
                                instance.printString
                                        ("-------------------------------");
                                instance.printFeed();
                                instance.printString("地址:中国深圳");
                                instance.printFeed();
                                instance.cutPaper(66,0);

                            } else {
                                instance.setAlignMode(0);//左对齐
                                instance.printString("账单编号 : 60743");
                                //超过不管用或者固件不支持 相对于一行开始的打印位置,一个空格==12
                                instance.setAbsolutePosition(8,1);
                                instance.printString("重印");
                                instance.printFeed();
                                instance.setAlignMode(0);//左对齐
                                instance.printString("日期 : 2018-11-11");
                                instance.setAbsolutePosition(228,0);
                                instance.printString("18:28");
                                instance.printFeed();
                                instance.printString("收银员 : 五五开");
                                instance.setAbsolutePosition(214,0);
                                instance.printString("台号:32");
                                instance.printFeed();
                                //需要48个
                                instance.printString("------------------------------------------------");

                                instance.printAndFeedPaper(10);//进纸
                                instance.printString("菜品名称");
                                instance.setAbsolutePosition(156,1);

                                instance.printString("数量");
                                instance.setAbsolutePosition(12,2);
                                instance.printString("金额");
                                instance.printAndFeedPaper(10);//进纸
                                instance.printString
                                        ("------------------------------------------------");
                                instance.printFeed();
                                instance.printString("稻小厨免茶芥");
                                instance.setAbsolutePosition(190,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(24,2);
                                instance.printString("0.0");

                                instance.printString("原只鲍鱼烧卖");
                                instance.setAbsolutePosition(190,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(12,2);
                                instance.printString("13.0");

                                instance.printString("黑丸");
                                instance.setAbsolutePosition(190,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(24,2);
                                instance.printString("8.0");

                                instance.printString("红米脆虾肠");
                                instance.setAbsolutePosition(190,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(12,2);
                                instance.printString("23.0");
                                instance.printString("猫王榴莲酥");
                                instance.setAbsolutePosition(190,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(12,2);
                                instance.printString("21.0");

                                instance.printString("干笋流沙包");
                                instance.setAbsolutePosition(190,1);
                                instance.printString("1");
                                instance.setAbsolutePosition(12,2);
                                instance.printString("16.0");


                                instance.setAlignMode(2);//走对齐
                                instance.printString("========================");
                                instance.printFeed();
                                instance.setAlignMode(0);
                                instance.printString("(3)点心优惠5折");

                                instance.setAbsolutePosition(12,2);
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("点菜总额:");
                                instance.setAbsolutePosition(12,2);
                                instance.printString("81.5");
                                instance.printString("折扣总计:");
                                instance.setAbsolutePosition(0,2);
                                instance.printString("-40.0");
                                instance.printString("--------------------------");
                                instance.printFeed();
                                instance.setCharSize(1, 1);

                                instance.printString("总收额: RMB: ");
                                //打印人民币符号
                                instance.setInterCharSet(8);
                                instance.sendOrder(new byte[]{(byte) 0x5c});
                                instance.setInterCharSet(0);//恢复默认
                                instance.printString("41.5");
                                instance.printFeed();
                                instance.setCharSize(0, 0);
                                instance.printString("--------------------------");
                                instance.printFeed();
                                instance.printFeed();
                                instance.printString("支付宝");
                                instance.setRelativePosition(120,0);
                                instance.printString("41.5");
                                instance.setRelativePosition(132,0);
                                instance.printString("00");
                                instance.setRelativePosition(132,0);
                                instance.printString("41.5");
                                instance.printString("找零");
                                instance.setRelativePosition(248,1);
                                instance.printString("00");
                                instance.printFeed();
                                instance.printString
                                        ("------------------------------------------------");
                                instance.printFeed();
                                instance.printString("地址:中国深圳");
                                instance.printFeed();
                                instance.cutPaper(66,0);
                            }
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }

                    }
                });
                mRunThread.start();
            }
        });

    }

    private void printBillWithTab() {
        PrinterAPI instance = PrinterAPI.getInstance();
        //居中
        instance.setAlignMode(1);
        //字体放大
        instance.setCharSize(1, 1);

        try {
            instance.printString("客户联");
            instance.printFeed();
            //恢复默认字体大小
            instance.setCharSize(0, 0);
            instance.printString("如需发票,请当日凭客户联开具");
            instance.printFeed();//换行
            instance.printString("深圳研科数码有限公司");
            instance.printFeed();
            instance.printString("电话:13389804314");
            instance.printFeed();

            if (is58) {
                instance.setAlignMode(0);//左对齐
                instance.printString("账单编号 : 60743   ");

                instance.printString("重印");
                instance.printFeed();
                instance.setAlignMode(0);//左对齐
                instance.printString("日期 : 2018-11-11 18:28");
                instance.printFeed();
                instance.printString("收银员 : 五五开 台号:32");
                instance.printFeed();
                //需要32个
                instance.printString
                        ("--------------------------------");

                instance.printAndFeedPaper(10);//进纸
                instance.printString("菜品名称             数量   金额");
                instance.printAndFeedPaper(10);//进纸
                instance.printString
                        ("--------------------------------");
                instance.printFeed();
                instance.printString("稻小厨免茶芥            1    0.0");
                instance.printString("原只鲍鱼烧卖            1   13.0");
                instance.printString("黑丸                    1    8.0");
                instance.printString("红米脆虾肠              1   23.0");
                instance.printString("猫王榴莲酥              1   21.0");
                instance.printString("干笋流沙包              1   16.0");
                instance.setAlignMode(2);//走对齐
                instance.printString("============");
                instance.printFeed();
                instance.setAlignMode(0);
                instance.printString("(3)点心优惠5折              40.0");

                instance.printFeed();
                instance.printFeed();
                instance.printString("点菜总额:                   81.5");
                instance.printString("折扣总计:                  -40.0");
                instance.printString("-------------");
                instance.printFeed();
                instance.setCharSize(1, 1);

                instance.printString("总收额:RMB:");
                //打印人民币符号
                instance.setInterCharSet(8);
                instance.sendOrder(new byte[]{(byte) 0x5c});
                instance.setInterCharSet(0);//恢复默认
                instance.printString("41.5");
                instance.printFeed();
                instance.setCharSize(0, 0);
                instance.printString("--------------------------");
                instance.printFeed();
                instance.printFeed();
                instance.printString("支付宝     41.5     00      41.5");
                instance.printString("找零                          00");
                instance.printFeed();
                instance.printString
                        ("--------------------------------");
                instance.printFeed();
                instance.printString("地址:中国深圳");
                instance.printFeed();


            } else {
                instance.setAlignMode(0);//左对齐
                instance.printString("账单编号 : 60743      ");

                instance.printString("重印");
                instance.printFeed();
                instance.setAlignMode(0);//左对齐
                instance.printString("日期 : 2018-11-11  18:28");
                instance.printFeed();
                instance.printString("收银员 : 五五开  台号:32");
                instance.printFeed();
                //需要48个
                instance.printString
                        ("------------------------------------------------");

                instance.printAndFeedPaper(10);//进纸
                instance.printString("菜品名称                          数量      金额");
                instance.printAndFeedPaper(10);//进纸
                instance.printString
                        ("------------------------------------------------");
                instance.printFeed();
                instance.printString("稻小厨免茶芥                         1       0.0");
                instance.printString("原只鲍鱼烧卖                         1      13.0");
                instance.printString("黑丸                                 1      " +
                        " " +
                        "8.0");
                instance.printString("红米脆虾肠                           1      "+
                        "23.0");
                instance.printString("猫王榴莲酥                           1      " +
                        "21.0");
                instance.printString("干笋流沙包                           1      " +
                        "16.0");
                instance.setAlignMode(2);//走对齐
                instance.printString("========================");
                instance.printFeed();
                instance.setAlignMode(0);
                instance.printString("(3)点心优惠5折                              " +
                        "40.0");

                instance.printFeed();
                instance.printFeed();
                instance.printString("点菜总额:                                   " +
                        "81.5");
                instance.printString("折扣总计:                                  " +
                        "-40.0");
                instance.printString("--------------------------");
                instance.printFeed();
                instance.setCharSize(1, 1);

                instance.printString("总收额: RMB: ");
                //打印人民币符号
                instance.setInterCharSet(8);
                instance.sendOrder(new byte[]{(byte) 0x5c});
                instance.setInterCharSet(0);//恢复默认
                instance.printString("41.5");
                instance.printFeed();
                instance.setCharSize(0, 0);
                instance.printString("--------------------------");
                instance.printFeed();
                instance.printFeed();
                instance.printString("支付宝          41.5           00           " +
                        "41.5");
                instance.printString("找零                                        " +
                        "  " +
                        "00");
                instance.printFeed();
                instance.printString
                        ("------------------------------------------------");
                instance.printFeed();
                instance.printString("地址:中国深圳");
                instance.printFeed();

            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
