我正在尝试创建一个从Android设备打印到TSP100 Star打印机的收据。我到处搜索,找不到打印光栅化收据的简单示例(因为TSP100只接受栅格)。我通过电子邮件发送了Star,他们发给我以下代码,但我不确定这是否正确,或者如何将其转换为格式化的位图并将其打印出来。
byte[] data;
ArrayList<Byte> list = new ArrayList<Byte>();
Byte[] tempList;
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1d, 0x61, 0x01}));
data = "[If loaded.. Logo1 goes here]\r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1c, 0x70, 0x01, 0x00, '\r', '\n'})); //Stored Logo Printing
data = "Company Name\r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
data = "Street1\r\nCity, ST, ZIPCODE\r\n\r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x1d, 0x61, 0x00})); // Alignment
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x44, 0x02, 0x10, 0x22, 0x00})); //Set horizontal tab
data = "Date: 2/22/2012".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
list.addAll(Arrays.asList(new Byte[]{' ', 0x09, ' '})); //Moving Horizontal Tab
data = "Time: 9:18 PM\r\n------------------------------------------------\r\n\r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x45})); // bold
data = "SALE \r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
list.addAll(Arrays.asList(new Byte[]{0x1b, 0x46})); // bolf off
data = "SKU ".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
list.addAll(Arrays.asList(new Byte[]{0x09}));
// notice that we use a unicode representation because that is how Java expresses these bytes at double byte unicode
// This will TAB to the next horizontal position
data = " Description \u0009 Total\r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
data = "34353434 \u0009 SP500\u0009 100.99\r\n".getBytes();
tempList = new Byte[data.length];
CopyArray(data, tempList);
list.addAll(Arrays.asList(tempList));
ETC ..
现在从ArrayList列表到打印机的位图。一个简单的收据示例将有助于奇迹。我从STAR要求它,但不知道他们需要多长时间才能回来。我认为有人必须这样做。
谢谢。
答案 0 :(得分:4)
你从哪里获得该代码?这实际上是我刚刚创建的一小部分收据。我是Kale Evans,我在Star Micronics工作。
此示例显示如何以原始文本形式将数据发送到打印机。如果您希望将光栅数据发送到打印机,则必须将收据呈现为android位图,然后将其作为参数传递给我相信的PrintImageAsBitmap函数(或类似名称。请查看栅格打印活动)。