In this core java tutorial we will learn How To Set SuperScript And SubScript In Pdf in java using iText library - core java tutorial with program and examples.
Follow these steps to Set SuperScript And SubScript In Pdf in java using iText library >
- Superscript > Create Chunk (com.itextpdf.text.Chunk), use constructor and pass the text which you want to be superscript.
- Now, use setTextRise method of Chunk and pass POSITIVE number in setTextRise method to set the superscript.
superScript.setTextRise(6f)
- Subscript > Create Chunk (com.itextpdf.text.Chunk), use constructor and pass the text which you want to be subscript.
- Now, use setTextRise method of Chunk and pass NEGATIVE number in setTextRise method to set the subscript.
superScript.setTextRise(-6f)
How to Set the Font Name, Size, Style and Colour In Pdf using itext in java
How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial
Convert Html To Pdf in java using iText - iText java tutorial
How To Set Header and Footer in pdf in java using Itext Example - iText java tutorial
Download jars required to execute program >
Program/Example 1 How To Set SuperScript And SubScript In Pdf in java - Using iText library
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
* How To Set SuperScript And SubScript In Pdf Using Itext Example -
* Using iText library - core java tutorial
*
*/
public class SuperScriptAndSubScriptInPdfUsingItextExample {
public static void main(String[] args) {
try {
String pdfFilePath = "e:/SuperScript And SubScript in Pdf Using Itext Example.pdf";
OutputStream fos = new FileOutputStream(new File(pdfFilePath));
Document document = new Document();
PdfWriter.getInstance(document, fos);
document.open();
document.add(new Paragraph(
"This is SuperScript And SubScript Example"));
document.add(new Phrase("Add SuperScript > "));
// Create SuperScript
Chunk superScript = new Chunk("This is Superscript");
superScript.setTextRise(6f); //Pass POSITIVE number in setTextRise method
document.add(superScript);
document.add(new Phrase("\nAdd SubScript > "));
// Create SubScript
Chunk subScript = new Chunk("This is Subscript");
subScript.setTextRise(-6f); //Pass NEGATIVE number in setTextRise method
document.add(subScript);
document.close();
fos.close();
System.out.println("PDF created in >> " + pdfFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/* OUTPUT of above program/Example -
PDF created in >> e:/SuperScript And SubScript in Pdf Using Itext Example.pdf
*/
|
PDF formed after executing above java program will look like this >
Program/Example 2 How To Set SuperScript And SubScript In Pdf in java - Using iText library
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfWriter;
/**
*
* How To Set SuperScript And SubScript In Pdf Using Itext Example -
* Using iText library - core java tutorial
*
*/
public class SuperScriptAndSubScriptInPdfUsingItextExample2 {
public static void main(String[] args) {
try {
String pdfFilePath = "e:/SuperScript And SubScript in Pdf Using Itext Example2.pdf";
OutputStream fos = new FileOutputStream(new File(pdfFilePath));
Document document = new Document();
PdfWriter.getInstance(document, fos);
document.open();
document.add(new Paragraph(
"This is SuperScript And SubScript Example"));
document.add(new Chunk("2"));
// Create SuperScript
Chunk superScript = new Chunk("3");
superScript.setTextRise(6f); //Pass POSITIVE number in setTextRise method
document.add(superScript);
document.add(new Chunk(" = 8"));
document.add(new Phrase("\nAdd SubScript > "));
// Create SubScript
Chunk subScript = new Chunk("This is Subscript");
subScript.setTextRise(-6f); //Pass NEGATIVE number in setTextRise method
document.add(subScript);
document.close();
fos.close();
System.out.println("PDF created in >> " + pdfFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/* OUTPUT of above program/Example -
PDF created in >> e:/SuperScript And SubScript in Pdf Using Itext Example2.pdf
*/
|
PDF formed after executing above java program will look like this >
Summary -
So in this core java tutorial we learned How To Set SuperScript And SubScript In Pdf in java using iText library - core java tutorial with program and examples.
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
References >
RELATED LINKS>
iText library tutorial in java - How to Create and work with PDF files in java
Creating the Table and set the Column Width And Spacing In Pdf in java
Rotate cells, cell padding, horizontal and vertical alignment of Cell in table in Pdf in java itext - iText java tutorial example
Creating LIST in pdf in java - iText tutorial >
Create Greek List In pdf in java using iText - iText java tutorial
How to Create Roman List In pdf in java - iText java tutorial
Create ZapfDingbats List In pdf in java - iText java tutorial program
How to Create Ordered List In pdf in java using iText - iText java tutorial
Creating the UnOrdered List In pdf in java - iText java tutorial example
How to Create Lists And SubLists In Pdf in java - iText java tutorial
Creating PASSWORD PROTECTED PDF in java - iText tutorial >
How to Create Password Protected Pdf in java - iText Example
Set FONT NAME, SIZE, STYLE, COLOUR in pdf in java - iText tutorial >
How to Set the Font Name, Size, Style and Colour In Pdf using itext in java
Create ANCHOR (HYPERLINK), SUPERSCRIPT, SUBSCRIPT, UNDERLINE AND STRIKETHROUGH in pdf in java - iText tutorial >
How To Set HyperLink (Anchor - a tag) In Pdf in java - iText java tutorial
How To Set SuperScript And SubScript In Pdf in java - iText java tutorial
UnderLine Text In Pdf in java - iText java tutorial example
Strikethrough Text In Pdf in java - iText java tutorial program
HTML to PDF in java - iText tutorial >
Convert Html To Pdf in java using iText - iText java tutorial
Create new page, set page height and width in java - iText tutorial >
How To Create New Pages In Pdf Using Itext - iText java tutorial example
How to Find Pdf Page Height And Width in java - iText java tutorial program
Labels:
Core Java
iText Pdf tutorial