is there a way to generate pdf containing non-ascii symbols with pisa from django template?

Posted by mihailt on Stack Overflow See other posts from Stack Overflow or by mihailt
Published on 2009-10-28T13:26:48Z Indexed on 2010/04/02 10:23 UTC
Read the original article Hit count: 356

Filed under:
|
|
|

Hi. i'm trying to generate a pdf from template using this snippet:

def write_pdf(template_src, context_dict):
    template = get_template(template_src)
    context = Context(context_dict)
    html  = template.render(context)
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result)
    if not pdf.err:
        return http.HttpResponse(result.getvalue(), mimetype='application/pdf')
    except Exception('PDF error')

but all non-latin symbols are not showing correctly, the template and view are saved using utf-8 encoding.

i've tried saving view as ANSI and then to user unicode(html,"UTF-8"), but it throws TypeError.

Also i thought that maybe it's because the default fonts somehow do not support utf-8 so according to pisa documentation i tried to set fontface in template body in style section.

that still gave no results.

Does any one have some ideas how to solve this issue?

© Stack Overflow or respective owner

Related posts about python

Related posts about django