【发布时间】: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