Thanks Mariano & Alan. Adding width to TD or TH tags did resolve the 
problem using the original html.py file without the fix implemented.*(Mariano, 
I tried installing your script and at this point it still fails when no 
width is specified. Another little issue, os.startfile() seems to be a 
Windows-only method.)*

So now, things are operational again. Looking forward to Mariano's html.py 
improvements.


On Sunday, July 15, 2012 3:04:04 PM UTC-4, Mariano Reingart wrote:
>
> On Sat, Jul 14, 2012 at 5:06 PM, 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. :-( 
>
> You need to restart the webservice to apply changes in gluon 
>
> > 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. 
>
> Current html2pdf conversion will not work properly if you don't use 
> explicit widths for table cells. 
> You can see the supported tags and a working example here: 
>
> http://code.google.com/p/pyfpdf/wiki/WriteHTML 
>
> Actually, I'm working in a better html2pdf render, using helpers and 
> web2pyHTMLParser: 
>
> http://code.google.com/p/pyfpdf/source/browse/fpdf/html.py 
>
> Hopefully, web2py helpers will improve the rendering mechanisms 
>
> Best regards, 
>
> Mariano Reingart 
> http://www.sistemasagiles.com.ar 
> http://reingart.blogspot.com 
>

Reply via email to