简体   繁体   中英

Creating a raster receipt on Star TSP100 printer in android

I'm trying to create a receipt that will print from an android device to a TSP100 Star printer. I have searched everywhere and can not find a simple example of printing a rasterized receipt (since TSP100 only accepts raster). I emailed Star and they sent me the following code, but I'm not sure this is correct, or how to take this and convert it to a formatted bitmap and print it.

    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..

Now to get from the ArrayList list to a bitmap to the printer. A simple receipt example would help wonders. I've requested it from STAR, but not sure how long they will take to get back. I figure someone out there must have done this.

Thank you.

Where did you get that code? That is actually a small snippet of a receipt of mine I created a while ago. I am Kale Evans, and I work at Star Micronics.

This example shows you how to send data to the printer as raw text. If you wish to send raster data to the printer, you have to render your receipt as an android bitmap, and then pass it as a parameter in the PrintImageAsBitmap function I believe(or a similar name. Take a look at the rasterprinting activity).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM