Menu

Printer Ticket Alignment Problem for Chinese Words

mica
2014-11-12
2021-10-15
  • mica

    mica - 2014-11-12

    I got problems for printing Chinese words in sales tickets. They are not aligned properly. (Sample printout)
    Instead of using "text align ='left' length='17' for printing, is it possible to print the contents similar to using table, tr, td tags of html?

     
  • chris J.

    chris J. - 2014-11-12

    for the price and value to use a right alignment.

    chris J.

     
  • mica

    mica - 2014-11-14

    Hi Chris,

    Thx for your feedback. The standard template already set the righ alignment for the price and value. I guess the problem is caused by the double byte size for Chinese characters comparing with single byte size for normal characters. :-(

    Any clues to solve the problem?

     
  • Yohan Choi

    Yohan Choi - 2015-01-06

    I don't use Chinese, but I use Korean word, so I solved that problem by modified Printer.Ticket.xml file.. like below


    #set ($longestName = 0)
    #set ($longestPriceTax = 0)
    #set ($shortestPriceTax = 100)
    #set ($shortestValue = 100)
    #set ($longestMultiply = 0)
    #set ($longestValue = 0)

        #foreach ($ticketline in $ticket.getLines())
    
        #set ($length1 = ${ticketline.printName().length()})
        #set ($length2 = ${ticketline.printPriceTax().length()})
        #set ($length3 = ${ticketline.printMultiply().length()})
        #set ($length4 = ${ticketline.printValue().length()})
    
        #if ($length1 > $longestName)
        #set ($longestName = $length1)
        #end
    
        #if ($length2 > $longestPriceTax)
        #set ($longestPriceTax = $length2)
        #end
    
        #if ($length3 > $longestMultiply)
        #set ($longestMultiply = $length3)
        #end
    
        #if ($length4 > $longestValue)
        #set ($longestValue = $length4)
        #end
    
        #if ($length2 < $shortestPriceTax)
        #set ($shortestPriceTax = $length2)
        #end
    
        #if ($length4 < $shortestValue)
        #set ($shortestValue = $length4)
        #end
    
        #end
    
        #set ($gap1 = 2)
        #set ($gap2 = 3)
        #set ($gap3 = 3)
        #set ($maxCharName = 8)
    
        <line>
            <text align ="left" length="15">상품</text>
            <text align ="right" length="5">단가</text>
            <text align ="right" length="8">수량</text>
            <text align ="right" length="8">가격</text>
        </line>
        <line>
            <text>------------------------------------------</text>
        </line>
    
        #foreach ($ticketline in $ticket.getLines())
    
        #set ($Namelength = ${ticketline.printName().length()})
        #set ($PriceTaxlength = ${ticketline.printPriceTax().length()})
        #set ($Multiplylength = ${ticketline.printMultiply().length()})
        #set ($Valuelength = ${ticketline.printValue().length()})
    
        #if ($Valuelength > 7)
        #set ($gap1 = 1)
        #set ($gap2 = 2)
        #set ($gap3 = 1)
        #else if ($PriceTaxlength > 6)
        #set ($gap1 = 1)
        #set ($gap2 = 2)
        #set ($gap3 = 2)
        #end
    
        #if ($Namelength > $maxCharName)
        #set ($offset1 = (1 + ($longestPriceTax - $PriceTaxlength)))
        #else
        #set ($offset1 = ($maxCharName - $Namelength + 1) + ($longestPriceTax - $PriceTaxlength))
        #end
        #set ($offset1 = $offset1 + $gap1)
        #set ($offset2 = $longestMultiply - $Multiplylength + $gap2)
    
        #set ($offset3 = $longestValue - $Valuelength  + $gap3)
    
        <line>
    
            #if ($ticketline.isProductCom())
            <text>*</text>
            #else
            #if ($Namelength > $maxCharName)
            <text>${ticketline.printName().substring(0,$maxCharName)}</text>    
            #else
            <text>${ticketline.printName()}</text>  
            #end
    
            #foreach ($i in [1..$offset1])
            <text> </text>
            #end
    
            #set ($checker = $PriceTaxlength - $shortestPriceTax)
            #foreach ($i in [0..$checker])
            <text></text>
            #end
            #set ($checker2 = $checker/2)
            #if ($checker2 > 0)
            <text></text>
            #end
    
            #end
            #set ($endPriceTax = $PriceTaxlength)
            <text>${ticketline.printPriceTax().substring(0,$endPriceTax)}</text>
    
            #foreach ($i in [0..$offset2])
            <text> </text>
            #end
    
            <text>x${ticketline.printMultiply()}</text>
    
            #foreach ($i in [0..$offset3])
            <text> </text>
            #end
    
            #set ($endValue = $Valuelength)
            <text>${ticketline.printValue().substring(0, $endValue)}</text>
    
        </line>
        #end
        <line>
            <text align="left" length="42">------------------------------------------</text>
        </line>
    

    I did some modified that code written by other developer who use Chinese.

    Still has some bugs....anyway you can align Chinese word on receipt .

    :)

     
  • Yohan Choi

    Yohan Choi - 2015-01-06

    It prints like this

     
  • Mark W

    Mark W - 2015-02-16

    I tried this but find it doesn't work well when you have product names of more than a few characters. I've found a way that's much simpler - just print each product line on 2 lines - one for the product name, the second for the prices / quantity.

    I used the modified header line from the example above as you need to change the length attributes slightly so they line up.

    Here is the code:

    <line><text align ="left" length="15">項目</text><text align ="right" length="5">價錢</text><text align ="right" length="8">數目</text><text align ="right" length="8">價值</text></line>
            <line><text align="left" length="42">------------------------------------------</text></line>
    #foreach ($ticketline in $ticket.getLines())
        <line>
    
        #if ($ticketline.isProductCom())
            <text align ="left" length="42">*${ticketline.printName()}</text>
        #else
            <text align ="left" length="42">${ticketline.printName()}</text>
        #end
        </line>
        <line>
            <text align ="right" length="25">${ticketline.printPriceTax()}</text>
            <text align ="right" length="7">x${ticketline.printMultiply()}</text>
            <text align ="right" length="10">${ticketline.printValue()}</text>
        </line>
    
        #if ($ticketline.productAttSetInstId)
            <line><text align ="left" length="42">${ticketline.productAttSetInstDesc}</text></line>
        #end
    #end
        <line><text align="left" length="42">------------------------------------------</text></line>
    

    It prints like this

     
  • Mark W

    Mark W - 2015-02-17

    Hi Fanzam,

    Yeah I agree about the wasting of paper and look, however in this case it was a migration from another platform with 1000+ products all with long Chinese names, so it solved it well for that.

    I think it is still a good option to have anyway so worth sharing. I've also noticed some large retailers using a similar format to combat the same type of issue with long names.

     

Log in to post a comment.