Digital Marriage Invitation Card

iText API- Add Bullets in Unordered List PDF using Java


In the previous iText tutorials, you have seen how to add ORDERED and UNORDERED list in the PDF document. While creating the UNORDERED list you have noticed that there is DASH (-) that indicates all the list data.

But in this example, we will add the BULLETS instead of DASH to indicate the UNORDERED list data. List class has a method setListSymbol() for setting the symbol of the UNORDERED list.

Similar Post: iText API- Ordered and Unordered List Example in Java

Steps to add bullets in Unordered List

Using Chunk and Font class u you have control of width and height of bullets.

Font zapfdingbats = new Font();
Chunk bullet = new Chunk("\u2022", zapfdingbats);
list.setListSymbol(bullet);

Or directly use Unicode of bullet.

list.setListSymbol("\u2022");

Or paste the bullets.

list.setListSymbol("•");

Check the Full Example

BulletedUnorderedListExample.java
package org.websparrow.itext;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class BulletedUnorderedListExample {
	public static void main(String[] args) throws FileNotFoundException, DocumentException {

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

		Paragraph paragraph = new Paragraph("Unordered list has been created - WebSparrow.org\n");
		document.add(paragraph);

		Font zapfdingbats = new Font();
		Chunk bullet = new Chunk("\u2022", zapfdingbats);

		List list = new List(List.UNORDERED);

		list.setListSymbol(bullet);

		list.add(new ListItem("Apple"));
		list.add(new ListItem("Google"));
		list.add(new ListItem("Microsoft"));
		list.add(new ListItem("Facebook"));

		document.add(list);
		document.close();

		System.out.println("List Created Successfully...");
	}
}

Output :

iText API- Add Bullets in Unordered List PDF using Java

Share this article on: