We are using Aspose PDF version 23.5 and trying to use the subscript/superscript properties it has in TextFragment. After trying several times we could not make it working.
Here is our code:
var _fullFormula = new TextFragment(“H”);
var strText = new TextSegment(“2”);
strText.TextState.Font = _fontScript.Font;
strText.TextState.FontSize = _fontScript.FontSize;
strText.TextState.FontStyle = _fontScript.FontStyle;
strText.TextState.Subscript = true; // setting this property, but not working
_fullFormula.Segments.Add(strText);
What is the issue here? How can we mark a text fragment as subscript?
@kchowdhury
It seems that you are having trouble with the subscript and superscript properties in the TextFragment
class while using Aspose PDF version 23.5. Based on your code snippet, you are correctly setting the Subscript
property to true
, but it is not functioning as expected.
Here are a few things to check and try:
-
Font Compatibility: Ensure that the font you are using supports subscript formatting. Some fonts may not render subscript or superscript correctly. You can try using a different font that is known to support these features.
-
Text State Configuration: Make sure that the TextState
properties are being set correctly. You might want to explicitly set the FontSize
to a smaller value for the subscript text to ensure it appears correctly positioned below the baseline.
-
Adding Segments: When adding the TextSegment
to the TextFragment
, ensure that you are not inadvertently overriding the TextState
settings. You can try creating a new TextFragment
for the subscript text and then combine them.
Here’s an example of how you might structure your code:
var _fullFormula = new TextFragment("H");
var strText = new TextSegment("2");
strText.TextState.Font = _fontScript.Font;
strText.TextState.FontSize = _fontScript.FontSize * 0.7f; // Adjust font size for subscript
strText.TextState.FontStyle = _fontScript.FontStyle;
strText.TextState.Subscript = true; // Set subscript property
_fullFormula.Segments.Add(strText);
- Testing with a Simple Example: If the issue persists, try creating a minimal example that only includes the subscript text to isolate the problem. This can help determine if the issue is with the specific text or the overall document setup.
If you continue to experience issues, consider checking the Aspose documentation or forums for any updates or similar cases that might provide additional insights.
If you have any further questions or need additional assistance, feel free to ask!
@asad.ali Can you please guide? We are struggling with it for a long time.
@kchowdhury
We tried below code with 24.10 version of the API but we also couldn’t get any success:
Document document = new Document();
Page page = document.Pages.Add();
TextFragment plainText = new TextFragment("Normal Text ");
TextSegment subscriptText = new TextSegment("Subscript");
subscriptText.TextState.Subscript = true;
TextSegment superscriptText = new TextSegment("Superscript");
superscriptText.TextState.Superscript = true;
plainText.Segments.Add(subscriptText);
plainText.Segments.Add(superscriptText);
page.Paragraphs.Add(plainText);
document.Save(dataDir + "Output.pdf");
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-58578
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.