Java Examples - Add List in a PDF


Advertisements


Problem Description

How to add list in a PDF using Java.

Solution

Following is the program to add list in a PDF using Java.

import com.itextpdf.kernel.pdf.PdfDocument; 
import com.itextpdf.kernel.pdf.PdfWriter; 

import com.itextpdf.layout.Document; 
import com.itextpdf.layout.element.List; 
import com.itextpdf.layout.element.Paragraph;  

public class AddingList { 
   public static void main(String args[]) throws Exception {     
      
      //Creating a PdfWriter 
      String dest = "C:/itextExamples/addngList.pdf"; 
      PdfWriter writer = new PdfWriter(dest); 

      //Creating a PdfDocument 
      PdfDocument pdf = new PdfDocument(writer); 

      //Creating a Document  
      Document document = new Document(pdf); 

      //Creating a Paragraph 
      Paragraph paragraph = new Paragraph("Tutorials Point provides the following tutorials"); 

      //Creating a list  
      List list = new List();  
      
      //Add elements to the list 
      list.add("Java"); 
      list.add("JavaFX"); 
      list.add("Apache Tika");
      list.add("OpenCV"); 
      list.add("WebGL"); 
      list.add("Coffee Script"); 
      list.add("Java RMI"); 
      list.add("Apache Pig"); 

      //Adding paragraph to the document 
      document.add(paragraph); 

      //Adding list to the document 
      document.add(list); 

      //Closing the document 
      document.close(); 
      System.out.println("List added"); 
   } 
}

Output

Adding List
java_itext

Advertisements