2

我正在尝试创建一张收据,该收据将从 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 提出了要求,但不确定他们需要多长时间才能回来。我想外面一定有人这样做了。

谢谢你。

4

1 回答 1

4

你从哪里得到那个代码?这实际上是我不久前创建的收据的一小部分。我是 Kale Evans,在 Star Micronics 工作。

此示例向您展示如何将数据作为原始文本发送到打印机。如果您希望将光栅数据发送到打印机,则必须将收据呈现为 android 位图,然后在我相信的 PrintImageAsBitmap 函数中将其作为参数传递(或类似名称。看看 rasterprinting 活动)。

于 2012-04-26T03:31:42.630 回答