473,412 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 "Programming
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 3003
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 "Programming
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\print_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.com...
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 "Programming
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(sys.argv)
printer = QPrinter(QPrinter.PrinterResolution)
printer.setPageSize(printer.A4)
printer.setOutputToFile(1)
printer.setOutputFileName("qtprint.ps")
painter = QPainter(printer)
painter.drawText(painter.window(), painter.AlignCenter, "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.com...
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 "Programming
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 "Programming
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_margin": 25,
"horz_margin": 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.setfirstweekday(calendar.SUNDAY)

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

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

self.canvas.drawString(label,
10,
self.setup["upperlefty"]- 40,
Font(face="sansserif",size=16,bold=1),
color=green)
for row, wk in enumerate(month_cal):
topy = self.setup["upperlefty"]+ row*self.setup["rowoffset"]
self.canvas.drawString('00:00', 10, topy+4,
Font(face="sansserif",size=8,bold=1),
color=darkorange)
self.canvas.drawString('12:00', 10,
topy+4+(self.setup["rowoffset"]-self.setup["vert_margin"])*.5 ,
Font(face="sansserif",size=8,bold=1),
color=darkorange)
self.canvas.drawLine( self.setup["upperleftx"]-10,

topy+(self.setup["rowoffset"]-self.setup["vert_margin"])*.5,
self.setup["upperleftx"]+
7*self.setup["coloffset"],

topy+(self.setup["rowoffset"]-self.setup["vert_margin"])*.5,
color=darkorange, width=1 )
self.canvas.drawString('08:00', 10,
topy+4+(self.setup["rowoffset"]-self.setup["vert_margin"])*(8/24.0) ,
Font(face="sansserif",size=6,bold=1),
color=darkorange)
self.canvas.drawLine( self.setup["upperleftx"]-10,

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

topy+(self.setup["rowoffset"]-self.setup["vert_margin"])*(8/24.0),
color=darkorange, width=1 )
self.canvas.drawString('17:00', 10,
topy+4+(self.setup["rowoffset"]-self.setup["vert_margin"])*(17/24.0) ,
Font(face="sansserif",size=6,bold=1),
color=darkorange)
self.canvas.drawLine( self.setup["upperleftx"]-10,

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

topy+(self.setup["rowoffset"]-self.setup["vert_margin"])*(17/24.0),
color=darkorange, width=1 )
self.canvas.drawString('24:00', 10,
topy+4+(self.setup["rowoffset"]-self.setup["vert_margin"]) ,
Font(face="sansserif",size=8,bold=1),
color=darkorange)

for col, date in enumerate(wk):
topx = self.setup["upperleftx"]+
col*self.setup["coloffset"]
self.canvas.drawString(wkdaytxt[col],
topx,
self.setup["upperlefty"]*.7,
Font(face="sansserif",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.drawRect( topx, topy,

(topx+(self.setup["coloffset"]-self.setup["horz_margin"])),

(topy+(self.setup["rowoffset"]-self.setup["vert_margin"])),
edgeColor=black, edgeWidth=2,
fillColor=transparent)
self.canvas.drawString('%d'%(i+1), topx, topy-2 ,
Font(face="sansserif",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(self,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_str2value(action['start_sec'])
e_dict, e_time = self.date_str2value(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_margin"]))
ypos_end = topy + (e_time *
(self.setup["rowoffset"]-self.setup["vert_margin"]))
right_side = topx +
(self.setup["coloffset"]-self.setup["horz_margin"])

self.canvas.drawRect( topx, ypos_start,
right_side, ypos_end,
edgeColor=black, edgeWidth=1,
fillColor=skyblue)
self.canvas.drawString(client, topx+2, ypos_start+5,
Font(face="sansserif",size=5,bold=0),
color=darkorchid)

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

def save(self, filename):
self.canvas.flush()
self.canvas.save(filename)

Jan 29 '06 #8

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

Similar topics

19
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 --. ...
17
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...
3
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,...
25
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...
0
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...
0
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...
6
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...
1
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...
6
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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
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...

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.