[Image-SIG] Problem printing images via ImageWin
howard at eegsoftware.com
howard at eegsoftware.com
Fri Jun 20 12:08:31 EDT 2003
I am trying to use the code snippet below to print images (under
Windows). The output file (out.png) is correctly saved but nothing ever
prints. When I uncomment out the WritePrinter command, the text prints
so I am *assuming* I opened the printer OK.
It appears that expose function does not send anything to the printer
context. This is PIL.1.1.4 (binary installer).
What AM I doing wrong?
--------
# grab image
img=_grabwidget(container.fr)
img.save("out.png")
##translate gray to white
##optionally make grayscale
dib=ImageWin.Dib('RGB',img.size)
dib.paste(img,None)
# get DC
try:
hnum=win32print.OpenPrinter(pname)
except:
if prt:
print 'failure OpenPrinter'
return
try:
win32print.StartDocPrinter(hnum,1,('Test',None,None))
except:
if prt:
print 'failure startdocprint'
##win32print.WritePrinter(hnum,'This is a test\n')
try:
dc=win32ui.CreateDCFromHandle(hnum)
except:
if prt:
print 'failure getting DC'
return
# output to DC
hdc=dc.GetHandleAttrib()
dib.expose(hdc)
# close DC
del dc
win32print.EndDocPrinter(hnum)
win32print.ClosePrinter(hnum)
del dib
del img
More information about the Image-SIG
mailing list