Hi All, I am having a few problems with my code to generate proper PDF reports. Basically I have the same problems with reportlab so i am giving pyfpdf a try - *Problems:*
1. Long text (example *description *in below code) does not fit in the boundaries. It does not wrap to next line it just exceeds the page width - please see sample report attached. 2. I cant make zebra strips (alternate line/row color) to work properly here 3. The HTML output does not work (I have the view rep_open_issues.html - no data) [Live Demo for HTML pyfpdf does not work Ex - this url - http://www.web2py.com.ar/fpdf/default/listing ] Throws error - *invalid view (default/listing.html)* Here is my code - def rep_open_issues(): response.title = "Open Issues" head = THEAD(TR(TH("Ticket",_width="15%"), TH("Sub Cateogry",_width="20%"), TH("Severity",_width="15%"), TH("Description",_width="50%"), _bgcolor="#A0A0A0")) foot = TFOOT(TR(TH("Fair Price - Good Day",_width="100%"), _bgcolor="#E0E0E0")) querysql = (""" Select ticket_no, sub_category, severity, description from issues where status='Open' and created_by='""" + logged_in_user ) try: allissues = db.executesql(querysql) except: pass rows = [] for issue in allissues: mycounter = [] mycounter.append(issue) i = len(mycounter) col = i % 2 and "#F0F0F0" or "#FFFFFF" rows.append(issue) # make the table object body = TBODY(*rows) table = TABLE(*[head,foot, body], _border="1", _align="center", _width="100%") if request.extension=="pdf": from gluon.contrib.pyfpdf import FPDF, HTMLMixin # define our FPDF class (move to modules if it is reused frequently) class MyFPDF(FPDF, HTMLMixin): def header(self): self.set_font('Arial','B',15) self.cell(0,10, response.title ,1,0,'C') self.ln(20) def footer(self): self.set_y(-15) self.set_font('Arial','I',8) txt = 'Page %s of %s' % (self.page_no(), self.alias_nb_pages()) self.cell(0,10,txt,0,0,'C') pdf=MyFPDF() # first page: pdf.add_page() pdf.write_html(str(XML(table, sanitize=False))) response.headers['Content-Type']='application/pdf' return pdf.output(dest='S') else: # normal html view: return dict(table=table) Not much is changed here- I know, i may be missing a few tricks. Please help me fill the same As a Ref - I checked this thread ["Re: How to Generate the effective report by using web2py"] in google groups but without much resolution. Please suggest. Thanks Rahul -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
rep_open_issues.pdf
Description: Adobe PDF document