Search code examples
xsltzplzpl-ii

ZPL: How to horizontally centered a line of text on a label regardless of text length


I need to center some text horizontally on a label so that if the length of text changes it will still remain centered.

I am using XSLT to process the format like this:

        <!-- Position from Home (3.75",4.00")-->
        <xsl:text><![CDATA[^FT494,812]]></xsl:text>

        <xsl:text><![CDATA[^A0B,62,62]]></xsl:text>

      <!-- I am using the FB command to center the text -->
       <xsl:text><![CDATA[^FB500,1,0,C]]></xsl:text>

        <!-- Field Block -->
        <xsl:text><![CDATA[^FD]]></xsl:text>
        <xsl:value-of select="/lb:label/lb:MyDataField" />
        <xsl:text><![CDATA[^FS]]></xsl:text>

So that the output looks like this:

Example A:

        123 Good Street
1234567890 1234567890 1234567890

or

Example: B

 123 Good Street
   1234567890

So far the text is not centering and the result looks like this:

        123 Good Street
        1234567890 1234567890 1234567890

Solution

  • I think your problem is stemming from the use of the B "Bottoms up" orientation in your font. The only examples I have of using ^FB is with the font in the N "normal orientation".

    ^XA^ll800  
    ^FO0,0^A0N,62,62^FB500,1,0,C^FD123 Good Street^FS  
    ^FO0,0^GB500,100,2  
    ^XZ
    

    results in:
    enter image description here