On Mon, Jul 16, 2012 at 5:08 PM, thinkwell <thinkwelldesi...@gmail.com> wrote: > Well, me again. I decided that I wanted to use points as measurements > instead of percentages, so now it barfs with an AttributeError. > > > > from gluon.contrib.pyfpdf import FPDF, HTMLMixin > from gluon.html import * > > > pets = TABLE(_width="720pt") > pets.append(TR(TH('Dogs', _width="72pt", > _align="left"),TH("Cats",_width="72pt", > _align="left"),TH('Snakes',_width="72pt", _align="left"))) > pets.append(TR('Collies','Tabby','Python', _width="60pt")) > > pets.append(TR('Akitas', 'Persian', 'Garter')) > pets.append(TR('German Shepherds', 'Alley Cats', 'Rattlesnakes')) > > > class MyFPDF(FPDF, HTMLMixin): > pass > > pdf=MyFPDF() > #First page > pdf.add_page() > pdf.write_html(pets.xml()) > > pdf.output('html2.pdf','F') > > > This is clearly unremarkable HTML, but no, I get tracebacks like so: > > Traceback (most recent call last): > File "pyfpdf_test.py", line 73, in <module> > pdf.write_html(pets.xml()) > File "/home/dave/PythonTraining/web2py/gluon/contrib/pyfpdf/html.py", line > 388, in write_html > h2p.feed(text) > File "/usr/lib/python2.7/HTMLParser.py", line 114, in feed > self.goahead(0) > File "/usr/lib/python2.7/HTMLParser.py", line 158, in goahead > k = self.parse_starttag(i) > File "/usr/lib/python2.7/HTMLParser.py", line 324, in parse_starttag > self.handle_starttag(tag, attrs) > File "/home/dave/PythonTraining/web2py/gluon/contrib/pyfpdf/html.py", line > 241, in handle_starttag > self.pdf.set_x(self.table_offset) > AttributeError: HTML2FPDF instance has no attribute 'table_offset'
Sorry, only percentage is supported. Pt and Em and any other unit is not supported. I'll try to add better error messages and documentation, sorry for the issue. > I find this remarkable; this ordinary HTML; web2py encourages the use of > HTML helpers. web2py is easy to use, requires few dependencies, etc. etc. > But what a fight to create a simple table-based PDF! :-( And I'm still > experimenting in the layout stage. My final report will be much larger and > include nested tables (that are already rendering fine in HTML, but not in > pyfpdf / html2pdf). Sorry, but definitively your report is out of scope of html2pdf / pyfpdf right now. Please remember, the current implementation is a basic HTML parser to do *basic* reports. Nested tables are not supported and I don't think they will in the near future. If I could get some funding maybe I could spend more time enhancing this. > Should I bite the bullet and install Reportlab? It'll be harder to get > started, more complicated to install & maintain (this will have to go on > multiple machines). The idea of a simple web2py project was very attractive > for these reasons. AFAIK Reportlab doesn't even have a html2pdf conversor. If you switch to reportlab, you will have to code your report using PlatyPlus. You should consider they commercial licence that includes paid support for this kind of issues. As you said, the html2pdf recipe is a simple web2py project Maybe you have to go with third-party tools like Pisa (xhtml2pdf) or use built-in pdf conversion of chrome-browser, or pdf printers. Best regards, Mariano Reingart http://www.sistemasagiles.com.ar http://reingart.blogspot.com --