HTMLFragment not working for Indian Language (Tamil, Telgu)

I have a valid Aspose PDF license with a subscription expiry date of 2023-09-06, which permits me to use SDK versions released up to that date.

Currently, I am using Aspose.PDF version 23.8.0. However, I am encountering an issue where the font does not render correctly. Below is the relevant code:

string wrap = "<div style=\"background-color:white; " + (rightToLeft ? "direction:rtl; " : "") + " text-align:" + textAlign + ";" + 
              (rightPadding > 0 ? "padding-right:" + rightPadding.ToString() + "mm; " : "") + 
              "color:rgb(" + (color ?? Color.Black).ToRgb().R + "," + (color ?? Color.Black).ToRgb().G + "," + 
              (color ?? Color.Black).ToRgb().B + "); text-align:" + textAlign + "; line-height:" + lineHeight + 
              "; font-size:{1}pt;font-weight:{3};font-style:{4};\">" +
              "<font face='{2}'>{0}</font></div>";

if (rightToLeft)
{
    text = LetterReverse(text);
}

HtmlFragment newText = new HtmlFragment(string.Format(wrap, text, fontSize.ToString(), fontName, 
                                                      (bold ? "bold" : "normal"), 
                                                      (italics ? "italic" : "normal")));
newText.HorizontalAlignment = (textAlign == "right" ? HorizontalAlignment.Right : HorizontalAlignment.Left);
newText.TextState = new TextState
{
    Font = FontRepository.FindFont(fontName)
};
container.Add(newText);

Interestingly, this issue is resolved when I update to version 23.9.0. However, since this version was released after my license expiry date, I am not permitted to use it.

@bhushanravi20091

Cause

The issue you’re experiencing with rendering Indian languages like Tamil and Telugu in Aspose.PDF version 23.8.0 is likely due to font compatibility. Some fonts may not support these languages properly, leading to incorrect rendering.

Solution

Since you’ve noted that upgrading to version 23.9.0 resolves the issue, but you’re unable to use it due to your license expiry, you can try the following steps:

  1. Check Font Availability: Ensure that the font you are using supports the specific Indian languages. You should use a Unicode-compliant font that is known to work well with these languages, such as “Noto Sans Tamil” or “Noto Sans Telugu”.

  2. Embed Fonts: Make sure to embed the font in your PDF document. This can help ensure that the text renders correctly on systems that may not have the font installed.

  3. Use a Different Approach: If the HTMLFragment is not rendering correctly, consider using a different method to add text, such as using TextBuilder or TextFragment, which may provide better support for complex scripts.

Code

Here’s a modified version of your code that ensures the font is embedded:

string wrap = "<div style=\"background-color:white; " + (rightToLeft ? "direction:rtl; " : "") + " text-align:" + textAlign + ";" + 
              (rightPadding > 0 ? "padding-right:" + rightPadding.ToString() + "mm; " : "") + 
              "color:rgb(" + (color ?? Color.Black).ToRgb().R + "," + (color ?? Color.Black).ToRgb().G + "," + 
              (color ?? Color.Black).ToRgb().B + "); line-height:" + lineHeight + 
              "; font-size:{1}pt;font-weight:{3};font-style:{4};\">" +
              "<font face='{2}'>{0}</font></div>";

if (rightToLeft)
{
    text = LetterReverse(text);
}

HtmlFragment newText = new HtmlFragment(string.Format(wrap, text, fontSize.ToString(), fontName, 
                                                      (bold ? "bold" : "normal"), 
                                                      (italics ? "italic" : "normal")));
newText.HorizontalAlignment = (textAlign == "right" ? HorizontalAlignment.Right : HorizontalAlignment.Left);
newText.TextState = new TextState
{
    Font = FontRepository.FindFont(fontName, true) // Ensure the font is embedded
};
container.Add(newText);

Next Steps

  1. Test the above code with different fonts that support Tamil and Telugu.
  2. If the issue persists, reach out to Aspose support for a temporary license to use the latest version, or check if you can renew your subscription to access the latest features and fixes.

Please implement these suggestions and let me know if you need further assistance!

I am using “Noto Sans Tamil” or “Noto Sans Telugu”, that’s working on the higher version but not the version that I have the liscence. I want to know is there many enhancement and fixes done on the higher version, before purchase.

@bhushanravi20091

We continuously enhance the API and address reported issues through our monthly updates. Therefore, we strongly recommend using the latest version of the API. If your license has expired and you’re unable to upgrade, you may request a free 30-day temporary license to evaluate the latest version. Once you’re satisfied, you can proceed with renewing your subscription.