Search code examples
htmlpdfhtml-renderer

Enable UTF-8 or set custom font with TheArtOfDev's HtmlRenderer.PdfSharp


I'm using TheArtOfDev's HtmlRenderer.PdfSharp to convert an HTML string to PDF in a ASP.NET web application. The HTML contains Japanese characters. The Japanese symbols are converted to ☐ ascii characters.

How can I enable UTF-8 or use a custom Japanese font? I tried the following without results:

  • Adding <head><meta charset='utf-8'></head> to the HTML string.
  • Adding <style>@font-face { font-family: myFont; src: url('path/font.ttf'); }</style> to the HTML string and then settings the font style on the element with Japanese text.
  • Try a CSS file with @font-face and calling TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.ParseStyleSheet

Solution

  • I gave up on HTMLRenderer and PDFSharp and solved all my issues with TuesPechkin, a wrapper for wkhtmltopdf.