1

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

Alias_Knagg
  • 886
  • 1
  • 7
  • 21
  • 1
    One thing to notice is that `soc.send(b)` may not send all of `b`, but only the first part. Use `soc.sendall(b)` instead. – gogognome Jan 21 '21 at 11:11
  • Thanks. Have corrected the question, but the result is the same :-( – Alias_Knagg Jan 21 '21 at 21:14
  • 1
    I have tried your code too on my HP Officejet 8620 with exactly the same result as you mention. The printer makes noises as if to start printing. And then nothing comes out of the printer... Hopefully somone else finds a solution. – gogognome Jan 22 '21 at 08:36
  • Ah, so its probably not just my printer then... Maybe I could use Wireshark to look at an example that works.. I would need to set up a printer in the OS that only uses 9100.. – Alias_Knagg Jan 22 '21 at 15:34
  • Hm.. It seems I am unable to print to 9100 from Ubuntu 18.04 at all. – Alias_Knagg Jan 22 '21 at 18:49

0 Answers0