Printing to port 9100 with PJL and Python

試著忘記壹切 提交于 2021-01-28 05:23:44

问题


I believe this code should work to print a PDF directly to most printers on port 9100.
This source and this one among others seems to agree on the details.
My printer wakes up and seems to "spool a job" for a moment, but then just goes quiet again.
The socket code is very crude of course, but still..

Maybe it's just my particular printer *.
Grateful if somebody could test this or point out any errors or improvements.

import socket

job = [
    b'\x1b%-12345X@PJL JOB NAME = "My Print Job Name"\r\n',
    b'@PJL ENTER LANGUAGE = PDF\r\n',
    open('mydoc.pdf', 'rb').read(),
    b'\x1b%-12345X @PJL EOF\r\n',
    b'\x1b%-12345X'
]

soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc.connect(('myprinter.local', 9100))
for b in job:
    # print(b)
    soc.sendall(b)
soc.close()

* A Brother MFC-J4620DW

来源:https://stackoverflow.com/questions/61224836/printing-to-port-9100-with-pjl-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!