Brian Kelley writes:
Paul McNett wrote:
>I simply want to know if anyone has a recipe that can take a
>grid, with any number of rows and columns, and put it to a
> PDF file and/or print it out.
Yeah. Here's a simple way of doing it. Take your grid and
convert it to an html table. Then use wxHtmlEasyPrinting to
print it out. Otherwise you can launch it in your webbrowser
and let that be your printing option.
Thanks for that, I'd forgotten about wxHtmlEasyPrinting even
after learning about it just a couple weeks ago! I took your
code, tweaked it a little, and made it part of my base grid
class, so that my framework can simply ask the grid for it's
current rendition in HTML for whatever reason. I added the
option to not include the HTML and BODY tags, in case the
framework wants to handle it (perhaps the grid's HTML is
just a part of a larger HTML doc). I also made the headers
print in bold, and I added a <TD WIDTH> attribute and
based it off of grid.GetColSize(col). So the user resizes the
grid, and they see their sizing reflected on the printout.
It's trickier if your grid contains images, you have to save
the images as gifs and link them to your html table.
I'll need images... I guess I need to write out the image
files to the temp directory, huh? That's too bad, since they
aren't files at this point (they are BLOBs in a DB) and the
writing out will add overhead and housekeeping. But I
can't complain too much, I suppose... this is just too easy!
Some oddities I noticed on wxGTK:
+ preview shows "Page 1 of 999"
+ zooming will zoom the page size, but not the
page contents
Anyway, here's some code to write a grid to html so that you
can use it with wxHtmlEasyPrinting.
Thanks for including your code, it was very helpful. Here is my
code, which was based on yours, and is a method in my grid
base class:
def getHTML(self, justStub=True, tableHeaders=True):
''' Get HTML suitable for printing out the data in
this grid via wxHtmlEasyPrinting.
If justStub is False, make it like a standalone
HTML file complete with <HTML><HEAD> etc...
'''
cols = self.GetNumberCols()
rows = self.GetNumberRows()
if justStub:
html = ["<HTML><BODY>"]
else:
html =
html.append("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>")
if tableHeaders:
html.append("<TR>")
for col in range(cols):
html.append("<TD ALIGN='center' VALIGN='top' WIDTH=%s><B>%s</B></TD>"
% (self.GetColSize(col), self.GetColLabelValue(col)))
html.append("</TR>")
for row in range(rows):
html.append("<TR>")
for col in range(cols):
html.append("<TD ALIGN='left' VALIGN='top'>%s</TD>"
% self.GetCellValue(row,col))
html.append("</TR>")
html.append("</TABLE>")
return "\n".join(html)
···
--
Paul