Skip to main content
Skip table of contents

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:


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 piece 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 How to introduce superscript? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.