728x90 AdSpace

Sunday, 28 May 2017

iText 5 PDF - List Leading space Example

To create PDF file we need iText 5 jar. Download iText Jars from iText Website or Maven Repository

Maven Dependency



 com.itextpdf
 itextpdf
 5.5.11

ListWithLeading.java
package com.javatutorialcorner.itextpdf;

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ListWithLeading {
 
  public static final String DEST = "C:/JTC/ListWithLeading.pdf";
 
    public static void main(String[] args) throws IOException,
            DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new ListWithLeading().createPdf(DEST);
    }
 
    public void createPdf(String dest) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();
        Font font = new Font(FontFamily.HELVETICA, 12);
        List list1 = new List(12);
        list1.setListSymbol("\u2022");
        list1.add(new ListItem("Value 1", font));
        list1.add(new ListItem("Value 2", font));
        list1.add(new ListItem("Value 3", font));
        document.add(list1);
        List list2 = new List(12);
        list2.setListSymbol("\u2022");
        list2.add(new ListItem(30, "Value 1", font));
        list2.add(new ListItem(30, "Value 2", font));
        list2.add(new ListItem(30, "Value 3", font));
        list2.setIndentationLeft(60);
        document.add(list2);
        document.close();
    }
}

Output

Reference : iText Website
Annamalai Thangaraj

Annamalai is working as Technical Lead in Leading Telecom company with 5+ years experience in Identity and Access Management , Telecom and Networks, BigData, Java, Spring, Struts, Hibernate, AngularJS, and Enterprise Web Application Development.

Website: Java Tutorials Corner

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: iText 5 PDF - List Leading space Example Rating: 5 Reviewed By: Annamalai Thangaraj