Windows print to default thermal printer

826 views Asked by At

I'm developing a program to a shop. The program needs to print the receipt of the order using a termal printer. I discovered that the printer follows the ESC/POS standard and I found out that there is a package that helps me having an interface with the printer caled python-esc/pos. However, to print throught a USB connected printer, I need to know the Vendor ID and Product ID. I've discovered a way to find this for all the connected printers on the sistem using the following code:

import usb

def is_printer(dev):
    if dev.bDeviceClass == 7:
        return True
    for cfg in dev:
        if usb.util.find_descriptor(cfg, bInterfaceClass=7) is not None:
            return True

for printer in usb.core.find(find_all=True, custom_match = is_printer):
    print('Decimal VendorID=' + str(printer.idVendor) + ' & ProductID=' + str(printer.idProduct) + '\n')
    print('Hexadecimal VendorID=' + hex(printer.idVendor) + ' & ProductID=' + hex(printer.idProduct) + '\n\n')

However, I discovered that my client has multiple printers connected to his system. I want to be able to always print to the default printer. I would appreciate any help doing that since there are not many docs about default termal printers and all that

Edit: I should clarify that I do not have a thermal printer with me, so I'm working on the dark here, just hoping that it works in his hands.

0

There are 0 answers