How to write superscript text example in PDF using java iText library

In this tutorial you will learn to add the superscript text in any paragraph or chunk of PDF document. The superscript text represents a character or text that is half the height of a normal character and printed at the top middle of the normal characters. The superscript text should be halfway above the normal text.

Please note we are using the iText version 5 for this example.

You can see in the below example that normal text can be created by Chunk element. For super script text you can create the text using Chunk element with setting rise value as positive in method setTextRise();

Below is example of code which generates the PDF document with superscript text.

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfWriter;
public class PDFSuperScriptExample {
    public static void main(String[] args) throws FileNotFoundException, DocumentException {
        // Create new PDF document
        Document document = new Document();
        // Create an output stream of PDF file.
        OutputStream out = new FileOutputStream("PDF_Super_Script_Example.pdf");
        // Get a PdfWriter instance to write in PDF document.
        PdfWriter.getInstance(document, out);
        // Open the PDF document;
        // Create a chunk of text with normal Text rise.
        Chunk normalText = new Chunk("This is normal text.");
        // Add the normal text to PDF document.
        // Create a another Chunk of text with text rise of 6f
        Chunk superScript = new Chunk("This is Superscript");
        // Add the supre script to PDF document
        //Close the PDF documetn after use.

The generated PDF document looks like below screen.