Criando um rodapé em uma documento PDF com o iText

3 respostas
G

Sou iniciante no iText. Estou tentando criar um rodapé em um documento PDF. Ele teria uma imagem alinha a esquerda e a data de geração do documento centralizado. Estava pensando em inserir uma tabela no rodapé com a imagem em uma celula e o texto em outra. Alguém poderia me dar uma ajuda?

3 Respostas

T

Coloque esta tabela no evento onEndPage… se tiver um cabeçalho tb deverá ficar neste evento…
ele se encarrega de replicar o conteúdo em todas as páginas… =]

G

Obrigado tyemy. Deu certo, pesquisei por esse evento e achei esse tutorial la na página do iText:

[url]http://itextdocs.lowagie.com/tutorial/directcontent/pageevents/index.php[/url]
[url]http://itextdocs.lowagie.com/examples/com/lowagie/examples/directcontent/pageevents/EndPage.java[/url]

Fiz uma tabela e mandei inserir no final da página.

public void onEndPage(PdfWriter writer, Document document) {

		try {

			Rectangle page = document.getPageSize();
			/*
			 * PdfPTable head = new PdfPTable(3); for (int k = 1; k <= 6; ++k)
			 * head.addCell("head " + k); head.setTotalWidth(page.getWidth() -
			 * document.leftMargin() - document.rightMargin());
			 * head.writeSelectedRows(0, -1, document.leftMargin(),
			 * page.getHeight() - document.topMargin() + head.getTotalHeight(),
			 * writer.getDirectContent());
			 */

			PdfPTable foot = new PdfPTable(3);
			image.scalePercent(50, 50);

			PdfPCell cell = new PdfPCell(image);

			cell.setBorder(0);
			cell.setHorizontalAlignment(Element.ALIGN_LEFT);
			cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
			foot.addCell(cell);

			DateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
			Date data = new Date();

			cell = new PdfPCell(new Phrase(sf.format(data)));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell.setBorder(0);
			foot.addCell(cell);

			cell = new PdfPCell(new Phrase(""));
			cell.setBorder(0);
			foot.addCell(cell);

			foot.setTotalWidth(page.getWidth() - document.leftMargin()
					- document.rightMargin());
			foot.writeSelectedRows(0, -1, document.leftMargin(), document
					.bottomMargin(), writer.getDirectContent());

		} catch (Exception e) {
			throw new ExceptionConverter(e);
		}

	}
T

:smiley:

Criado 23 de setembro de 2009
Ultima resposta 24 de set. de 2009
Respostas 3
Participantes 2