Printing to port 9100 with PJL and Python

1.7k Views Asked by At

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

0

There are 0 best solutions below