Example usage for com.itextpdf.text.pdf PdfPTable setLockedWidth

List of usage examples for com.itextpdf.text.pdf PdfPTable setLockedWidth

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setLockedWidth.

Prototype

public void setLockedWidth(final boolean lockedWidth) 

Source Link

Document

Uses the value in setTotalWidth() in Document.add().

Usage

From source file:be.rheynaerde.poolsheets.ClubPoolSheet.java

License:Open Source License

@Override
protected void buildTable(Document document) throws DocumentException {
    int columnCount = configuration.getNrOfPlayers() + configuration.getSummaryColumnCount() + 3;
    int nameCellWidth = 5;

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth(// w  w w . ja  va 2 s. c  o  m
            (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount())
                    * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    widths[0] = 1f * nameCellWidth;
    for (int i = 1; i < widths.length; i++) {
        widths[i] = 1f;
    }
    widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f;
    table.setWidths(widths);

    PdfPCell cell = new PdfPCell(new Paragraph(configuration.getTitle(), configuration.getTitleFont()));
    cell.setColspan(columnCount);
    cell.setPaddingBottom(configuration.getSquareCellSize() / 2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    {
        table.addCell(getHeaderCell(bundle.getString("name")));
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int i = 0; i < configuration.getSummaryColumnCount(); i++) {
            table.addCell(getHeaderCell(configuration.getSummaryColumnName(i)));
        }
    }

    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1));
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < i; j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result));
            resultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(resultCell);
        }
        table.addCell(getSolidCell());
        for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell resultCell = new PdfPCell(new Phrase(result == null ? "" : result));
            resultCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            resultCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(resultCell);
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int j = 0; j < configuration.getSummaryColumnCount(); j++) {
            String result = configuration.getSummaryColumnValue(i + 1, j);
            PdfPCell summaryCell = new PdfPCell(new Phrase(result == null ? "" : result));
            summaryCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            summaryCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(summaryCell);
        }
    }

    document.add(table);
}

From source file:be.rheynaerde.poolsheets.PufCompletePoolSheet.java

License:Open Source License

@Override
protected PdfPTable getScoreTable() throws DocumentException {
    final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2;
    //one column for each player, an extra column for the numbers and a column for the team marks

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;/*from  w  w  w. ja  v a 2s.  c  om*/
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1)));
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2)));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
        if (i == configuration.getNrOfPlayers(1))
            table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM,
                    configuration.getNrOfPlayers(2), 1));

        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); j++) {
            if (i == j) {
                PdfPCell blackCell = getSolidCell();
                table.addCell(blackCell);
            } else {
                table.addCell(configuration.getResult(i, j));
            }
        }
    }

    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.PufSingleTeamPoolSheet.java

License:Open Source License

@Override
protected PdfPTable getScoreTable() throws DocumentException {
    final int columnCount = configuration.getNrOfPlayers() + 2;

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;/*  w w w  .j  a va2s. c o  m*/
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers()));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(); j++) {
            if (i == j) {
                PdfPCell blackCell = getSolidCell();
                table.addCell(blackCell);
            } else {
                table.addCell(configuration.getResult(i, j));
            }
        }
    }

    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.PufTeamPoolSheet.java

License:Open Source License

protected PdfPTable getScoreTable() throws DocumentException {
    //table for scores
    final int columnCount = configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2) + 2;
    //one column for each player, an extra column for the numbers and a column for the team marks

    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setTotalWidth((columnCount) * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;/*from   ww w  .  jav a 2 s  .  c  om*/
    }
    table.setWidths(widths);

    PdfPCell topCell = getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, 2);
    topCell.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(topCell);
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(1)));
    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.RIGHT, 1, configuration.getNrOfPlayers(2)));

    table.addCell(getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, 1, 1));
    {
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(1) + configuration.getNrOfPlayers(2); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(1), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(1); i++) {
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        if (i == 0) {
            PdfPCell blackCell = getSolidCell();
            blackCell.setColspan(configuration.getNrOfPlayers(1));
            blackCell.setRowspan(configuration.getNrOfPlayers(1));
            table.addCell(blackCell);
        }
        for (int j = 0; j < configuration.getNrOfPlayers(2); j++) {
            table.addCell(configuration.getResult(0, i, 1, j));
        }
    }

    table.addCell(
            getCellWithBorder(table.getDefaultCell(), Rectangle.BOTTOM, configuration.getNrOfPlayers(2), 1));
    for (int i = 0; i < configuration.getNrOfPlayers(2); i++) {
        table.addCell(getHeaderCell(Integer.toString(configuration.getNrOfPlayers(1) + i + 1)));
        for (int j = 0; j < configuration.getNrOfPlayers(1); j++) {
            table.addCell(configuration.getResult(1, i, 0, j));
        }
        if (i == 0) {
            PdfPCell blackCell = getSolidCell();
            blackCell.setColspan(configuration.getNrOfPlayers(2));
            blackCell.setRowspan(configuration.getNrOfPlayers(2));
            table.addCell(blackCell);
        }
    }
    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return table;
}

From source file:be.rheynaerde.poolsheets.StandardPoolSheet.java

License:Open Source License

protected void buildTable(Document document) throws DocumentException {
    int columnCount = 1 + 1 + configuration.getNrOfPlayers() + 1 + configuration.getSummaryColumnCount();
    // name + number + scores + spacer 
    //    + summary
    PdfPTable table = new PdfPTable(columnCount);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

    table.setTotalWidth((configuration.getNrOfPlayers() + 7 //the name column + extra space between grid and summary
                                                            //currently the name column just gets a width that is
                                                            //a multiple of the width of the other cells. Better
                                                            //would be to let this cell take up the remaining space.
            + configuration.getSummaryColumnCount()) * configuration.getSquareCellSize());
    table.setLockedWidth(true);
    float[] widths = new float[columnCount];
    widths[0] = 5f;/*from  w  w  w  .j  a  v a  2 s  . co  m*/
    for (int i = 1; i < widths.length; i++) {
        widths[i] = 1f;
    }
    widths[widths.length - 1 - configuration.getSummaryColumnCount()] = 0.1f;
    table.setWidths(widths);

    {
        table.addCell(getHeaderCell(bundle.getString("name")));
        table.addCell(getSolidCell());
        for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
            table.addCell(getHeaderCell(Integer.toString(i + 1)));
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int i = 0; i < configuration.getSummaryColumnCount(); i++) {
            table.addCell(getHeaderCell(configuration.getSummaryColumnName(i)));
        }
    }

    for (int i = 0; i < configuration.getNrOfPlayers(); i++) {
        table.addCell(configuration.getNamePlayer(i + 1) == null ? "" : configuration.getNamePlayer(i + 1));
        table.addCell(getHeaderCell(Integer.toString(i + 1)));
        for (int j = 0; j < i; j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        table.addCell(getSolidCell());
        for (int j = i + 1; j < configuration.getNrOfPlayers(); j++) {
            String result = configuration.getResult(i + 1, j + 1);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        table.addCell(new PdfPCell()); //spacer column
        for (int j = 0; j < configuration.getSummaryColumnCount(); j++) {
            String result = configuration.getSummaryColumnValue(i + 1, j);
            PdfPCell cell = new PdfPCell(new Phrase(result == null ? "" : result));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }
    }
    document.add(table);
}

From source file:beans.ManagedBeanReportes.java

public void inventario() throws DocumentException, IOException {
    FacesContext facexcontext = FacesContext.getCurrentInstance();
    ValueExpression vex = facexcontext.getApplication().getExpressionFactory()
            .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class);
    ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext());

    FacesContext context = FacesContext.getCurrentInstance();

    Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft,   int marginRight,   int marginTop,   int marginBottom

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setPageEvent(new ManagedBeanReportes.Watermark(""));
    if (!document.isOpen()) {
        document.open();/*w ww .j av  a  2  s. com*/
    }

    try {

        ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
        //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png");
        //Image welladigital = Image.getInstance(imageUrl1);
        //welladigital.setAbsolutePosition(377f, 760f);
        //welladigital.scalePercent(40);
        //document.add(welladigital);

        //crear tabla PARA NOMBRE DEL AO
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        // table.setTotalWidth(540f);
        table.setLockedWidth(true);
        float[] headerWidths = { 120, 20, 310 };
        table.setWidths(headerWidths);
        table.getDefaultCell();

        SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY");
        StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio));

        Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12);
        underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location
        PdfPCell table5 = new PdfPCell(new Paragraph(underline));
        table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table5.setColspan(3);
        table5.setBorder(Rectangle.NO_BORDER);
        table.addCell(table5);

        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        PdfPCell table2 = new PdfPCell();

        table2 = new PdfPCell(
                new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont));
        table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table2.setColspan(3);
        table2.setBorder(Rectangle.NO_BORDER);
        table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        table.setLockedWidth(true);
        table.setWidths(headerWidths);
        table.getDefaultCell();
        table.addCell(table2);
        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda()));
        formato = new SimpleDateFormat("yyyy-MM-dd");
        cadena = new StringBuilder(formato.format(fecha_inicio));

        //document.add(traerSubtabla02(cadena.toString()));
        document.add(new Paragraph("\n", pequeFont));
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String ctxPath = ((ServletContext) ctx.getContext()).getContextPath();
        document.close();
        formato = new SimpleDateFormat("dd_MM_yyyy");
        cadena = new StringBuilder(formato.format(fecha_inicio));
        String fileName = cadena.toString();

        writePDFToResponse(context.getExternalContext(), baos, fileName);
        context.responseComplete();

    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:beans.ManagedBeanReportes.java

