Issue with Language Rendering while converting html to pdf

When converting an html file to pdf which contains Bangali or Japanese Language it’s not rendering properly and shows square boxes. I am using .net Version 22.6.0
We have uploaded our html file to HTML to PDF Converter - free online app | Convert HTML from anywhere and it throws the same error. Aspose Error.zip (21.4 KB)

Thanks in Advance!

@gotethics

Please install the fonts used in your HTML on the system where you are converting HTML to PDF to avoid this issue. Moreover, we suggest you please use the latest version of Aspose.PDF for .NET 22.10.

@tahir.manzoor After the upgrade of the version to 22.10. Japanese text is rendering fine, however, the issue still exists with Bangali and Hindi languages as well. You’ve mentioned that install the fonts on the machine. But I’m not specifying any font in HTML.

@awais.ilyas, @gotethics

Please install ‘Nirmala UI’ font and use following code example to avoid the shared issue. Hope this helps you.

HtmlLoadOptions htmloptions = new HtmlLoadOptions(); 
FontRepository.getSubstitutions().add(new PdfFontSubstitution());
var document = new Document(MyDir + "Aspose-html to pdf issue.html", htmloptions);

document.save(MyDir + "22.10.pdf");
private static class PdfFontSubstitution extends CustomFontSubstitutionBase {
	@Override
	public boolean trySubstitute(OriginalFontSpecification originalFontSpecification, Font[] substitutionFont) {
		
		
		if (!originalFontSpecification.isEmbedded()) {
			substitutionFont[0] = FontRepository.findFont("Nirmala UI");
			return true;
		} else {
			return super.trySubstitute(originalFontSpecification, substitutionFont);
		}
	}
}

@tahir.manzoor In your above solution, I have to always specify different fonts according to language. But users can add content in any language, I have tested Bengali, Hindi, and Japanese at the moment but my assumption is there are also other languages that aren’t rendering properly.

here is the code snippet I’m using in .NET.

var htmlContent = $“My multi-lingual html {content}”;

        using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(htmlContent)))
        {
            var options = new HtmlLoadOptions();
            var pdfDocument = new Aspose.Pdf.Document(memoryStream, options);

            using var outputMemoryStream = new MemoryStream();
            pdfDocument.RemoveMetadata();
            pdfDocument.Info.Author = string.Empty;
            pdfDocument.Info.Title = string.Empty;
            pdfDocument.Save(outputMemoryStream);

            return outputMemoryStream.ToArray();
        }

@awais.ilyas

In your case you need to install fonts related Bengali, Hindi, and Japanese languages. You do not need to specify the font as suggested in my previous font.

substitutionFont[0] = FontRepository.findFont("Nirmala UI");

@awais.ilyas

For your case, we have logged a ticket as PDFJAVA-42195 in our issue tracking system. We will inform you once there is an update available on it. We apologize for your inconvenience.

@tahir.manzoor any update on this ticket PDFJAVA-42195 Thank you

@awais.ilyas

Currently, your issue is pending for analysis and is in the queue. Once our product team completes the analysis of your issue, we will then be able to provide you an estimate.

@tahir.manzoor any update on this? I have checked also following URL: Convert HTML, XHTML, Markdown, MHTML, EPUB and SVG Online or Using C# still Japanese language isn’t rendering from HTML to PDF.

@awais.ilyas

Regretfully, the ticket could not get resolved due to other pending issues in the queue. Nevertheless, your concerns have been recorded and we will surely inform you as soon as we make some progress towards ticket resolution. Please be patient and spare us some time.

We apologize for the inconvenience.