Skip to content

Instantly share code, notes, and snippets.

@Keegan-y
Forked from sanjeevsiva17/printToPrinter.py
Created November 7, 2022 09:13
Show Gist options
  • Save Keegan-y/1a4f8f3583f4229cb2f61662e26635af to your computer and use it in GitHub Desktop.
Save Keegan-y/1a4f8f3583f4229cb2f61662e26635af to your computer and use it in GitHub Desktop.
Create and send zpl file to printer
import os, sys
import subprocess
def printToPrnter(name, city):
data = "^XA" \
"^FO200,30^ADN,30,20^FB400,3,0,C^FD"+name+"^FS" \
"^FO200,80^ADN,30,20^FB400,3,0,C^FD"+city+"^FS" \
"^XZ"
try:
f = open("code.zpl", "w")
f.write(data)
f.close()
except Exception as e:
return "Could not create zpl file :" + str(e)
try:
subprocess.call(['lp', '-d', 'Zebra_Technologies_ZTC_GC420t_', '-o', 'raw', 'code.zpl'])
except Exception as e:
return "Error calling printer :" + str(e)
os.remove("code.zpl")
return "Print Succesfull"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment