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

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

Introduction

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

Prototype

public void setTotalWidth(final float columnWidth[]) throws DocumentException 

Source Link

Document

Sets the full width of the table from the absolute column width.

Usage

From source file:Almacen.Responsiva.java

private void b_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_imprimirActionPerformed
    // TODO add your handling code here:
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/* w  w  w  .  j av  a 2  s  .  c  om*/
        String empleado = "";
        String puesto = "";
        if (t_datos.getRowCount() > 0) {
            //consulta
            Query q = session.createSQLQuery(
                    "select empleado.nombre as empleado, puestos.nombre as puesto from empleado inner join puestos on puestos.id_puestos=empleado.id_puesto where empleado.id_empleado="
                            + t_id_empleado.getText() + ";");
            q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
            List lista = q.list();

            for (int i = 0; i < lista.size(); i++) {
                java.util.HashMap map = (java.util.HashMap) lista.get(i);
                empleado = (String) map.get("empleado");
                puesto = (String) map.get("puesto");
            }

            Date fecha = new Date();
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
            String Mes[] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto",
                    "Septiembre", "Octubre", "Noviembre", "Diciembre" };
            Calendar fecha1 = new GregorianCalendar();
            int anio = fecha1.get(Calendar.YEAR);
            int mes = fecha1.get(Calendar.MONTH);
            int dia = fecha1.get(Calendar.DAY_OF_MONTH);
            //DateFormat dateFormat1 = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
            String valor = dateFormat.format(fecha);
            File folder = new File("reportes/Responsivas");
            folder.mkdirs();
            PdfReader reader = new PdfReader("imagenes/CartaResponsiva.pdf");
            PdfStamper stamp = new PdfStamper(reader,
                    new FileOutputStream("reportes/Responsivas/" + valor + "CartaResponsiva.pdf"));
            PdfContentByte cb = stamp.getUnderContent(1);
            PdfContentByte cb2 = stamp.getUnderContent(2);
            AcroFields fdfDoc = stamp.getAcroFields();
            // Creo una fuente
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

            cb.beginText();
            //dia
            try {
                if (dia < 9)
                    fdfDoc.setField("Dia", "0" + String.valueOf(dia));
                else
                    fdfDoc.setField("Dia", String.valueOf(dia));
            } catch (Exception e) {
                fdfDoc.setField("Dia", "error");
            }
            //mes
            try {
                fdfDoc.setField("Mes", Mes[mes]);
            } catch (Exception e) {
                fdfDoc.setField("Mes", "");
            }
            //ao
            try {
                fdfDoc.setField("Anio", String.valueOf(anio));
            } catch (Exception e) {
                fdfDoc.setField("Anio", "");
            }
            //nombre
            try {
                fdfDoc.setField("Nombre", empleado);
            } catch (Exception e) {
                fdfDoc.setField("Nombre", "");
            }
            //puesto
            try {
                fdfDoc.setField("Puesto", puesto);
            } catch (Exception e) {
                fdfDoc.setField("Puesto", "");
            }

            //tabla de herramientas
            float tam[] = new float[] { 250, 50, 180 };
            Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
            PDF reporte = new PDF();
            PdfPTable tabla = reporte.crearTabla(3, tam, 100, Element.ALIGN_LEFT);
            tabla.setTotalWidth(tam);
            BaseColor cabecera = BaseColor.GRAY;
            BaseColor contenido = BaseColor.WHITE;
            int centro = Element.ALIGN_CENTER;
            int izquierda = Element.ALIGN_LEFT;
            int derecha = Element.ALIGN_RIGHT;

            tabla.addCell(reporte.celda("HERRAMIENTA", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("CANTIDAD", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("NOTAS", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

            for (int i = 0; i < t_datos.getRowCount(); i++) {
                tabla.addCell(reporte.celda(t_datos.getValueAt(i, 1).toString(), font, contenido, izquierda, 0,
                        1, Rectangle.RECTANGLE));

                tabla.addCell(reporte.celda(String.valueOf((double) t_datos.getValueAt(i, 2)), font, contenido,
                        centro, 0, 1, Rectangle.RECTANGLE));
                if (t_datos.getValueAt(i, 3) != null)
                    tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda,
                            0, 1, Rectangle.RECTANGLE));
                else
                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE));
            }

            tabla.completeRow();
            tabla.writeSelectedRows(0, -1, 70, 720, cb2);
            cb.endText();
            stamp.close();
            reporte.cerrar();
            reporte.visualizar("reportes/Responsivas/" + valor + "CartaResponsiva.pdf");
        } else {
            JOptionPane.showMessageDialog(this, "No Existe Ninguna Responsiva");
        }
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null) {
        if (session.isOpen()) {
            session.close();
        }
    }
}

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

License:Open Source License

protected PdfPTable getBout(String player1, String player2) {
    PdfPTable table = new PdfPTable(2);
    table.setTotalWidth(configuration.getSquareCellSize() * 2);
    PdfPCell player1Name = new PdfPCell(new Phrase(player1));
    player1Name.setBorder(Rectangle.BOTTOM);
    player1Name.setHorizontalAlignment(Element.ALIGN_CENTER);
    player1Name.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player2Name = new PdfPCell(new Phrase(player2));
    player2Name.setBorder(Rectangle.BOTTOM);
    player2Name.setHorizontalAlignment(Element.ALIGN_CENTER);
    player2Name.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player1Score = new PdfPCell(new Phrase(" "));
    player1Score.setBorder(Rectangle.RIGHT);
    player1Score.setFixedHeight(configuration.getSquareCellSize());
    PdfPCell player2Score = new PdfPCell(new Phrase(" "));
    player2Score.setBorder(Rectangle.LEFT);
    player2Score.setFixedHeight(configuration.getSquareCellSize());
    table.addCell(player1Name);// w  w  w .  java 2  s  .  c o m
    table.addCell(player2Name);
    table.addCell(player1Score);
    table.addCell(player2Score);
    table.setSpacingBefore(10);
    return table;
}

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(
            (configuration.getNrOfPlayers() + 1 + nameCellWidth + 0.1f + configuration.getSummaryColumnCount())
                    * configuration.getSquareCellSize());
    table.setLockedWidth(true);/*from w  w  w . j  ava 2 s .com*/
    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);/*www  . j a  v a  2s  .  c  o m*/
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    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);//  www .jav  a  2  s. co m
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    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);/*  www. j  a va2  s .  c  o  m*/
    float[] widths = new float[columnCount];
    for (int i = 0; i < widths.length; i++) {
        widths[i] = 1f;
    }
    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);//w  ww.  j a  va  2 s  .  c  o  m
    float[] widths = new float[columnCount];
    widths[0] = 5f;
    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:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable createModelPage(Contact contact, Model model, PdfWriter pdfWriter)
        throws IOException, DocumentException {

    final PdfPTable pdfPTable = new PdfPTable(new float[] { 40f, 1f, 59f });
    pdfPTable.setTotalWidth(iTextUtil.PAGE_SIZE.getWidth());
    pdfPTable.addCell(cell(buildModelDetailSection(model, pdfWriter)));
    pdfPTable.addCell(cell(new Paragraph()));
    pdfPTable.addCell(cell(buildModelPricingTables(contact, model)));
    return pdfPTable;

}

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();//from  w  ww  .  ja v  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())) {/*  ww w . ja  v  a2 s.  co  m*/
            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;
}