Django - pdf response has wrong encoding - xhtml2pdf -


i'm working on invoice pdf generator on django website. use xhtml2pdf. seems working encodings not correct. there wrong signs/characters when use diacritics.

this view:

def render_to_pdf(template_src, context_dict):     template = get_template("pdf/pdf.html")     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 httpresponse(result.getvalue(), content_type='application/pdf; encoding="utf-8"')     return httpresponse('we had errors<pre>%s</pre>' % escape(html)) 

and html:

<!doctype html> <html>   <head>     <meta charset="utf-8">     <title>title</title>   </head>   <body>     <p>Č š ž Ž x y ľ ĺ ó</p>   </body> </html> 

this generated pdf: enter image description here

do know how make work correctly?

try add font urls html, don't forget replace path , name

<!doctype html> <html>   <head>       <style>         @font-face {         font-family: freesans;         src: url("/usr/share/fonts/truetype/freefont/freesans.ttf");         }          body {         font-family: freesans;         }     </style>       <meta charset="utf-8">     <title>title</title>   </head>   <body>     <p>Č š ž Ž x y ľ ĺ ó</p>   </body> </html> 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -