Thanks Paolo. The code in that plugin was helpful (although I ended up with
different formatting of my PDF using appreport) than I do with the
standalone product.
Anyway, putting this in my controller worked for me. (There was a bug in my
original code - using the read method of StringIO instead of getvalue .)
def report_pisa():
results = dict(success=1)
if request.extension=="pdf":
import xhtml2pdf.pisa as pisa
import StringIO
html = response.render('report/report_pisa.html', results)
doc = StringIO.StringIO()
pdf = pisa.CreatePDF(html, dest = doc)
return doc.getvalue()
return results
On Sunday, November 11, 2012 8:53:21 PM UTC+11, Paolo Caruccio wrote:
>
> did you try appreport (a web2py plugin)
> https://github.com/lucasdavila/web2py-appreport ?
>
>
> Il giorno domenica 11 novembre 2012 06:39:21 UTC+1, chris_g ha scritto:
>>
>>
>> Has anyone had any luck running Pisa in a web2py view?
>> I've only had success with using it at the command line:
>> pisa example.html
>> --> pisa.pdf
>>
>> I've tried putting the following in a view, but I am getting an empty
>> string returned.
>>
>> {{
>> import logging
>> import os
>> import StringIO
>> import xhtml2pdf.pisa as pisa
>> filename = '%s/%s.html' % (request.controller,request.function)
>> if os.path.exists(os.path.join(request.folder,'views',filename)):
>> html=response.render(filename)
>> else:
>> html=BODY(BEAUTIFY(response._vars)).xml()
>> pass
>> result = StringIO.StringIO()
>> pdf = pisa.CreatePDF(html, result)
>> =result.read()
>> }}
>>
>>
>>
>>
--