Hello,
I’m trying to convert an HTML to PDF with some Simplified Chinese characters on it (and some more languages but let’s focus on Chinese first as the solution I guess would be the same for all the others) but I get some tofu characters on it.
If I visualize the HTML on the browser it displays correctly, has the reference to the Chinese supported font and everything looks good.
Here’s my PDF result: mypdf.pdf (7.1 MB)
Here’s my code:
var htmlOptions = new HtmlLoadOptions
{
InputEncoding = “UTF-8”,
IsEmbedFonts = true
};
var htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html));
var fontSource = new FolderFontSource(_fontsPath);
FontRepository.Sources.Add(fontSource);
htmlOptions.PageInfo = new PageInfo
{
Width = PageSize.PageLetter.Width,
Height = PageSize.PageLetter.Height,
Margin = new MarginInfo(0,0,0,0),
IsLandscape = false
};
var document = new Document(htmlStream, htmlOptions);
var pdf = new PdfFile(document);
var output = new MemoryStream();
document.Save(output, SaveFormat.Pdf);
Here’s the html code: Screenshot 2021-10-19 163455.png (33.8 KB)
Here’s how it looks on the browser: Screenshot 2021-10-19 163538.png (50.7 KB)
Version used: 21.9.0
I have tried with both CDN references and local font files on my local environment (.ttf, .otf files)
Thanks in advance for the support