I wanted to convert HTML to PDF having special characters but the output is not showing the special characters.
from io import BytesIO
from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
def html2pdf(template_source,context_dict={}):
template=get_template(template_source)
html=template.render(context_dict)
result=BytesIO()
pdf=pisa.CreatePDF(BytesIO(html.encode('utf-8')),result)
if not pdf.err:
return HttpResponse(result.getvalue(),content_type="application/pdf")
return None
is my pdf.py
and I have a HTML file which is pdf.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<head>
<style>
body {font-family: 'Josefin Slab';
font-size: large;
background-color: beige;}
</style>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2 class="utf">This is myŐ, Ű, ő or ű✅✅ pdf file with special char</h2>
</body>
</html>
When I am converting this into a PDF it is showing
This is my■, ■, ■ or ■■■■■■■■■■■■■ pdf file with special......
What to do now?