473,599 Members | 3,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Placing graphics & text on printed page - jan06call.jpg (0/1)

I am trying to use Python to send to the printer a calender filled
with a mix of text and simple graphics. I want to draw on the printed
page something like a table with 6 rows and 7 columns to represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP

I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses a coordinate
system to allow you to draw lines and to place text on the printed
page precisely. I have attached a file "jan06call. jpg" to this message
to illustrate what I am trying to do.

Does Python have a module which would help me do this?

To put it another way, can Python control the placement of text and
graphics precisely on the printed page?

I have scoured my Python programming texts, python.org, and this
usenet group without success. Mark Lutz's wonderful book "Programmin g
Python" has not one reference to the word "printer" in its index.
Surely, I must be overlooking something or thinking about this wrong.

Michael Galvin
Muskegon, MI

Jan 12 '06 #1
7 3018
To see an example of what I am trying to accomplish, look at this page
on my personal website:

http://mysite.verizon.net/michaelgalvin/jan06call.html

I now realize my attachement could not be posted on this usenet group.

On Thu, 12 Jan 2006 12:16:02 -0500, Michael Galvin
<mi***********@ verizon.net> wrote:
I am trying to use Python to send to the printer a calender filled
with a mix of text and simple graphics. I want to draw on the printed
page something like a table with 6 rows and 7 columns to represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP

I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses a coordinate
system to allow you to draw lines and to place text on the printed
page precisely. I have attached a file "jan06call. jpg" to this message
to illustrate what I am trying to do.

Does Python have a module which would help me do this?

To put it another way, can Python control the placement of text and
graphics precisely on the printed page?

I have scoured my Python programming texts, python.org, and this
usenet group without success. Mark Lutz's wonderful book "Programmin g
Python" has not one reference to the word "printer" in its index.
Surely, I must be overlooking something or thinking about this wrong.

Michael Galvin
Muskegon, MI

Jan 12 '06 #2
Michael Galvin wrote:
To see an example of what I am trying to accomplish, look at this page
on my personal website:

http://mysite.verizon.net/michaelgalvin/jan06call.html

I now realize my attachement could not be posted on this usenet group.

I suspect your best option would be to use ReportLab's open source
package (www.reportlab.org) to generate PDF files.

You may, however, be able to get at the Windows device context through
wxPython (www.wxpython.org): if you download the demonstration you'll
see that on Windows they do send fairly arbitrary graphics to the
Windows printer queue.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Jan 12 '06 #3
Michael Galvin ha scritto:
I am trying to use Python to send to the printer a calender filled
with a mix of text and simple graphics. I want to draw on the printed
page something like a table with 6 rows and 7 columns to represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP

I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses a coordinate
system to allow you to draw lines and to place text on the printed
page precisely. I have attached a file "jan06call. jpg" to this message
to illustrate what I am trying to do.

Does Python have a module which would help me do this?


You can try to use pycairo for graphics, using postscript as a backend.
Then print the postscript file (with Ghostscript).

Or you can use a more high level tool.

Regards Manlio Perillo
Jan 12 '06 #4
Pywin32 wraps most of the GDI functions used to draw
lines and text directly on a printer device context.
Many of them are only implemented as methods of
MFC objects rather than exposed directly.

See \win32\Demos\pr int_desktop.py for some examples
of working directly with a printer DC.

hth
Roger

"Michael Galvin" <mi***********@ verizon.net> wrote in message news:aq******** *************** *********@4ax.c om...
To see an example of what I am trying to accomplish, look at this page
on my personal website:

http://mysite.verizon.net/michaelgalvin/jan06call.html

I now realize my attachement could not be posted on this usenet group.

On Thu, 12 Jan 2006 12:16:02 -0500, Michael Galvin
<mi***********@ verizon.net> wrote:
I am trying to use Python to send to the printer a calender filled
with a mix of text and simple graphics. I want to draw on the printed
page something like a table with 6 rows and 7 columns to represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP

I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses a coordinate
system to allow you to draw lines and to place text on the printed
page precisely. I have attached a file "jan06call. jpg" to this message
to illustrate what I am trying to do.

Does Python have a module which would help me do this?

To put it another way, can Python control the placement of text and
graphics precisely on the printed page?

I have scoured my Python programming texts, python.org, and this
usenet group without success. Mark Lutz's wonderful book "Programmin g
Python" has not one reference to the word "printer" in its index.
Surely, I must be overlooking something or thinking about this wrong.

Michael Galvin
Muskegon, MI


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jan 12 '06 #5
Steve Holden wrote:
Michael Galvin wrote:
To see an example of what I am trying to accomplish, look at this page
on my personal website:

