How to use Python ESC/POS printing with Epson TM-T81III inside ERPNext Print Format (Jinja)?

Hi ERPNext/Frappe community,

I am trying to print images on an Epson TM-T81III POS printer using Python ESC/POS and Pillow, and I want to integrate this into an ERPNext Print Format (Jinja).

Here is the Python code that works perfectly outside ERPNext:
from escpos.printer import Network
from PIL import Image # pip install Pillow if needed

Connect to printer

kitchen = Network(“192.168.68.111”, profile=“TM-T88III”)

Load and resize image (maintain aspect ratio)

img_path = “/Users/mondaysys03/Desktop/image_convert/Frame .png”
img = Image.open(img_path).convert(‘L’) # Grayscale for thermal
img_resized = img.resize((512, int(img.height * 512 / img.width)), Image.Resampling.LANCZOS)
resized_path = img_path + ‘_resized.png’
img_resized.save(resized_path) # Optional: save resized

kitchen.image(resized_path) # Or use ‘_resized.png’
kitchen.cut()
kitchen.close()

I want to trigger this printing from a Print Format in ERPNext, ideally using Jinja or a server-side script, so that when I open or print an invoice, it automatically sends the image to the POS printer.
What is the best practice to integrate ESC/POS Python printing inside ERPNext Print Formats?
Any working examples of Pillow + escpos printing from ERPNext?
Any guidance, examples, or references to community threads would be much appreciated!

Thanks in advance :folded_hands:

if you want to import external libraries like Pillow,Network etc..
you have to do code level customisation, you can not do it from UI (desk view).

create a custom app
bench new-app myprinter
and create a python file custom_print.py

and ask a good AI to write a code that hooks to the Print Action (specifically invoice with particular print format)

1 Like

:wink: