Example #1
0
    // Evento cuando que se ejecuta al terminar una página
    @Override
    public void onEndPage(PdfWriter writer, Document document) {
      // Creamos una tabla de dos culumnas
      PdfPTable table = new PdfPTable(2);
      table.setHorizontalAlignment(Element.ALIGN_CENTER);

      try {
        // Establecemos las medidas de la tabla
        table.setWidths(new int[] {24, 10});
        table.setTotalWidth(100);
        // Establecemos la altura de la celda
        table.getDefaultCell().setFixedHeight(20);
        // Quitamos el borde
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        // Alineamos el contenido a la derecha
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        // Escribimos el primer texto
        // en la primera celda
        table.addCell(String.format("Página %d de ", writer.getCurrentPageNumber()));
        // Obtenemos el template total
        // y lo agregamos a la celda
        PdfPCell cell = new PdfPCell(Image.getInstance(total));
        // quitamos el borde
        cell.setBorder(Rectangle.NO_BORDER);
        // lo agregamos a la tabla
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 330, 40, writer.getDirectContent());
      } catch (DocumentException de) {
        throw new ExceptionConverter(de);
      }
    }