Soichiro
Soichiro

Reputation: 91

Python send png file to default printer

I have a thermal printer and I would love to print a logo on top of the receipt... Is there something such as shutil.copyfile for png images?

My code is the following

   locations = ['/dev/usb/lp0', '/dev/usb/lp1', '/dev/usb/lp2']
        size = locations.__len__()
        i = 0

        while i < size:
            printer = locations[i]
            try:
                shutil.copyfile('output.txt', printer)
                break
            except IOError:
                i += 1

        if i == size:
            logging.error('Unable to connect to the printer')

Upvotes: 2

Views: 1929

Answers (1)

Soichiro
Soichiro

Reputation: 91

This is the solution that I was able to find thanks to thebjorn

os.system("lp -o fit-to-page -o orientation-requested=3 -o media=Custom.58x210mm logo.png")

Thank you, everyone.

Upvotes: 3

Related Questions