473,513 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 19988
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
22255
by: Patrick Herb | last post by:
Hello, I'm trying to print the content of a RichTextBox from my VB 6 app. What I want is that the CommonDialog shows up, the user selects a printer and the content of the RichTextBox prints to...
2
2580
by: Jody Burgess | last post by:
Hi; I am writing my first python program and would like to know how to change stdout to refer to my default printer or any other printer on my network. The other question is, Is there an API set...
5
1990
by: Tom Berry | last post by:
We currently are trying our first transformation from VB6 to VB.Net. Of course, the Printer object is gone, but I'm having trouble finding the replacement syntax necessary to perform similar...
7
6861
by: Steve M | last post by:
Hello, I'm having problems sending information from a python script to a printer. I was wondering if someone might send me in the right direction. I wasn't able to find much by Google TIA...
2
3476
by: Luis Ramos | last post by:
Sorry, i am new in .net languages. In vb6 i use to do this to print: printer.Fontname= "Arial" printer.FontSize=8 Printer.print "some text" Printer.Enddoc And the text is printed to the spoll...
0
1481
by: What What | last post by:
I'm trying to print a report to a printer directly using PHP printer function. I have code like the following one. <? if($handle=printer_open()){ print "Printer Connected<br>"; }...
4
16776
ADezii
by: ADezii | last post by:
Recently, there seems to be several questions specifically related to Printers and changing Printing characteristics for Forms and Reports. For this reason alone, I decided to dedicate this week's...
0
891
by: ZitoMD | last post by:
I have an application where the user selects appropriate files from a OpenFileDialog box which then sends the file to the PDF printer. My problem is that I want to wait until there are no more...
0
1451
by: praveenhathwar | last post by:
Im trying to print to a 40 column printer through my VB Application. But the printer instead of printing it will keep showing Spooling status. Im Using Epson TM-U220PD Printer, VB 6.0 and Sql Server...
0
1764
by: arieta | last post by:
Hey, I'm still learning and just needed some help. Basically I want to add a link on a webpage, that contains the web-friendly version of a document, so that when you click on the link, it will...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.