Putting the following code in generic.pdf and getting report.pdf does not work?
(also, per default there is a generic.pdf made by massimo that uses
markmin and latex if I remember it correctly)

from gluon.contrib.pyfpdf import FPDF, HTMLMixin
from gluon.sanitizer import sanitize

class MyFPDF(FPDF, HTMLMixin):
   pass

pdf=MyFPDF()
pdf.add_page()
html=response.render('%s/%s.html' %
(request.controller,request.function))
html = sanitize(html, escape=False)
pdf.write_html(html)
response.headers['Content-Type']='application/pdf'
response.write(pdf.output(dest='S'), escape=False)


Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com



On Thu, May 26, 2011 at 4:30 PM, luifran <lbernalhernan...@yahoo.es> wrote:
> if I have a view , for example report.html, how I render this view in
> pdf with the generic pdf?
>
> On 4 oct 2010, 17:08, Mariano Reingart <reing...@gmail.com> wrote:
>> On Sun, Oct 3, 2010 at 1:10 AM, mdipierro <mdipie...@cs.depaul.edu> wrote:
>>
>> > I am sure this can also be done and better with pyfpdf but I have not
>> > tried. Perhaps Mariano can help us
>>
>> Having latest web2py versions (including pyfpdf), write in a 
>> views/generic.pdf:
>>
>> ---- begin file ----
>> {{
>>
>> from gluon.contrib.pyfpdf import FPDF, HTMLMixin
>> from gluon.sanitizer import sanitize
>>
>> class MyFPDF(FPDF, HTMLMixin):
>>     pass
>>
>> pdf=MyFPDF()pdf.add_page()
>> html=response.render('%s/%s.html' %
>> (request.controller,request.function))
>> html = sanitize(html, escape=False)pdf.write_html(html)
>> response.headers['Content-Type']='application/pdf'
>> response.write(pdf.output(dest='S'), escape=False)
>>
>> }}
>>
>> ---- end file---
>>
>> At MyFPDF class you can add headers and footers.
>>
>> The sanitize part is to strip some HTML tags that cannot be rendered
>> (ie. javascript).
>>
>> As some DIVs contents and similar may still pass (like menus), a
>> better alternative may be render only certains portions of the page in
>> a custom view:
>>
>> pdf.write_html(str(XML(CENTER(section), sanitize=False)))
>>
>> Best regards,
>>
>> Mariano Reingarthttp://www.sistemasagiles.com.arhttp://reingart.blogspot.com
>

Reply via email to