import java.awt.Color;
import java.io.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class testPointille {
    
    public static void main(String[] args) {
        // creation of the document with a certain size and certain margins
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test Pointille.pdf"));
		document.open();
		BaseFont bf = BaseFont.createFont("Helvetica", "Cp1252", false);
 		Font font = new Font(bf, 15);
               
               
               //create a Table 					
 		Table table = new Table(3);
 		table.setBorderWidth(1);
 		table.setBorderColor(new Color(0, 0, 255));
 		table.setCellpadding(5);
 		table.setCellspacing(5);
 		Cell cell = new Cell(new Phrase(new Chunk("example cell with colspan 1 and rowspan 2",font)));
 		cell.setRowspan(2);
 		cell.setBorderColor(new Color(255, 0, 0));
 		table.addCell(cell);
 		
 		
 		cell = new Cell(testPointille.ajoutPetitPoint(cell, "1.1", bf, font));
 		table.addCell(cell);
 		
 		cell = new Cell(testPointille.ajoutPetitPoint(cell, "2.1", bf, font));
 		table.addCell(cell);
 		
 		cell = new Cell(testPointille.ajoutPetitPoint(cell, "1.2", bf, font));
 		table.addCell(cell);
 		
 		cell = new Cell(testPointille.ajoutPetitPoint(cell, "2.2", bf, font));
 		table.addCell(cell);
 		
		document.add(table);
		document.close();
        }
        catch (Exception de) {
            de.printStackTrace();
        }
    }
    
    public static Phrase ajoutPetitPoint (Cell cellule, String text, BaseFont bf, Font font){
    	// add "..." to the string text
    	
    	float longText = bf.getWidthPoint(text, font.size());
    	float longCell = longText+ 100f;//cellule.width();
    	
    	float longPoint = bf.getWidthPoint(".", font.size());
    	
    	System.err.println(" longText :"+longText+"\n longCell :"+longCell+"\n longPoint :"+longPoint+"\n----------------------------------");
    	int nbpoint  = (int)((longCell - longText) / longPoint);
    	
    	String chaine="";
    	for (int i=0; i<nbpoint; i++){
    		chaine = chaine + ".";
    	}
    	Phrase retour =  new Phrase (text+chaine);
    	return retour;
    }	
}

