【问题标题】:Creating label using ZPL Python使用 ZPL Python 创建标签
【发布时间】:2021-12-05 10:21:54
【问题描述】:

我正在尝试使用 QR 码和一些文本创建标签并将标签另存为 PDF。我无法将标签尺寸更改为 9 X 3 厘米。我该怎么做?

到目前为止我尝试了什么?

import requests
import shutil

zpl = """
^XA
^FO50,60^A0,15^FDID 123456^FS

^FO100,100
^BQN,2,5
^FDQA,QR_CODE^FS

^FO120,270^A0,15^FDTest here^FS
^FO150,290^A0,15^FDSome more text here^FS
^FO25,25^GB500,350,2^FS

^XZ
"""

# adjust print density (8dpmm), label width (4 inches), label height (6 inches), and label index (0) as necessary
url = 'http://api.labelary.com/v1/printers/8dpmm/labels/3.5x10/0/'
files = {'file' : zpl}
headers = {'Accept' : 'application/pdf'} # omit this line to get PNG images back
response = requests.post(url, headers = headers, files = files, stream = True)

if response.status_code == 200:
    response.raw.decode_content = True
    with open('label.pdf', 'wb') as out_file: # change file name for PNG images
        shutil.copyfileobj(response.raw, out_file)
else:
    print('Error: ' + response.text)

【问题讨论】:

    标签: python python-requests shutil zpl


    【解决方案1】:

    你需要找到基本上4个参数的正确组合,它们是:

    1. 以点为单位的图形元素的大小,例如文本和边界框。
    2. 标签的密度(或分辨率)应与您的打印机相匹配。
    3. (物理)标签的大小。
    4. PDF 页面的大小。

    以下是如何控制每一项的示例。
    仅显示相关行:

    # The values in your ZPL set the sizes in dots:
    zpl = """
    ^XA
    ^FO50,60^A0,15^FDID 123456^FS
    
    ... (your full ZPL here) ...
    
    """
    
    # Then:
    
    # 1. Set the density (24dpmm) and the size of the label in inches (2.8x2):
    url = 'http://api.labelary.com/v1/printers/24dpmm/labels/2.8x2/0/'
    
    # 2. Set the PDF page size, here A4:
    headers = {'Accept' : 'application/pdf', 'X-Page-Size':'A4'}
    

    注意:如果页眉中没有设置PDF页面大小,那么它将与物理标签大小匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多