Skip to content

Commit d164646

Browse files
authored
ZPL Layout helpers (#328)
1 parent 6723ffc commit d164646

File tree

6 files changed

+744
-9
lines changed

6 files changed

+744
-9
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
additional_dependencies: ['flake8-bugbear']
4646

4747
- repo: https://github.com/agritheory/test_utils
48-
rev: v1.18.0
48+
rev: v1.19.0
4949
hooks:
5050
- id: update_pre_commit_config
5151
- id: validate_frappe_project

beam/beam/print_format/labelary_print_preview/labelary_print_preview.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"docstatus": 0,
1111
"doctype": "Print Format",
1212
"font_size": 14,
13-
"html": "<div class=\"zpl-label\">\n<img src=\"data:image/png;base64,{{ labelary_api(doc, 'Handling Unit 6x4 ZPL Format', {}) }}\" /> \n</div>\n",
13+
"html": "<div class=\"zpl-label\">\n<img src=\"data:image/png;base64,{{ labelary_api(doc, 'Handling Unit 6x4 ZPL Format', {'width': 6, 'height': 4, 'dpmm': 8}) }}\" /> \n</div>\n",
1414
"idx": 0,
1515
"line_breaks": 0,
1616
"margin_bottom": 15.0,

beam/beam/printing.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ def labelary_api(doc, print_format, settings=None):
151151
e.globals.update(methods)
152152
template = e.from_string(print_format.raw_commands)
153153
output = template.render(doc=doc)
154-
url = "http://api.labelary.com/v1/printers/8dpmm/labels/6x4/0/"
154+
155+
# Extract label dimensions and DPI from settings
156+
# dpmm: dots per millimeter (default 8 = ~203 DPI)
157+
# width: label width in inches (default 6)
158+
# height: label height in inches (default 4)
159+
# index: label index for multi-label formats (default 0)
160+
dpmm = settings.get("dpmm", 8) # 8 dpmm ≈ 203 DPI, 12 dpmm ≈ 300 DPI
161+
width = settings.get("width", 6)
162+
height = settings.get("height", 4)
163+
index = settings.get("index", 0)
164+
165+
url = f"http://api.labelary.com/v1/printers/{dpmm}dpmm/labels/{width}x{height}/{index}/"
155166
r = requests.post(url, files={"file": output})
156-
return base64.b64encode(r.content).decode("ascii")
167+
content = r.content
168+
return base64.b64encode(content).decode("ascii")

0 commit comments

Comments
 (0)