By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,478 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Errno 32 Broken pipe

P: n/a
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.
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.