Adding a superscript to text in a block in PDFProcessing library.

0 Answers 11 Views
Top achievements
Rank 1
Dudley asked on 27 Apr 2022, 04:00 PM

I would like to add a superscript to text I am adding to a block.  I tried adding the text to a block, and then a TextFragment to the block, but I can't seem to move the text up as a superscript.

block.InsertText(text ?? string.Empty);
var frag = new TextFragment(superscript);
frag.FontSize = fontSize - 2;

I tried using frag.TextRise but it doesn't seem to affect the vertical offset of the fragment no matter what values I use. I also tried using frag.Position, but that doesn't affect it either.   Clearly I am missing something.  Perhaps I should use another approach?

Thanks in advance,

Dudley Chapman

Telerik team
commented on 28 Apr 2022, 08:47 AM

Hi, Dudley,

I am sharing my reply to your ticket in this forum thread as well, in the hope it could be useful to others as well.

To format the text as sub/superscript, you can use the Block.TextProperties.BaselineAlignment property. I've attached a small sample project that shows how to do this. Essentially, the properties are set to a given block, then the desired element (in this case a text fragment) is inserted with the current properties applied. They are then changed to fit the requirements for the next text fragment, before its insertion. Finally, the RadFixedDocumentEditor is used to insert the whole block in the document. The RadFixedDocumenEditor is useful for creating new PDF documents with a flow-like (word-like) structure. We have a great article regarding text properties, which I can recommend - Text and Graphic Properties. It contains useful information on text formatting.

I hope my input helps. I'd be glad to further help if needed, just let me know. Have a great day.

No answers yet. Maybe you can help?

Asked by
Top achievements
Rank 1
Share this question