Errno 32 Broken pipe

C

Chris Jankowski

I am trying to print an image file to a network printer and getting
the following error. This is a Windows based system, using a network
printer.

Any ideas.
Error Message: cannot print image (exceptions.IOError:[Errno 32]
Broken pipe)

**************************************************************
Code:
#! /usr/local/bin/python
#
# The Python Imaging Library.
# $Id: //modules/pil/Scripts/pilprint.py#2 $
#
# print image files to postscript printer
#
# History:
# 0.1 96-04-20 fl Created
# 0.2a1 96-10-04 fl Use draft mode when converting.
#

VERSION = "pilprint 0.2a1/96-10-04"

import Image
import PSDraw

letter = ( 1.0*72, 1.0*72, 7.5*72, 10.0*72 )

def description(file, image):
import os
title = os.path.splitext(os.path.split(file)[1])[0]
format = " (%dx%d "
if image.format:
format = " (" + image.format + " %dx%d "
return title + format % image.size + image.mode + ")"

import getopt, os, sys

if len(sys.argv) == 1:
print "PIL Print 0.2a1/96-10-04 -- print image files"
print "Usage: pilprint files..."
print "Options:"
print " -c colour printer (default is monochrome)"
print " -p print via lpr (default is stdout)"
print " -P <printer> same as -p but use given printer"
sys.exit(1)

try:
opt, argv = getopt.getopt(sys.argv[1:], "cdpP:")
except getopt.error, v:
print v
sys.exit(1)

printer = None # print to stdout
monochrome = 1 # reduce file size for most common case

for o, a in opt:
if o == "-d":
# debug: show available drivers
Image.import_plugins()
print Image.ID
sys.exit(1)
elif o == "-c":
# colour printer
monochrome = 0
elif o == "-p":
# default printer channel
printer = "lpr"
elif o == "-P":
# printer channel
printer = "lpr -P%s" % v

for file in argv:
try:

im = Image.open(file)

title = description(file, im)

if monochrome and im.mode not in ["1", "L"]:
im.draft("L", im.size)
im = im.convert("L")

if printer:
fp = win32pipe.popen(printer, "w")
else:
fp = sys.stdout

ps = PSDraw.PSDraw(fp)

ps.begin_document()
ps.setfont("Helvetica-Narrow-Bold", 18)
ps.text((letter[0], letter[3]+24), title)
ps.setfont("Helvetica-Narrow-Bold", 8)
ps.text((letter[0], letter[1]-30), VERSION)
ps.image(letter, im)
ps.end_document()

except:
print "cannot print image",
print "(%s:%s)" % (sys.exc_type, sys.exc_value)
****************************************************************
Thanks

Chris J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top