473,472 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Printing a text file using Python

I have been trying to print a text file to my printer but the most I have
been able to do is print one line. I have been using the following commands.

dc = win32ui.CreateDC()
dc.CreatePrinterDC()
dc.SetMapMode(4) # This is UI_MM_LOENGLISH
# With this map mode, 12 points is 12*100/72 units = 16
font = win32ui.CreateFont({'name' : 'Arial', 'height' : 16})
dc.SelectObject(font)
f=open("./Reports/Report.txt","r")
memory=f.read()
f.close
memory.split('\n')
dc.StartDoc("./Reports/Report.txt")
dc.StartPage()
dc.TextOut(10,10,memory)
dc.EndPage()
dc.EndDoc()

Can anyone tell me how I need to change this so it will print out the entire
file instead of just one line.

Thanks in advance...
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.524 / Virus Database: 321 - Release Date: 10/6/2003
Jul 18 '05 #1
1 5784
"Serge Guay" <se***@theguays.com> wrote:
I have been trying to print a text file to my printer but the most I have
been able to do is print one line. I have been using the following commands.

dc = win32ui.CreateDC()
dc.CreatePrinterDC()
dc.SetMapMode(4) # This is UI_MM_LOENGLISH
# With this map mode, 12 points is 12*100/72 units = 16
font = win32ui.CreateFont({'name' : 'Arial', 'height' : 16})
dc.SelectObject(font)
f=open("./Reports/Report.txt","r")
memory=f.read()
f.close
memory.split('\n')
dc.StartDoc("./Reports/Report.txt")
dc.StartPage()
dc.TextOut(10,10,memory)
dc.EndPage()
dc.EndDoc()

Can anyone tell me how I need to change this so it will print out the entire
file instead of just one line.


The Windows GDI calls don't know anything about lists. There are several
ways to do what you want:

for i in range(memory):
dc.TextOut(10, 10+16*i, memory[i])

Of course, that only works if everything fits on one page. Another
alternative is to let Windows do the splitting, using dc.DrawText with
DT_CALCRECT. If you try that, DON'T do the split. Pass the whole string
to dc.DrawText. It will STILl have to fit on one page.

If you have multiple pages, you will have to count the Y coordinates
yourself and call EndPage/StartPage.

That's why I use reportlab for my printing.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fuzzyman | last post by:
I looked through the manual, I looked on the web and could find very little on this subject.... The closest I could find was : http://www.faqts.com/knowledge_base/view.phtml/aid/4549. Saying...
7
by: Kamilche | last post by:
I'm pretty desperate to get color syntax printing. I just tried out the evaluation version of 'Komodo', which several people in here suggested, and its print features are terrible. The text is...
2
by: Darcy Kahle | last post by:
I am trying to do some advanced printing in python using the win32ui module, and have run into an issue. I need to print a page landscape. As I could not determine how to specify the orientation...
5
by: Donnal Walter | last post by:
We want to be able to print HTML or PDF files to a given printer from Python in a kind of batch mode (without opening a preview window or printer dialog for each file). The printer is on a network,...
19
by: dcrespo | last post by:
Hi all... Is there a way to print a PDF file directly from Python without having Acrobat installed? I know about ReportLab. It's a python module that lets you create almost any PDF document, but I...
10
by: Mario | last post by:
Hello all, I'm trying hard to make possible to print some simple text from python to the default printer using wxPython, after days of internet searches I found this page:...
10
by: Brian Hanson | last post by:
Hi, I am trying to programmatically print a pdf file via an asp.net application. I have seen other postings that mention the following code used or something similar to it in a vb.net app. ...
7
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...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
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...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.