ESC/POS 工具类

   public static final byte ESC = 27;// 换码
   public static final byte FS = 28;// 文本分隔符
   public static final byte GS = 29;// 组分隔符
   public static final byte DLE = 16;// 数据连接换码
   public static final byte EOT = 4;// 传输结束
   public static final byte ENQ = 5;// 询问字符
   public static final byte SP = 32;// 空格
   public static final byte HT = 9;// 横向列表
   public static final byte LF = 10;// 打印并换行(水平定位)
   public static final byte CR = 13;// 归位键
   public static final byte FF = 12;// 走纸控制(打印并回到标准模式(在页模式下) )
   public static final byte CAN = 24;// 作废(页模式下取消打印数据 )

   // ------------------------打印机初始化-----------------------------

   /**
    * 打印机初始化
    * 
    * @return
    */
   public static byte[] init_printer() {
      byte[] result = new byte[2];
      result[0] = ESC;
      result[1] = 64;
      return result;
   }

   // ------------------------换行-----------------------------

   /**
    * 换行
    * 
    * @param -lineNum要换几行
   
    */
   public static byte[] nextLine(int lineNum) {
      byte[] result = new byte[lineNum];
      for (int i = 0; i < lineNum; i++) {
         result[i] = LF;
      }

      return result;
   }

   // ------------------------下划线-----------------------------

   /**
    * 绘制下划线(1点宽)
    
    */
   public static byte[] underlineWithOneDotWidthOn() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 45;
      result[2] = 1;
      return result;
   }

   /**
    * 绘制下划线(2点宽)
    * 
    */
   public static byte[] underlineWithTwoDotWidthOn() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 45;
      result[2] = 2;
      return result;
   }

   /**
    * 取消绘制下划线
    */
   public static byte[] underlineOff() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 45;
      result[2] = 0;
      return result;
   }


   // ------------------------加粗-----------------------------

   /**
    * 选择加粗模式
    */
   public static byte[] boldOn() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 69;
      result[2] = 0xF;
      return result;
   }

   /**
    * 取消加粗模式
    */
   public static byte[] boldOff() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 69;
      result[2] = 0;
      return result;
   }

   // ------------------------对齐-----------------------------

   /**
    * 左对齐
    */
   public static byte[] alignLeft() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 97;
      result[2] = 0;
      return result;
   }

   /**
    * 居中对齐
    */
   public static byte[] alignCenter() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 97;
      result[2] = 1;
      return result;
   }

   /**
    * 右对齐
    */
   public static byte[] alignRight() {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 97;
      result[2] = 2;
      return result;
   }

   /**
    * 水平方向向右移动col列
    */
   public static byte[] set_HT_position(byte col) {
      byte[] result = new byte[4];
      result[0] = ESC;
      result[1] = 68;
      result[2] = col;
      result[3] = 0;
      return result;
   }
   // ------------------------字体变大-----------------------------

   /**
    * 字体变大为标准的n倍
    */
   public static byte[] fontSizeSetBig(int num) {
      byte realSize = 0;
      switch (num) {
      case 1:
         realSize = 0;
         break;
      case 2:
         realSize = 17;
         break;
      case 3:
         realSize = 34;
         break;
      case 4:
         realSize = 51;
         break;
      case 5:
         realSize = 68;
         break;
      case 6:
         realSize = 85;
         break;
      case 7:
         realSize = 102;
         break;
      case 8:
         realSize = 119;
         break;
      }
      byte[] result = new byte[3];
      result[0] = 29;
      result[1] = 33;
      result[2] = realSize;
      return result;
   }

   /**
    * 字体取消倍宽倍高
    */
   public static byte[] fontSizeSetSmall(int num) {
      byte[] result = new byte[3];
      result[0] = ESC;
      result[1] = 33;

      return result;
   }




   // ------------------------切纸-----------------------------

   /**
    * 进纸并全部切割
    * 
    */
   public static byte[] feedPaperCutAll() {
      byte[] result = new byte[4];
      result[0] = GS;
      result[1] = 86;
      result[2] = 65;
      result[3] = 0;
      return result;
   }

   /**
    * 进纸并切割(左边留一点不切)
    */
   public static byte[] feedPaperCutPartial() {
      byte[] result = new byte[4];
      result[0] = GS;
      result[1] = 86;
      result[2] = 66;
      result[3] = 0;
      return result;
   }


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值