http://mysite.verizon.net/michaelgalvin/jan06call.html

I now realize my attachement could not be posted on this usenet group.
I suspect your best option would be to use ReportLab's open source
package (www.reportlab.org) to generate PDF files.


One alternative, although I'm not convinced that it is actively
maintained any more, is the Piddle/Sping library [1]. As mentioned
elsewhere, the Cairo bindings would provide a similar developer
experience to that, and Cairo is increasingly fashionable.
You may, however, be able to get at the Windows device context through
wxPython (www.wxpython.org): if you download the demonstration you'll
see that on Windows they do send fairly arbitrary graphics to the
Windows printer queue.


PyQt [2] seems to support printing fairly conveniently. Consider this
very simple example:

from qt import *
import sys
qapp = QApplication(sy s.argv)
printer = QPrinter(QPrint er.PrinterResol ution)
printer.setPage Size(printer.A4 )
printer.setOutp utToFile(1)
printer.setOutp utFileName("qtp rint.ps")
painter = QPainter(printe r)
painter.drawTex t(painter.windo w(), painter.AlignCe nter, "Hello")
painter.end()

I haven't used printing in Qt [3] before, so apologies must go out if
I've made fundamental mistakes in the above code which did, admittedly,
produce output that resembled my expectations. Another route might be
to use a Tkinter canvas - at least in times of old, such canvases were
able to dump their contents as PostScript.

Paul

[1] http://piddle.sourceforge.net/
[2] http://www.riverbankcomputing.co.uk/pyqt/index.php
[3] http://doc.trolltech.com/3.3/graphics.html

Jan 13 '06 #6
One option is to create your page as an image file using PIL (which can
handle your text and drawing requirements, as well as any
pictures/graphics), then print it to a windows printer using my
ImagePrintWin module.

ImagePrintWin can print to any normal windows printer, and includes an
optional GUI for doing a "Printer Setup" type dialog (including preview).
It can even handle ICC profiles for your printer if you want color accuracy.

