
{filelink=10608}
/***** Code de MesExemples.com *******/
/**
* @(#)ExempleTableCellAlignment.java
*
*
* @author
*sakoba(java.mesexemples.com) @version 1.00 2013/5/29
*/
import java.io.FileOutputStream;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
public class ExempleTableCellAlignment {
public static void main(String[] args) {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
PdfWriter pdf_writer = PdfWriter.getInstance(document,
new FileOutputStream("c:/ExempleTableCellAlignment.pdf"));
document.open();
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
// Aligner horizontalement au centre
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
// Aligner horizontalement au centre
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
table.getDefaultCell().setFixedHeight(70);
table.addCell("!");
table.addCell("Texte Texte Texte Texte Texte Texte ");
table.addCell(new Phrase(new Chunk("cell")));
table.addCell("Texte Texte ");
table.addCell(new Phrase(new Chunk("cell")));
table.addCell("Texte Texte Texte ");
table.addCell(new Phrase(new Chunk("cell")));
table.addCell("Texte Texte Texte ");
table.addCell(new Phrase(new Chunk("cell")));
table.addCell("Texte ");
table.addCell(new Phrase(new Chunk("cell")));
table.addCell("Texte ");
table.addCell(new Phrase(new Chunk("cell")));
table.addCell("Texte ");
table.addCell(new Phrase(new Chunk("cell")));
document.add(table);
} catch (Exception de) {
de.printStackTrace();
}
document.close();
}
}