Thanks a lot for example. It didn't work but I found a solution with
work. After some modifications:

        from xhtml2pdf.pisa import CreatePDF, startViewer
        from tg.render import render as render_template
        import cStringIO
        html = render_template({"param1": 1, "param2": 2}, "genshi",
"myapp.templates.page", doctype=None)
        dest = '/home/user/files/pdf/test.pdf'
        result = file(dest, "wb")
        pdf = CreatePDF(cStringIO.StringIO(html), result)
        result.close()
        import paste.fileapp
        f = paste.fileapp.FileApp('/home/user/files/pdf/test.pdf')
        from tg import use_wsgi_app
        return use_wsgi_app(f)

It's work fine without national characters but with it in template
it's returning the error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0119' in
position 2497: ordinal not in range(128)

I have in my script:
# -*- coding: utf-8 -*-

and also in template:

<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"
py:if="False"/>

How can I set default encoding to utf-8 for render? Or is there any
other solution?

please help





2012/6/20 Alessandro Molina <[email protected]>:
> Minimal example with xhtml2pdf is:
>
>        from xhtml2pdf.pisa import CreatePDF
>        from tg import render_template (or from tg.render import
> render as render_template for TG2.1)
>
>        html = render_template({"param1": value1, "param2": value2},
>                                          "genshi", "myapp.templates.page",
>                                          doctype=None)
>
>        f = StringIO()
>        CreatePDF(StringIO(html), f)
>        f.seek(0)
>        return f
>
> There is even an example to integrate it as a middleware somewhere if
> I'm not wrong.
>
> On Wed, Jun 20, 2012 at 3:08 PM, Timuçin Kızılay
> <[email protected]> wrote:
>> I need that too.
>> maybe a quick example to generate pdf files would be better suited. Not
>> convert html to pdf but generating directly to pdf would be better.
>>
>>
>>
>> On 20-06-2012 15:58, abc_coder wrote:
>>>
>>> Hi All
>>>
>>> I want to convert my web page to pdf, write it to file and allow users
>>> to download it for print.
>>> But I don't have any idea how do this with current version of tg.
>>> I found some examples for xhtml2pdf but I couldn't make it working with
>>> my app.
>>> The doc for xhtml2pdf are very poor and I had problems with finding any
>>> examples.
>>>
>>> I tried also shell script wkhtmltopdf but it's not working for pages
>>> with authentication.
>>>
>>> Is there any easy way of doing that? how can I get data from genshi
>>> template to convert it to pdf?
>>>
>>> I would be very grateful for giving some good code examples.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "TurboGears" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/turbogears?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/turbogears?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to