1

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'))
Mattie
  • 20,280
  • 7
  • 36
  • 54
user1442957
  • 7,191
  • 5
  • 22
  • 19

2 Answers2

7

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

<meta http-equiv="content-type" content="text/html; charset=utf-8"> 
Jeff T
  • 620
  • 8
  • 12
0

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

pisa.CreatePDF(html.content, dest=pdfFile, encoding='utf-8')
madtyn
  • 1,469
  • 27
  • 55