public PdfPTable traerSubtabla(Tienda t) throws DocumentException {
    PdfPTable tabla_PesajeDetalle = new PdfPTable(4);
    tabla_PesajeDetalle.setWidthPercentage(100);
    tabla_PesajeDetalle.setTotalWidth(450f);
    tabla_PesajeDetalle.setLockedWidth(true);

    tabla_PesajeDetalle.setWidths(anchocol03);
    tabla_PesajeDetalle.getDefaultCell();

    PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);

    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) {
        tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto()));
        String ubicaciones_ = "";
        for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t,
                det.getProducto())) {//from  ww  w  .ja  va 2  s.  com
            if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) {
                ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_;
            }
        }
        tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock())));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad())));
    }
    return tabla_PesajeDetalle;
}

From source file:cl.preguntame.clases.Cabecera.java

/**
 * Esta es el metodo a llamar cuando ocurra el evento onEndPage, es en este
 * evento donde crearemos el encabeazado de la pagina con los elementos
 * indicados./*from w  w  w.j ava2  s  .c  o m*/
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        // Se determina el ancho y altura de la tabla 
        table.setWidths(new int[] { 24, 24, 2 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);

        // Borde de la celda
        table.getDefaultCell().setBorder(Rectangle.BOTTOM);

        table.addCell(encabezado);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

        table.addCell(String.format("Pagina % 01d de ", writer.getPageNumber()));

        PdfPCell cell = new PdfPCell(Image.getInstance(total));

        cell.setBorder(Rectangle.BOTTOM);

        table.addCell(cell);
        // Esta linea escribe la tabla como encabezado
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}

From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java

License:Apache License

/**
 * header ? footer  //  w  ww  . j  ava  2  s  .c  om
 */
public void onEndPage(PdfWriter writer, Document document) {

    if (titleFlag)
        return;

    Font font = new Font(bfKorean, 9);
    PdfPTable hTable = new PdfPTable(1);
    PdfPTable ftable = new PdfPTable(3);
    try {

        hTable.setWidths(new int[] { 100 });
        hTable.setTotalWidth(500);
        hTable.setLockedWidth(true);
        hTable.getDefaultCell().setFixedHeight(15);
        hTable.getDefaultCell().setBorder(Rectangle.BOTTOM);
        hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font));
        hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent());

        ftable.setWidths(new int[] { 100, 100, 100 });
        ftable.setTotalWidth(500);
        ftable.setLockedWidth(true);
        ftable.getDefaultCell().setBorder(Rectangle.TOP);
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font));
        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        if (pagingFlag)
            ftable.addCell(new Phrase(
                    MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())),
                    font));
        else
            ftable.addCell("");

        ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font));
        ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent());
    } catch (Exception de) {
        throw new ExceptionConverter(de);
    }
}

From source file:com.automaster.autoview.server.servlet.TableHeader.java

/**
 * Adds a header to every page/*from  ww w  . jav  a 2  s  .co m*/
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable table = new PdfPTable(3);
    try {
        table.setWidths(new int[] { 24, 24, 2 });
        table.setTotalWidth(527);
        table.setLockedWidth(true);
        table.getDefaultCell().setFixedHeight(20);
        table.getDefaultCell().setBorder(Rectangle.BOTTOM);
        table.addCell(header);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(String.format("Pgina %d de", writer.getPageNumber()));
        PdfPCell cell = new PdfPCell(Image.getInstance(total));
        cell.setBorder(Rectangle.BOTTOM);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent());
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}