user1442957
user1442957

Reputation: 7719

python pisa utf8 issue

I am trying to convert a local HTML to a PDF, but the html document has non-ASCII characters that end up broken in the PDF. Why does pisa not work for all UTF-8 characters?

with open('file.html') as m:
  data = m.read()
  m.close()        
  pisa.CreatePDF(data, file('final.pdf', 'w'))

Upvotes: 1

Views: 3799

Answers (2)

madtyn
madtyn

Reputation: 1549

For me it helped using the encoding option with encoding='utf-8':

pisa.CreatePDF(html.content, dest=pdfFile, encoding='utf-8')

Upvotes: 0

Jeff T
Jeff T

Reputation: 620

Got it. This needs to be at the top of your generated content:

<meta http-equiv="content-type" content="text/html; charset=utf-8"> 

Upvotes: 7

Related Questions