How to introduce superscript?

Tags: fontssuperscriptiText 7

I want to format a date like this: 14th may 2015. However, the th in 14 should be in superscript as is what happens when you use the "sup" tag.

This is my code:

ph102 = new Phrase(csq.EventDate.Value.Day
        +  Getsuffix(csq.EventDate.Value.Day)
        + csq.EventDate.Value.ToString("MMM")
        + " " + csq.EventDate.Value.Year
        + " at " + eventTime.ToString("hh:mm tt"), textFont7);
PdfPCell cellt2 = new PdfPCell(ph102);

Posted on StackOverflow on May 19, 2015 by Dhasarathan T

When I read your question, I assume that you want something like this:


Please check OrdinalNumbers example. Here is a peace of code and you see that what you call "sup" is done by using a smaller font and a text rise:

PdfFont small = PdfFontFactory.createFont(FontConstants.HELVETICA);
Text st = new Text("st").setFont(small).setTextRise(7).setFontSize(6);
Text nd = new Text("nd").setFont(small).setTextRise(7).setFontSize(6);
Text rd = new Text("rd").setFont(small).setTextRise(7).setFontSize(6);
Text th = new Text("th").setFont(small).setTextRise(7).setFontSize(6);

Paragraph first = new Paragraph()
        .add("The 1")
        .add(" of May");
Paragraph second = new Paragraph()
        .add("The 2")
        .add(" and the 3")
        .add(" of June");
Paragraph fourth = new Paragraph()
        .add("The 4")
        .add(" of July");

In the 5th version of iText we used Chunk class instead of Text, but it doesn't exist anymore.

Click this link if you want to see how to answer this question in iText 5.