Olá pessoal, estou utilizando o iText para um pequeno trabalho na faculdade e estou com o seguinte problema:
crio um objeto Document e adiciono uma tabela. O formato de página do documento é A4 e a tabela fica pequena demais e centralizada na página. Como faço para que a tabela ocupe toda a largura da página e centralize o conteúdo de suas células no canto inferior esquerdo?
Ajuda no iText
1 Resposta
vou te mandar um exemplo de como fazer essas coisas:
Vê se te ajuda! Flw! :thumbup:
public class TabelaSimples {
public void gerarArquivoPdf() throws Exception {
Document documento = getDocument("Juliano Alves", "Tabela Simples", false);
PdfWriter writer = PdfWriter.getInstance(documento, new FileOutputStream("TabelaSimples.pdf"));
documento.open();
Table table = new Table(4);
table.setWidth(100); // Porcentagem de largura da página
//table.setBorder(Rectangle.NO_BORDER);
int[] a = {30, 30, 20, 20}; // Porcentagens
table.setWidths(a);
createPdfCell(table, "Nome", Cell.ALIGN_CENTER, 1, 1, true, 12);
createPdfCell(table, "Email", Cell.ALIGN_CENTER, 1, 1, true, 12);
createPdfCell(table, "Tel.", Cell.ALIGN_CENTER, 1, 1, true, 12);
createPdfCell(table, "Cel.", Cell.ALIGN_CENTER, 1, 1, true, 12);
createPdfCell(table, "José da Silva", Cell.ALIGN_LEFT, 1, 1, false, 10);
createPdfCell(table, "[email removido]", Cell.ALIGN_LEFT, 1, 1, false, 10);
createPdfCell(table, "([telefone removido]", Cell.ALIGN_CENTER, 1, 1, false, 10);
createPdfCell(table, "([telefone removido]", Cell.ALIGN_CENTER, 1, 1, false, 10);
createPdfCell(table, "Antônio Paiva", Cell.ALIGN_LEFT, 1, 1, false, 10);
createPdfCell(table, "[email removido]", Cell.ALIGN_LEFT, 1, 1, false, 10);
createPdfCell(table, "([telefone removido]", Cell.ALIGN_CENTER, 1, 1, false, 10);
createPdfCell(table, "([telefone removido]", Cell.ALIGN_CENTER, 1, 1, false, 10);
createPdfCell(table, "Tatiana Tomaz", Cell.ALIGN_LEFT, 1, 1, false, 10);
createPdfCell(table, "[email removido]", Cell.ALIGN_LEFT, 1, 1, false, 10);
createPdfCell(table, "([telefone removido]", Cell.ALIGN_CENTER, 1, 1, false, 10);
createPdfCell(table, "([telefone removido]", Cell.ALIGN_CENTER, 1, 1, false, 10);
documento.add(table);
documento.close();
}
public void createPdfCell(Table table, String content, int aligment,
int colspan, int rowspan, boolean bold, int fontSize)
throws Exception {
Cell cell = null;
if (bold)
cell = new Cell(new Phrase(content, FontFactory.getFont(
FontFactory.HELVETICA, fontSize, Font.BOLD)));
else
cell = new Cell(new Phrase(content, FontFactory.getFont(
FontFactory.HELVETICA, fontSize, Font.NORMAL)));
cell.setHorizontalAlignment(aligment);
//cell.setBorder(Rectangle.NO_BORDER);
cell.setColspan(colspan);
cell.setRowspan(rowspan);
table.addCell(cell);
}
public Document getDocument(String autor, String titulo, boolean landscape) {
Document documento = null;
if (landscape)
documento = new Document(PageSize.A4.rotate(), 30, 30, 30, 30);
else
documento = new Document(PageSize.A4, 30, 30, 30, 30);
documento.addAuthor(autor);
documento.addTitle(titulo);
return documento;
}
public static void main(String[] args) {
try {
new TabelaSimples().gerarArquivoPdf();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Criado 5 de dezembro de 2007
Ultima resposta 5 de dez. de 2007
Respostas 1
Participantes 2