Make text in ZPL label bold or underlined?
Asked Answered
L

3

19

Due to a new EU law every food packaging label has to outline possible allergy-causing ingredients by either styling them bold or underlined in the ingredients list.

Currently I'm printing my labels via ZPL to zebra printers. I checked the ZPL manuel 1 & 2 and didn't find way how to print something in bold or underlined. Is there any way to do this?

Example: "Ingredients: water, sugar, milk, cheese, chocolate"

SHOULD BE NOW: "Ingredients: water, sugar, milk, cheese, chocolate"

My current label code for the ingredients is:

^CF0,15
^FO13,245
^FB530,2,,L,
^FH^FD__VAR_INGREDIENTS__
^FS

Thank you very much for your help,

Stefan

Lardaceous answered 9/12, 2014 at 10:54 Comment(0)
O
33

To underline - use a monospaced font like AA,AC,AD,AF or AG

Use

^FO350,50^AGR^FDwhatever,milk,butter,salt^FS
^FO340,50^AGR^FD         ____ ______^FS

where the underline here is under milk and butter, you can adjust the offset by trimming the FO's X and Y positions by a few dots (10 X here)

On further investigation, I found

To bold

Use an old dot-matrix-printer trick. Still using fixed-pitch font, reprint the text but replacing the non-bold characters with spaces and adjust the X-position by 1 or 2 dots, reprint again with the Y-position adjusted by 1 o2 2 dots.

^FO350,50^AGR^FDwhatever,milk,butter,salt^FS
^FO348,50^AGR^FD         milk butter^FS
^FO350,52^AGR^FD         milk butter^FS

To underline, draw a graphics box below the required letters. This is relatively easy to calculate since the width of each letter is constant.

^FO345,490^GB0,160,4^FS
^FO345,690^GB0,240,4^FS

I tested using an A300 and 8"*3" labels, so I needed to rotate the text, hence some odd calculations. The manual does not show the ^FS, even in the examples but I found it was required.

Ossetic answered 27/12, 2014 at 19:37 Comment(10)
Some time ago I figured out the underline trick myself, but the bold trick was new. Thanks! :)Skippet
@ArgaPK Oh come,now. That would be useful. In 1997, Zebra stopped talking to me because they insisted that SSCC and EAN-128 were identical.Ossetic
@Ossetic Ok ,thanks , could you please tell me how to display text in different colors ???Separate
@Separate I've never used a zebra colour printer.Ossetic
@Ossetic Why? What is the drwaback?Separate
@ArgaPK: Because I've been unemployed for 16 years and have no application for them outside of an industrial setting. When I attempted to use something similar many years ago, I was told that I shouldn't be attempting to get the required test labels from the vendor (who didn't understand what labels I required) but to explain the problem to the the IT clerk who would do that as my time was expensive. Naturally, telling the clerk would take just as much time and I'd have to rely on his simply being a parrot to get the message to the vendor, but that was management's attitude.Ossetic
@Ossetic Thankyou, this is really helpful!Pup
@Ossetic Is there a way to make the text italic?Rissa
@Rissa : Not inbuilt, as far as I'm aware. You may possibly use a suitable downloadable font if you can find one.Ossetic
@Ossetic Yes, I also got the same response from the support team. ThanksRissa
H
9

You could also try and make the font width grow a little:

^A0N,18,20

"^A" starts the font setting, where "0" is the embedded font, "N" the rotation, "18" the height and "20" the font width. The last one is 10 by default. So you're actually making the font wider, which results in a form of bold...

It may not affect the lines that are printed horizontally, but you will get a sense of bold.

(I know it's an 'old' topic, but I just wanted to share)

Homicidal answered 17/3, 2017 at 15:24 Comment(1)
Since I got in trouble today and still no BOLD by the ZPL-Language I appreciate this simple solution. ThanksMisconceive
U
0

Based on @raphioly-san I decided to increase the font-size to get font-weight bold/bolder equivalent.

for the following javascript object and functions, I achieve the desired result on Node-RED app :


    const element = { 
        type: 'text', 
        content: 'Article: 1001779', 
        x: 5, // horizontal position from left border
        y: 5, // vertical position from top border
        font_size: 6, // font size in pixels
        font_weight: 'bold', // can be 'bold', 'bolder' or remove line for 'normal'
    };
    
    const margin = 2; // for 2mm margins

    return {
        ...msg
        payload: generateZPLText(element, margin)
    };

    function mmToPoints(mm, margin) {
        return Math.abs( (mm + margin) / 10 * 72);
    }

    function generateZPLText(element, margin) {
        const x_points = mmToPoints(element.x, margin);
        const y_points = mmToPoints(element.y, margin);
        const fontSize = element.font_size ? element.font_size * 4 : 20;
        
        if(element.font_weight) {
            if(element.font_weight == 'bolder') {
                const fontWidth = Math.abs( (fontSize + 5) * 4 );
            }
            else if(element.font_weight == 'bold') {
                const fontWidth = Math.abs( (fontSize + 3) * 4 );
            }
            else {
                const fontWidth = Math.abs( fontSize * 4 );
            }
        }
    
        return `^FO${x_points},${y_points}^A0N,${fontSize},${fontWidth}^FD${element.content}^FS`;
    }

Urial answered 25/1 at 13:18 Comment(2)
What is the PrintDensity defined in your ZPL code? How are you doing Math.abs( (mm + margin) / 10 * 72) to convert from mm to points?Indomitable
As I don't know how ZPL reacts with floats, I prefer to use integers (hence the use of Math.abs). The calculation is resulting from several trials starting with the conversion of 2.54 inches to mm, which, in the end, has evolved into a different calculation. Regarding resolution, I can't be sure, but here is what I can say: ZPL MODE: ZPL II, PRINT WIDTH: 457, RESOLUTION: 832 8/MM FULL, FIRMWARE: V61.17.17Z, DARKNESS: 15.0Urial

© 2022 - 2024 — McMap. All rights reserved.