iText

How to introduce superscript?

How do I format dates so that the "th" in 14th or "rd" in 3rd is in superscript?

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:

C#
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:

Superscript

Superscript

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

Java
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(st)
        .add(" of May");
document.add(first);
Paragraph second = new Paragraph()
        .add("The 2")
        .add(nd)
        .add(" and the 3")
        .add(rd)
        .add(" of June");
document.add(second);
Paragraph fourth = new Paragraph()
        .add("The 4")
        .add(th)
        .add(" of July");
document.add(fourth);

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

Click How to introduce superscript? | iText 5 PDF Development Guide if you want to see how to answer this question in iText 5.