You can download ImagePrintWin (GPL'd) from my site at:

http://www.cazabon.com/python/downlo...agePrintWin.py
The pyCMS module for doing ICC is available also on my site at:

http://www.cazabon.com/pyCMS/

Kevin Cazabon.

"Michael Galvin" <mi***********@ verizon.net> wrote in message
news:qj******** *************** *********@4ax.c om...
I am trying to use Python to send to the printer a calender filled
with a mix of text and simple graphics. I want to draw on the printed
page something like a table with 6 rows and 7 columns to represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP

I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses a coordinate
system to allow you to draw lines and to place text on the printed
page precisely. I have attached a file "jan06call. jpg" to this message
to illustrate what I am trying to do.

Does Python have a module which would help me do this?

To put it another way, can Python control the placement of text and
graphics precisely on the printed page?

I have scoured my Python programming texts, python.org, and this
usenet group without success. Mark Lutz's wonderful book "Programmin g
Python" has not one reference to the word "printer" in its index.
Surely, I must be overlooking something or thinking about this wrong.

Michael Galvin
Muskegon, MI

Jan 15 '06 #7
Michael Galvin wrote:
I am trying to use Python to send to the printer a calender filled
with a mix of text and simple graphics. I want to draw on the printed
page something like a table with 6 rows and 7 columns to represent a
calendar. I want to place text precisely within those boxes on the
printed page. I am using Python 2.4 on Windows XP

I was in the past able to do this within Visual Basic using its
printer object. Visual Basic's printer object uses a coordinate
system to allow you to draw lines and to place text on the printed
page precisely. I have attached a file "jan06call. jpg" to this message
to illustrate what I am trying to do.

Does Python have a module which would help me do this?

To put it another way, can Python control the placement of text and
graphics precisely on the printed page?

I have scoured my Python programming texts, python.org, and this
usenet group without success. Mark Lutz's wonderful book "Programmin g
Python" has not one reference to the word "printer" in its index.
Surely, I must be overlooking something or thinking about this wrong.

Michael Galvin
Muskegon, MI


This does something like you want using piddle. It is designed to make
a pdf of a calendar on a sheet of paper that has times blocked out (the
add_data and print_action methods).

import sys, os, string, re, calendar, time, datetime, copy
from optparse import OptionParser
from piddlePDF import *

class output_pdf:

setup = { #constants to use for spacing
"upperleftx ": 0.75*72,
"upperlefty ": 1*72,
"rowoffset" : 2.0 * 72,
"coloffset" : 1.0 * 72,
"vert_margi n": 25,
"horz_margi n": 25,
}

canvas = PDFCanvas() # backend you want to test
def __init__(self, year, month, title ):
### global canvas
self.printcal( year, month, title)

def printcal(self, year, month, label):
""" prints the days, and times and outside boxes for each day.
sets up a dictionary with the x and y offset for each day.
"""
global calpos
calpos = {}

wkdaytxt = ['Sun', 'Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat']
calendar.setfir stweekday(calen dar.SUNDAY)

# use calendar to figure out days for dates (a list of lists)
month_cal= calendar.monthc alendar( year, month)
#figure out how many weeks and days
daywk1st, days= calendar.monthr ange( year, month)

if len(month_cal) == 6: self.setup["rowoffset"] = 1.8*72

self.canvas.dra wString(label,
10,
self.setup["upperlefty "]- 40,
Font(face="sans serif",size=16, bold=1),
color=green)
for row, wk in enumerate(month _cal):
topy = self.setup["upperlefty "]+ row*self.setup["rowoffset"]
self.canvas.dra wString('00:00' , 10, topy+4,
Font(face="sans serif",size=8,b old=1),
color=darkorang e)
self.canvas.dra wString('12:00' , 10,
topy+4+(self.se tup["rowoffset"]-self.setup["vert_margi n"])*.5 ,
Font(face="sans serif",size=8,b old=1),
color=darkorang e)
self.canvas.dra wLine( self.setup["upperleftx "]-10,

topy+(self.setu p["rowoffset"]-self.setup["vert_margi n"])*.5,
self.setup["upperleftx "]+
7*self.setup["coloffset"],

topy+(self.setu p["rowoffset"]-self.setup["vert_margi n"])*.5,
color=darkorang e, width=1 )
self.canvas.dra wString('08:00' , 10,
topy+4+(self.se tup["rowoffset"]-self.setup["vert_margi n"])*(8/24.0) ,
Font(face="sans serif",size=6,b old=1),
color=darkorang e)
self.canvas.dra wLine( self.setup["upperleftx "]-10,

topy+(self.setu p["rowoffset"]-self.setup["vert_margi n"])*(8/24.0),
self.setup["upperleftx "]+
7*self.setup["coloffset"],

topy+(self.setu p["rowoffset"]-self.setup["vert_margi n"])*(8/24.0),
color=darkorang e, width=1 )
self.canvas.dra wString('17:00' , 10,
topy+4+(self.se tup["rowoffset"]-self.setup["vert_margi n"])*(17/24.0) ,
Font(face="sans serif",size=6,b old=1),
color=darkorang e)
self.canvas.dra wLine( self.setup["upperleftx "]-10,

topy+(self.setu p["rowoffset"]-self.setup["vert_margi n"])*(17/24.0),
self.setup["upperleftx "]+
7*self.setup["coloffset"],

topy+(self.setu p["rowoffset"]-self.setup["vert_margi n"])*(17/24.0),
color=darkorang e, width=1 )
self.canvas.dra wString('24:00' , 10,
topy+4+(self.se tup["rowoffset"]-self.setup["vert_margi n"]) ,
Font(face="sans serif",size=8,b old=1),
color=darkorang e)

for col, date in enumerate(wk):
topx = self.setup["upperleftx "]+
col*self.setup["coloffset"]
self.canvas.dra wString(wkdaytx t[col],
topx,
self.setup["upperlefty "]*.7,
Font(face="sans serif",size=16, bold=1),
color=green)
topx = self.setup["upperleftx "]+
col*self.setup["coloffset"]
topy = self.setup["upperlefty "]+
row*self.setup["rowoffset"]
calpos[date] = (topx, topy)
for i in range(days):
topx, topy = calpos[i+1]

self.canvas.dra wRect( topx, topy,

(topx+(self.set up["coloffset"]-self.setup["horz_margi n"])),

(topy+(self.set up["rowoffset"]-self.setup["vert_margi n"])),
edgeColor=black , edgeWidth=2,
fillColor=trans parent)
self.canvas.dra wString('%d'%(i +1), topx, topy-2 ,
Font(face="sans serif",size=12, bold=1),
color=red)

def date_str2value( self,intime):
tuple_names = ["tm_year", "tm_mon", "tm_mday", "tm_hour",
"tm_min", "tm_sec", "tm_wday", "tm_yday", "tm_isdst"]
t_tuple = time.localtime( intime)
t_dict = {}
for i, name in enumerate(tuple _names):
t_dict[name] = t_tuple[i]
floattime = (float(t_dict['tm_hour'])*60 +
float(t_dict['tm_min']))/float(24*60)

return t_dict, floattime

def print_action(se lf,year,month, action):
##action_list = re.split(r'\t', action)
##starttime = action_list[1]
##endtime = action_list[2]
client = action['destination']

s_dict, s_time = self.date_str2v alue(action['start_sec'])
e_dict, e_time = self.date_str2v alue(action['stop_sec'])
##print s_dict, s_time, ":-:", e_dict, e_time
if (s_dict['tm_mday'] == e_dict['tm_mday'] and
s_dict['tm_mon'] == int(month) and
s_dict['tm_year'] == int(year)):
topx, topy = calpos[s_dict['tm_mday']]
ypos_start = topy + (s_time *
(self.setup["rowoffset"]-self.setup["vert_margi n"]))
ypos_end = topy + (e_time *
(self.setup["rowoffset"]-self.setup["vert_margi n"]))
right_side = topx +
(self.setup["coloffset"]-self.setup["horz_margi n"])

self.canvas.dra wRect( topx, ypos_start,
right_side, ypos_end,
edgeColor=black , edgeWidth=1,
fillColor=skybl ue)
self.canvas.dra wString(client, topx+2, ypos_start+5,
Font(face="sans serif",size=5,b old=0),
color=darkorchi d)

def add_data(self, year, month, data):
for action in data:
#print "adding data", action
self.print_acti on(year, month, action)

def save(self, filename):
self.canvas.flu sh()
self.canvas.sav e(filename)

Jan 29 '06 #8

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

Similar topics

19
33086
by: Philipp Lenssen | last post by:
I don't know the English word, but I'm referring to the double-dash which is used to separate parts of a sentence. I'm using — so far. Now I saw – which is slightly shorter. Some sites use --. Is there anything I should know to make a good decision on which to use, other than what looks best? I think the W3C validator is always handing out errors, even when I go through the different charsets. I remember a time when the W3C validator...
17
3844
by: black tractor | last post by:
HI there.. l was just wondering, if l place a "table" in the "editable region" of my template, will the text, graphics placed inside the this "table" MOVE BY ITSELF?? l mean, recently l had a "table" insert in my "editable region", have it placed in the "center" of the page.. while it display correctly on my browser, with setting at 1024x768 (IE6),
3
1667
by: Ace Calhoon | last post by:
Hello, I'm encountering a strange error when printing my forms and reports in Access. Printed documents will intermittently fail to contain graphical elements (i.e. charts will only print labels, printed forms will only contain text, etc.). When viewed in print preview, the graphics display correctly. Initially this problem only occured once in a great while. More recently it has persisted through a complete shut down and re-boot of...
25
2645
by: JeffS | last post by:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :) Is there a library function for placing the cursor position in the console? Or is it something that can only be done with a platform API call? I was able to do this in Windows with a Windows.h function, but I want to also do it on Linux/Unix as well. I won't ask for a Linux API call that positions the cursor, as that is
0
1105
by: Mark Davison | last post by:
Hi, I hope someone can help, this has been driving me mad! I am trying to generate a graphic on the fly. This is then shown in the browser in a "print preview" type window. The user can click a "Print" button and all the graphics are printed. The problem I have is that the text looks distorted. If you try the example below you will see the problem. This example creates a graphic, writes some text to it and then saves it to your disk as a...
0
1699
by: Arnold | last post by:
Hi Everyone; In a report, I've essentially recreated a paper sheet by adding various labels--name, date, problem, year, Progress Notes, etc.--and horizontal lines (people have traditionally written notes). I made all of these in the Page Header section. By the way, this is a report form to track the daily progress of students. --Report Header--none. --Grouping section--yes. The report form has a StudentID Header, which
6
3238
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
1
15331
by: IvoShalev | last post by:
Hi there, I just want to give some sudgestions on how to draw some plain things only using the header file <graphics.hand of course the standart files <stdio.h<conio.h<stdlib.h>. First of All you have to load drivers for the graphic. -You must have the file EGAVGA.BGI to be in the same directory where your code is. -with this driver you will have 640/480 resolution with 16 colors 1 page or you can choose 320/280 16col with 2 video...
6
5165
by: Greg Esres | last post by:
I have some text lines to print that are much longer than the width of the paper, maybe as much as 6 times. For a given page, I'd like everything that doesn't fit to print on a second page, and whatever doesn't fit there to go on a third page, etc, so that I can piece together the final output by laying the pages side by side. Things that don't work well: 1) Breaking up the line into sections of a given # of characters. Problem with...
0
7992
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7904
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8267
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6725
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5850
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2414
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 we have to send another system
1
1505
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.