471,888 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,888 software developers and data experts.

Print to printer

I can't seem to figure out how to print with my printer using python.
I'm using Mac OSX 10.4. I was thinking maybe something with
applescript. Does anyone know?

Oct 28 '05 #1
7 19419
You should be more specific. What do you want to print? Text, images,
....
If you want a cross platform solution you could use wxPython:
http://wiki.wxwidgets.org/docbrowse....intingoverview

For text you could use wxHtmlEasyPrinting:
http://wiki.wxpython.org/index.cgi/Printing

For mac solutions, you better post this on the pythonmac mailing list.

Stani
--
http://pythonide.stani.be
http://pythonide.stani.be/manual/html/manual.html

Oct 29 '05 #2
I just want to print text. I'll try macpython. Thanks for the help.

Oct 31 '05 #3
I just want to print text. I'll try macpython. Thanks for the help.

Oct 31 '05 #4
avnit wrote:
I can't seem to figure out how to print with my printer using python.
I'm using Mac OSX 10.4. I was thinking maybe something with
applescript. Does anyone know?


Mac OSX is unix, right?

This ought to work then:
import os
printer = os.popen('lpr', 'w')
printer.write('This is a test.\n')
printer.close()


Try to get 'lpr' or 'lp' to work from a command line.
You should be able to use 'lpstat -p' to figure out
printer names if you need that (then use 'lpr -P ps'
to print to a printer called ps.)
Nov 1 '05 #5
Wow. That worked perfectly. Thanks a lot.

Nov 5 '05 #6
Do you know if there's a way to print a file? I'm trying to print an
HTML file, so your solution is good, but doesn't really work for me.
Just reading the HTML file and the printing the content obviously
wouldn't work. I also tried:
printer.write(file('path/to/file.ext'))


but apparently this function only takes strings as parameters.

Thanks.

Nov 5 '05 #7
avnit wrote:
Do you know if there's a way to print a file? I'm trying to print an
HTML file, so your solution is good, but doesn't really work for me.
Just reading the HTML file and the printing the content obviously
wouldn't work. I also tried:
printer.write(file('path/to/file.ext'))


but apparently this function only takes strings as parameters.


Unless you have a strong desire to waste time and memory by opening
the file reading the content into a string and then call printer.write,
you could simply do something along the lines of this:

fn = 'path/to/file.ext'
printer = 'ps'
print_cmd = 'lpr -P %s %s'
os.system(print_cmd % (printer, fn))
Nov 7 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Patrick Herb | last post: by
5 posts views Thread by Tom Berry | last post: by
7 posts views Thread by Steve M | last post: by
2 posts views Thread by Luis Ramos | last post: by
reply views Thread by ZitoMD | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.