Digital Marriage Invitation Card

iText API- Roman and Greek List Example


This tutorial will explain about how you will add a Roman and Greek list in pdf document using iText API and Java.

To work with these type of list iText provide the RomanList and GreekList class.

Roman List Example

Create the object of RomanList then call the add() method to add the list item.

RomanListExample.java
package org.websparrow.itext;

import java.io.FileOutputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.RomanList;
import com.itextpdf.text.pdf.PdfWriter;

public class RomanListExample {
	public static void main(String[] args) {
		try {

			Document document = new Document();
			PdfWriter.getInstance(document, new FileOutputStream("iText/romanlist.pdf"));
			document.open();

			RomanList romanList = new RomanList();
			romanList.add(new ListItem("Computer"));
			romanList.add(new ListItem("Mouse"));
			romanList.add(new ListItem("Printer"));
			romanList.add(new ListItem("Keyboard"));
			romanList.add(new ListItem("CPU"));
			romanList.add(new ListItem("Monitor"));

			document.add(romanList);
			document.close();

			System.out.println("Done");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Output:

iText API- Roman and Greek List Example

Greek List Example

Similarly, create the object of GreekList then calls the add() method to add the list item.

GreekListExample.java
package org.websparrow.itext;

import java.io.FileOutputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.GreekList;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.pdf.PdfWriter;

public class GreekListExample {
	public static void main(String[] args) {
		try {

			Document document = new Document();
			PdfWriter.getInstance(document, new FileOutputStream("iText/greeklist.pdf"));
			document.open();

			GreekList greekList = new GreekList();
			greekList.add(new ListItem("Computer"));
			greekList.add(new ListItem("Mouse"));
			greekList.add(new ListItem("Printer"));
			greekList.add(new ListItem("Keyboard"));
			greekList.add(new ListItem("CPU"));
			greekList.add(new ListItem("Monitor"));

			document.add(greekList);
			document.close();

			System.out.println("Done");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Output:

iText API- Roman and Greek List Example

Share this article on: