当前位置:   article > 正文

Python实现博思得打印机网络打印图片_python 调用打印机打印图片

python 调用打印机打印图片
import socket
mysocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = "X.X.X.X"        //打印机ip地址
port = 9100             //打印机端口
image_path = "123.pcx"        
class Function():
    @staticmethod
    def Print_pcx():
        try:
            mysocket.connect((host, port))
            with open(image_path,"rb") as f:
                img = f.read()
                len_img = len(img)
                a0 = b'I8,1,001\r\n'
                a0 += b'ZN\r\n'
                a0 += b'q795\r\n'
                a0 += b'O\r\n'
                a0 += b'*D5F\r\n'
                a0 += b'JF\r\n'
                a0 += b'H10\r\n'
                a0 += b'ZT\r\n'
                a0 += b'Q520,25\r\n'
                a0 += b'GK"img_1"\r\n'
                a0 += b'GM"img_1"' + bytes(str(len_img), 'GBK') + b'\r\n'
                a0 += img + b'\r\n'
                a0 += b'N\r\n'
                a0 += b'GG50,50,"img_1"\r\n'
                a0 += b'W1\r\n'
                a0 += b'GK"img_1"\r\n'
                mysocket.send(a0)
            mysocket.close()
        except:
            print("Printer connection failed")

function = Function()
function.Print_pcx()
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/546072
推荐阅读
相关标签
  

闽ICP备14008679号