Skip to content

Instantly share code, notes, and snippets.

@sanjeevsiva17
Created May 4, 2021 10:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sanjeevsiva17/c0eefadbaf75e90f37f53e79cd7f9d85 to your computer and use it in GitHub Desktop.
Save sanjeevsiva17/c0eefadbaf75e90f37f53e79cd7f9d85 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