0

I Have an HTML code in which some texts are in the Hindi language. When I am converting the HTML file to PDF using weasyprint library, The generated PDF looks something like this:

enter image description here

This is my code for conversion:

from weasyprint import HTML
output = open('kt.html', 'rb')#, encoding='utf-8')
html = HTML(output)
html.write_pdf(target='ouput.pdf')

Tried using encoding also, but got this error:

TypeError: Cannot set an encoding with a unicode input, set ['override_encoding', 'transport_encoding']

How to solve this issue?

EDIT: HTML code looks something like this: enter image description here

and HTML browser preview looks something like this

enter image description here

Ayush
  • 373
  • 4
  • 12
  • Isn’t it just that your font does not support those characters? I see there is a deleted answer with `font-family: sans-serif`, but have you tried Arial instead? Also, what does it look like when you open the source HTML with a browser? I suggest you put your HTML & CSS in the question, so we have a [mre]. – Didier L Jan 13 '22 at 18:04
  • Hi @DidierL, updated the question as per your requirement, Also, Arial is also not working. I think while conversion from HTML to pdf, weasyprint library is not able to recognize this HINDI font. – Ayush Jan 13 '22 at 18:21
  • Please don’t put screenshots of code in your questions, it does not allow people to reproduce the problem. Put the real code instead. Also make your example minimal AND complete: reduce it to the bare minimum HTML/CSS that still reproduces the problem. – Didier L Jan 13 '22 at 18:38
  • 1
    FYI, on my side I tried with the string “नमस्ते दुनिया”, and it worked with the default font, as long as I pass `-e utf8` on the command-line or `` in the document. If I don’t, however, the result is completely different from yours: I get “`नमसà¥à¤¤à¥‡ दà¥à¤¨à¤¿à¤¯à¤¾`”. I would still think the problem is your font and not an encoding issue. – Didier L Jan 13 '22 at 18:42

0 Answers0