473,562 Members | 2,650 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 20016
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 wxHtmlEasyPrint ing:
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(f ile('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(f ile('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
22278
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 the selected printer. I'm not concerned about the text format. What I tried is something like this CommonDialog1.ShowPrinter
2
2588
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 of classes that allow me to interact with network devices. In other words, if I have a path and filename inside of a string variable in python,...
5
1999
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 actions or set variables. We are interested in doing this inline (no pop-up dialog box). Specifically, where how would I replace the following...
7
6869
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 Steve
2
3478
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 of the windows. My question is: How can i make the same thing in VB .NET 2003? thanks for help
0
1483
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>"; } printer_write($handle, "Text to print"); printer_close($handle); ?>
4
16789
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 Tip to these Topics. The Tip will actually consist of several Tips which I feel are very useful for all Users, from Newbies to Experts. In order to...
0
897
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 files in the Printer Queue prior to moving on to the next step which is combining the PDFs. IE If I combine too early the files still in the queue do...
0
1456
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 2000 as Backend. Anybody plz help me out in this context. I need to solve this urgently... Here is my code... sql = "select * from...
0
1767
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 print the printer-friendly version (a pdf). So far, I've got this script: <a...
0
7655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7577
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7627
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7935
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6221
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5193
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
903
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.