Java: Créer une table dans un document PDF

Author:

Java: Créer une table dans un document PDF
Download

/***** Code de MesExemples.com *******/
/**
 * @(#)PDFTable.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/5/29
 */
 
 
 
import java.io.FileOutputStream;
 
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
 
public class PDFTable {
  public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {
      PdfWriter writer = PdfWriter.getInstance(document,  
      	new FileOutputStream("c:/PDFTable.pdf"));
 
      document.open();
      // créer une table
      PdfPTable table = new PdfPTable(3);
      // Créer une cellule
      PdfPCell cell = new PdfPCell(new Paragraph("header de la table"));
      cell.setColspan(3);
      // Ajouter la cellule dans la table
      table.addCell(cell);
      // Modifier l'alignement
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
      document.add(table);
 
 
    } catch (Exception de) {
      de.printStackTrace();
    }
    document.close();
  }
}

Cet article Java: Créer une table dans un document PDF est apparu en premier sur .