Python 将 png 文件发送到默认打印机

Python send png file to default printer

我有一台热敏打印机,我想在收据顶部打印一个徽标...是否有类似 shutil.copyfile 的 png 图像?

我的代码如下

   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')

感谢 thebjorn,这是我找到的解决方案

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

谢谢大家