1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > text 热敏打印机_ESC/POS热敏打印机示例

text 热敏打印机_ESC/POS热敏打印机示例

时间:2022-01-08 02:55:40

相关推荐

text 热敏打印机_ESC/POS热敏打印机示例

使用

package yao.print.wpt630.demo;

import java.io.IOException;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.List;

import javax.microedition.io.Connector;

import javax.microedition.io.StreamConnection;

import yao.print.api.BasePrinter;

import yao.print.api.Connection;

import yao.print.api.PrinterDriver;

import yao.print.api.content.Doucument;

import yao.print.api.content.Printable;

import yao.print.api.content.printable.CutPage;

import yao.print.api.content.printable.Table;

import yao.print.api.exception.PrinterException;

import yao.print.wpt630.demo.connection.BTconnection;

public class PrintTableDemo {

public static final DateFormat date_time_format = new SimpleDateFormat(

"yyyy-MM-dd HH:mm:ss");

public static void main(String[] args) throws InterruptedException,

IOException {

// 建立蓝牙连接(需要bluetooh设备)

// 需要运行ListBluToothDevice,从列出的设备列表中取得蓝牙地址

final StreamConnection c = (StreamConnection) Connector.open(

"btspp://98D331B0723D:1", Connector.READ_WRITE);

final Connection bTconnection = new BTconnection(c);

// 加载驱动

BasePrinter p = null;

try {

p = PrinterDriver.newInstanse("yao.print.wpt630.WTPrinter", "");

} catch (InstantiationException | IllegalAccessException

| ClassNotFoundException e) {

e.printStackTrace();

}

// 设置蓝牙连接

p.setConnection(bTconnection);

// 封装文档内容

Doucument document = new Doucument();

document.addContents(_orderItem());

document.addContent(new CutPage());

// 打印文档内容

try {

p.print(document);

} catch (PrinterException e) {

e.printStackTrace();

}

// 关闭连接

try {

bTconnection.close();

} catch (IOException e) {

e.printStackTrace();

}

}

static List _orderItem() {

List list = new ArrayList<>();

String[] header = new String[] { "商品名称", "数量", "总价" };

int[] cell_width = new int[] { 12, 10, 10 };

Table table = new Table(header, cell_width, new boolean[] { false,

true, true });

table.addOneRow(new String[] { "老人香蕉", "35", "996.00" });

table.addOneRow(new String[] { "靓妹木瓜", "10", "80.10" });

table.addOneRow(new String[] { "热带火龙果", "20", "965.45" });

table.addOneRow(Table.LINE_ROW);

table.addOneRow(new String[] { "合计", "960", "188888" });

list.add(table);

return list;

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。