【问题标题】:ZPL print Italic Bold and UnderlineZPL 打印斜体粗体和下划线
【发布时间】:2022-02-05 01:58:40
【问题描述】:

我需要打印带有动态内容的 ZPL。

我需要你的帮助。我动态内容,帮助

这个词可以打印吗?注意内容是动态的。 请提供 ZPL 代码。

【问题讨论】:

标签: zpl


【解决方案1】:

如果你想输入粗体,你可以使用这个

^FO340,128^FDbold^FS ^FO339,128^FDbold^FS

另一个选项(下划线、斜体和粗体的外部字体使用) http://labelary.com/docs.html

【讨论】:

    【解决方案2】:

    没有简单的方法可以使用 ZPL 来粗体或斜体文本。打印机的字体非常基本,不能这样更改。

    【讨论】:

    • 现在有什么可以做斜体的吗?
    【解决方案3】:

    复杂的字体设置(斜体、粗体、衬线)实际上作为压缩图像发送到 ZPL 打印机(您可以使用 ZebraDesigner 进行检查)。 该格式称为 Z64,它基于 LZ77。 这两个页面包含用 Java 编写转换器的有趣代码:

    http://www.jcgonzalez.com/img-to-zpl-online

    https://gist.github.com/trevarj/1255e5cbc08fb3f79c3f255e25989a18

    ...我仍然不确定转换的 CRC 部分是否会在未来保持不变,因为这可能取决于供应商。

    这是第一个脚本的 Python 端口:

    import cv2
    import base64
    import matplotlib.pyplot as plt
    import io
    import numpy
    
    blacklimit=int(50* 768/100)
    compress=False
    total=0
    width_byte=0
    mapCode =  dict()
    LOCAL_PATH="C://DEV//printer//zebra_debug.txt"
    '''
    class StringBuilder(object):
    
        def __init__(self):
            self._stringio = io.StringIO()
        
        def __str__(self):
            return self._stringio.getvalue()
            
        def getvalue(self):
            return self._stringio.getvalue()
        
        def append(self, *objects, sep=' ', end=''):
            print(*objects, sep=sep, end=end, file=self._stringio)
    '''
    def init_map_code():
        global mapCode
        mapCode[1] = "G"
        mapCode[2] = "H"
        mapCode[3] = "I"
        mapCode[4] = "J"
        mapCode[5] = "K"
        mapCode[6] = "L"
        mapCode[7] = "M"
        mapCode[8] = "N"
        mapCode[9] = "O"
        mapCode[10] = "P"
        mapCode[11] = "Q"
        mapCode[12] = "R"
        mapCode[13] = "S"
        mapCode[14] = "T"
        mapCode[15] = "U"
        mapCode[16] = "V"
        mapCode[17] = "W"
        mapCode[18] = "X"
        mapCode[19] = "Y"
        mapCode[20] = "g"
        mapCode[40] = "h"
        mapCode[60] = "i"
        mapCode[80] = "j"
        mapCode[100] = "k"
        mapCode[120] = "l"
        mapCode[140] = "m"
        mapCode[160] = "n"
        mapCode[180] = "o"
        mapCode[200] = "p"
        mapCode[220] = "q"
        mapCode[240] = "r"
        mapCode[260] = "s"
        mapCode[280] = "t"
        mapCode[300] = "u"
        mapCode[320] = "v"
        mapCode[340] = "w"
        mapCode[360] = "x"
        mapCode[380] = "y"
        mapCode[400] = "z"
            
    def numberToBase(n, b):
        if n == 0:
            return [0]
        digits = []
        while n:
            digits.append(int(n % b))
            n //= b
        return digits[::-1]
    
    def four_byte_binary(binary_str):
        
        decimal=int(binary_str, 2)
        if decimal>15:
            returned=hex(decimal).upper()
            returned=returned[2:]
        else:
            #returned=hex(decimal).upper()+"0"
            returned=hex(decimal).upper()
            if binary_str!="00000000":
                print("cut="+returned)
            returned=returned[2:]
            returned="0"+returned
            if binary_str!="00000000":
                print("low10="+returned)
        #
        if binary_str!="00000000":
            print(binary_str+"\t"+str(decimal)+"\t"+returned+"\t")
        return returned
        
    def createBody(img):
        global blacklimit
        global width_byte
        global total
        height, width, colmap = img.shape 
        print(height)
        print(width)
        print(colmap)
        rgb = 0
        index=0
        aux_binary_char=['0', '0', '0', '0', '0', '0', '0', '0']
        sb=[]
        if(width%8>0):
            width_byte=int((width/8)+1)
        else:
            width_byte=width/8
        total=width_byte*height
        print(height)
        print("\n")
        print(width)
        print("\n")
        i=0
        for h in range(0, height):
            for w in range(0, width):
                color = img[h,w]
                #print(color)
                #print(w)
                
                blue=color[0]
                green=color[1]
                red=color[2]
                blue=blue  & 0xFF
                green=green  & 0xFF
                red=red  & 0xFF
                """
                blue=np.uint8(blue)
                green=np.unit8(green)
                red=np.unit8(red)
                
                """
                #print(bin(blue))
                auxchar='1'
                total_color=red+green+blue
                if(total_color> blacklimit):
                    #print('above_black_limit')
                    auxchar='0'
                aux_binary_char[index]=auxchar
                index=index+1
                if(index==8 or w==(width-1)):
                    if "".join(aux_binary_char) !="00000000":
                        print(i)
                    sb.append(four_byte_binary("".join(aux_binary_char)))
                    i=i+1
                    aux_binary_char=['0', '0', '0', '0', '0', '0', '0', '0']
                    index=0
            #print(h)
            
            sb.append("\n")
        #print(sb)
        print(blacklimit)
        return ''.join(sb)
    
    def encode_hex_ascii(code):
        global width_byte
        global mapCode
        max_linea=width_byte*2
        sb_code=[]
        sb_linea=[]
        previous_line=1
        counter=1
        aux = code[0]
        first_char=False
        for i in range(1, len(code)):
            if(first_char):
                aux=code[i]
                first_char=False
                continue
            if(code[i]=="\n"):
                if(counter>= max_linea and aux=='0'):
                    sb_linea.append(",")
                elif(counter>= max_linea and aux=='F'):
                    sb_linea.append("!")  
                elif(counter>20):
                    multi20=int((counter/20))*20
                    resto20=counter%20
                    sb_linea.append(mapCode[multi20])  
                    if(resto20!=0):
                        sb_linea.append(mapCode[resto20] +aux)  
                    else:
                        sb_linea.append(aux)
                else:
                    sb_linea.append(mapCode[counter] +aux)
                
                counter=1
                first_char=True
                if(''.join(sb_linea)==previous_line):
                    sb_code.append(":")
                else:
                    sb_code.append(''.join(sb_linea))
                previous_line=''.join(sb_linea)
                sb_linea=[]
                continue
            if aux==code[i]:
                counter=counter+1
            else:
                if counter>20:
                    multi20=int((counter/20))*20
                    resto20=counter%20
                    sb_linea.append(mapCode[multi20]) 
                    if resto20!=0:
                        sb_linea.append(mapCode[resto20] + aux)
                    else:
                        sb_linea.append(aux)
                else:
                    
                    sb_linea.append(mapCode[counter] + aux)
                counter=1
                aux=code[i]
        return ''.join(sb_code)
        
    def head_doc():
        global total
        global width_byte
        return "^XA " + "^FO0,0^GFA,"+ str(int(total)) + ","+ str(int(total)) + "," + str(int(width_byte)) +", "
        
    def foot_doc():
        return  "^FS"+ "^XZ"    
    
    def process(img):
        global compress
        init_map_code()
        cuerpo=createBody(img)
        print("CUERPO\n")
        print(cuerpo)
        print("\n")
        if compress:
            cuerpo=encode_hex_ascii(cuerpo)
            print("COMPRESS\n")
            print(cuerpo)
            print("\n")
        return head_doc() + cuerpo + foot_doc() 
        
    img = cv2.imread("C:\\Users\\ftheeten\\Pictures\\out.jpg", cv2.IMREAD_COLOR )
    compress=True
    blacklimit ==int(50* 768/100)
    test=process(img)
    
    file=open(LOCAL_PATH, 'w')
    file.write(test)
    file.close()
    

    【讨论】:

      猜你喜欢
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 2013-11-06
      • 2012-07-20
      • 1970-01-01
      相关资源
      最近更新 更多