Is this report to be printed? If so, just generate a pdf. On Saturday, July 14, 2012 4:06:33 PM UTC-4, thinkwell wrote: > > Hello everyone, > > I'm experimenting with pyfpdf with HTML formatting, but it's not going so > well. Is a bit buggy. For example, this code generates a KeyError: 'width'. > > {from gluon.contrib.pyfpdf import FPDF, HTMLMixin > from gluon.html import * > > header = HEAD('html2pdf', _align='center') > > pets = TABLE(_border=1, _width="100%") > pets.append(TR(TH('Dogs'),TH("Cats"),TH('Snakes'))) > pets.append(TR('Collies','Tabby','Python')) > pets.append(TR('Akitas', 'Persian', 'Garter')) > > > class MyFPDF(FPDF, HTMLMixin): > pass > > html2 = pets.xml() > > print html2 > > pdf=MyFPDF() > #First page > pdf.add_page() > pdf.write_html(html2) > pdf.output('html2.pdf','F')} > > I > {/usr/lib/python2.7/HTMLParser.pyc in goahead(self, end) > 156 if startswith('<', i): > 157 if starttagopen.match(rawdata, i): # < + letter > --> 158 k = self.parse_starttag(i) > 159 elif startswith("</", i): > 160 k = self.parse_endtag(i) > > /usr/lib/python2.7/HTMLParser.pyc in parse_starttag(self, i) > 322 self.handle_startendtag(tag, attrs) > 323 else: > --> 324 self.handle_starttag(tag, attrs) > 325 if tag in self.CDATA_CONTENT_ELEMENTS: > 326 self.set_cdata_mode(tag) > > /home/dave/PythonTraining/web2py/gluon/contrib/pyfpdf/html.pyc in > handle_starttag(self, tag, attrs) > 245 self.td = dict([(k.lower(), v) for k,v in > attrs.items()]) > 246 self.th = True > --> 247 if self.td.has_key('width'): > 248 self.table_col_width.append(self.td['width']) > 249 if tag=='thead': > > KeyError: 'width' > } > > I tried changing line 247 to - > {if self.td.has_key('width'):} > > But the KeyError is still getting raised. :-( > > Is generating reports from HTML not recommended? In addition to this > KeyError, I've frequently gotten "list out of range" exceptions raised as > well, on what seem like the most vanilla of experiments. > > >
--