Question

I am printing using the Windows Compact Framework to a Zebra belt printer using the OpenNetCF serial port class and CPCL. The printed label is pretty much as it should be, but the barcode value is not printing beneath the barcode as it should.

I create an ArrayList of commands to be sent the printer and then pass them one at a time to the serial port. If the controls that supply the values are empty, I use some dummy data, like so:

    private void btnPrint_Click(object sender, System.EventArgs e)
    {
        string listPrice = txtList.Text;
        if (listPrice.Trim() == string.Empty)
        {
            listPrice = "3.14";
        }
        string description = txtDesc.Text;
        if (description.Trim() == string.Empty)
        {
            description = "The Life of Pi";
        }
        string barcode = txtUPC.Text;
        if (barcode.Trim() == string.Empty)
        {
            barcode = "01701013992";
        }

        ArrayList arrList = new ArrayList();

        arrList.Add("! 0 200 200 120 1\r\n"); // replace 120 with label height if different than 1.25"/120 pixels (at 96 pixels per inch)
        arrList.Add("RIGHT\r\n");
        arrList.Add(string.Format("TEXT 0 5 0 0 {0}\r\n", listPrice)); 
        arrList.Add("LEFT\r\n");
        arrList.Add(string.Format("TEXT 0 0 0 52 {0}\r\n", description)); 
        arrList.Add("CENTER\r\n");
        arrList.Add("BARCODE-TEXT 0 0 5\r\n");
        arrList.Add(string.Format("BARCODE 128 1 1 50 0 77 {0}\r\n", barcode)); 
        arrList.Add("FORM\r\n");
        arrList.Add("PRINT\r\n");

        PrintUtils pu = new PrintUtils();
        pu.PrintLabel(arrList);
    }

    public void PrintLabel(ArrayList linesToSend)
    {
        using (SerialPort serialPort = new SerialPort())
        {
            serialPort.BaudRate = 19200;
            serialPort.Handshake = Handshake.XOnXOff;
            serialPort.DataBits = 8;
            serialPort.Parity = Parity.None;
            serialPort.StopBits = StopBits.One;
            serialPort.PortName = "COM1:";
            serialPort.Open();

            Thread.Sleep(500); //this may not even be necessary and, if so, a different value may be better

                        foreach (string line in linesToSend)
            {
                serialPort.Write(line);
            }

            serialPort.Close();
        }
    }

...the problem is that the label (when I allow the dummy data to print) should be:

        3.14
The Life of Pi
    <barcode here>
    01701013992

...and here's what is really printing:

        3.14
The Life of Pi
    <barcode here>
    [blank]

So the problem is that the barcode as text ("01701013992") is not printing beneath the barcode.

Does anybody know why this is occurring even though I've got a BARCODE-TEXT command in there, and how to rectify it?

UPDATE

A key piece of info came my way, namely that the label height (in my case) should be 254, not 120 (for my 1.25" in height label, I was calculating based on 96 pixels == 1 inch, but in actuality this particular printer is 203 dpi, so 1.25 X == 254 (more precisely 253.75, but 254 is close enough).

So the code has changed to this:

// Command args (first line, prepended with a "!": horizontal (X) pos, resolution, resolution, label height, copies
// TEXT args are: fontNumber, fontSizeIdentifier, horizontal (X) pos, vertical (Y) pos
// BARCODE args are: barcodeType, unitWidthOfTheNarrowBar, ratioOfTheWideBarToTheNarrowBar, unitHeightOfTheBarCode, 
//      horizontal (X) pos, vertical (Y) pos, barcodeValue
// BARCODE-TEXT args are: fontNumber, fontSizeIdentifier, space between barcode and -text
// 1 inch = 203 dots (Zebra QL220 is a 203 dpi printer); font 4,3 == 90 pixels; font 2,0 == 12 pixels
arrList.Add("! 0 200 200 254 1\r\n"); // 203 dpi X 1.25 = 254
arrList.Add("RIGHT\r\n");
arrList.Add(string.Format("TEXT 4 3 0 0 {0}\r\n", listPrice)); 
arrList.Add("LEFT\r\n");
arrList.Add(string.Format("TEXT 2 0 0 100 {0}\r\n", description)); 
arrList.Add("BARCODE-TEXT 2 0 5\r\n"); 
arrList.Add("CENTER\r\n");
arrList.Add(string.Format("BARCODE 128 1 1 50 0 120 {0}\r\n", barcode)); 
arrList.Add("FORM\r\n");
arrList.Add("PRINT\r\n");

...but I'm STILL not seeing the description label - except for a lonely "P" below the "3" and the "." in the price.

Are my calculations wrong, or what?

Here's what I'm thinking I have:

Label is 254 dots/1.25" high.

First line starts at YPos 0 and prints "3.14" in a 90 pixel font, right-aligned. That prints fine.

Second line starts at YPos 100 (10 dots below the 90-dot first line), left-aligned. All I see is the aforementioned "P" in what seems to be the right size.

Third line is the barcode, at YPos (120), centered; prints fine

Fourth/final line is the barcode as text beneath the barcode proper, centered; prints fine.

NOTE: I can't put a bounty on this yet, but anybody who solves it I will award 100 points as soon as I'm able (in two days, I reckon).

Was it helpful?

Solution

It turns out that the problem was that I was using font # 2 in order to get a font size of 12 (it is the only font that provides that size). The problem with font # 2 is that it is "OCR-A" and as such only prints certain characters. In the string I was passing as a test ("The Life of Pi", to go along with the list price of 3.14), the only character it recognizes in that string is P. So that's why it's the only one I saw.

I had to increase my font size to the next available, namely 24, using font #5 (Manhattan) or 7 (Warwick).

"mk" from zebra provided me with this information ("The OCR font is a special font that doesn’t include all characters that you are trying to print.").

If you look at Appendix D in the CPCL programming manual, it does show font #2 as being "OCR-A," but it didn't dawn on me that that meant it's character set precluded most alpha characters. Even if that's obvious to some, it seems to me that should be emphasized in the manual: When printing text, don't use font #2!

Note: Font #6 (MICR) is also to be avoided for text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top