Windows Printing using win32print

KellyK kelly.kranabetter at gems6.gov.bc.ca
Tue Jun 26 13:52:10 EDT 2001


On Mon, 25 Jun 2001 15:24:04 -0700, Timothy Grant <tjg at hyperlinq.net>
wrote:
>In my first iteration, I simply wrote a text file, then used
>os.system('copy filename lpt1:') to print it. This worked just
>fine, but one of the variables I need to test is how an
>interaction with the actual Windows printers works. To that end
>I started reading up on win32print. I was able to come up with
>the following...
<snip>

Here is what I use to send HPGL jobs to an HP 1055 plotter. The PJL
commands set the job name (so the jobname appears on the printer's LCD
screen) and switch the printer into HPGL mode. It has been a while but
I seem to remember that I needed to have the switch to HPGL mode even
though the "copy file lpt1" style worked. Perhaps you will need
something similar?

import win32print, os

UEL= "\x1b" "%-12345X"   # control code to get to PJL
p= win32print.OpenPrinter(r"\\server\design10")
filename= "blah.000"
jobname= os.path.splitext(os.path.split(filename)[1])[0]
j= win32print.StartDocPrinter(p, 1, (jobname, None, None))
f= open(filename, "rb")
buffer_size= 100000
t= f.read(buffer_size)
win32print.WritePrinter(p, UEL + "@PJL JOB NAME = \"" + jobname +
"\"\n at PJL ENTER LANGUAGE = HPGL2\n")
while t:
  win32print.WritePrinter(p, t)
  t= f.read(buffer_size)
f.close()
win32print.WritePrinter(p, UEL + "@PJL EOJ \"" + jobname + "\"\n" +
UEL)
win32print.EndDocPrinter(p)
win32print.ClosePrinter(p)




More information about the Python-list mailing list