title: Printing to port 9100 with PJL and Python
body: <p>I believe this code should work to print a PDF directly to most printers on port 9100.<br />
  <a href="http://www.frankworsley.com/blog/2011/1/23/printing-directly-to-a-network-printer" rel="nofollow noreferrer">This source</a> and <a href="https://stackoverflow.com/questions/35562106/print-pdf-using-pcl-and-pjl-in-php">this one</a> among others seems to agree on the details.<br />
  My printer wakes up and seems to &quot;spool a job&quot; for a moment, but then just goes quiet again.<br />
  The socket code is very crude of course, but still..</p>
  <p>Maybe it's just my particular printer *.<br />
  Grateful if somebody could test this or point out any errors or improvements.</p>
  <pre><code>import socket
  
  job = [
      b'\x1b%-12345X@PJL JOB NAME = &quot;My Print Job Name&quot;\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()
  </code></pre>
  <p>* A Brother MFC-J4620DW</p>