Example usage for com.lowagie.text.pdf PdfPTable addCell

List of usage examples for com.lowagie.text.pdf PdfPTable addCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable addCell.

Prototype

public void addCell(Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosDerecha(Paragraph datosDerecha) throws Exception {
    ciudad = Cotizacion.PanelCotizacion.labelCiudad.getText();
    Connection conexion = null;//from  www  .  j av a 2  s.  c  o m
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);

        stm = (Statement) conexion.createStatement();

        //            System.out.println("nombre++++---->      "+nombreCliente);
        ResultSet rs = stm.executeQuery("SELECT * FROM todolonas.ajustes;");
        while (rs.next()) {
            telefonoNegocio = rs.getString("telefonoNegocio");
            numeroCelular = rs.getString("numeroCelular");
            correoNegocio = rs.getString("correoNegocio");
            domicilioNegocio = rs.getString("domicilioNegocio");
            RFC = rs.getString("RFC");
            leyendaCotizacion = rs.getString("leyendaCotizacion");
            colonia = rs.getString("colonia");
        }
        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    PdfPTable table = new PdfPTable(2);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table.addCell("");
    table.addCell(telefonoNegocio);
    table.addCell("");
    table.addCell(numeroCelular);
    table.addCell("");
    table.addCell(correoNegocio);
    table.addCell("");
    table.addCell(domicilioNegocio);
    table.addCell("");
    table.addCell(colonia);
    table.addCell("");
    table.addCell(RFC);
    table.addCell("");
    table.addCell(ciudad);
    table.setWidthPercentage(100);
    table.setHorizontalAlignment(Element.ALIGN_RIGHT);
    datosDerecha.add(table);

}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosDerecha2(Paragraph datosDerecha2) {
    fecha = PanelCotizacion.labelObtenerFecha.getText();
    ubicacion = PanelCotizacion.cajaAsunto.getText();
    asunto = PanelCotizacion.cajaUbicacion.getText();
    PdfPTable table2 = new PdfPTable(2);
    table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table2.addCell("Fecha");
    table2.addCell(fecha);/*  w ww. j  ava2  s. c  om*/
    table2.addCell("Ubicacin");
    table2.addCell(ubicacion);
    table2.addCell("Asunto");
    table2.addCell(asunto);
    table2.setWidthPercentage(50);
    table2.setHorizontalAlignment(350);
    table2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    datosDerecha2.add(table2);
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosEspecificaciones(Paragraph datosNormal) throws BadElementException {
    Connection conexion = null;//from w w  w  . ja v a 2s.  co m
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);
        stm = (Statement) conexion.createStatement();
        ResultSet rs = stm.executeQuery("select max(numero) as numero from todolonas.cotizacion;");

        while (rs.next()) {
            idCotiza = rs.getInt("numero");
        }

        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);

        stm = (Statement) conexion.createStatement();
        ResultSet rs = stm.executeQuery(
                "SELECT especificacionTrabajo FROM todolonas.cotizacion where numero = '" + idCotiza + "';");
        while (rs.next()) {
            especificacionTrabajo = rs.getString("especificacionTrabajo");
        }
        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    if (especificacionTrabajo.equals("NA")) {
        System.out.println("no hay especificacion trabajo");
    } else {
        PdfPTable table2 = new PdfPTable(2);
        table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table2.addCell("Especificacin Trabajo");
        table2.addCell(especificacionTrabajo);
        table2.setWidthPercentage(70);
        table2.setHorizontalAlignment(Element.ALIGN_LEFT);
        agregarLineasEnBlanco(datosNormal, 1);
        datosNormal.add(table2);
    }
    try {
        Class.forName("org.gjt.mm.mysql.Driver");
        conexion = (Connection) DriverManager.getConnection(url, login, password);

        stm = (Statement) conexion.createStatement();

        //            System.out.println("nombre++++---->      "+nombreCliente);
        ResultSet rs = stm.executeQuery(
                "SELECT especificacionDiseno FROM todolonas.cotizacion where numero = '" + idCotiza + "';");
        while (rs.next()) {
            especificacionDiseno = rs.getString("especificacionDiseno");
        }
        conexion.close();
    } catch (Exception e) {
        System.out.println("error: " + e);
    }
    if (especificacionDiseno.equals("NA")) {
        System.out.println("no hay especificacion trabajo");
    } else {
        PdfPTable table2 = new PdfPTable(2);
        table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
        table2.addCell("Especificacin Diseo");
        table2.addCell(especificacionDiseno);
        table2.setWidthPercentage(70);
        table2.setHorizontalAlignment(Element.ALIGN_LEFT);
        agregarLineasEnBlanco(datosNormal, 1);
        datosNormal.add(table2);
    }
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosTablaProductos(Paragraph subCatPart) throws BadElementException {
    numeroFilas = LogicaCotizacion.numero;
    cantidadTabla = new String[numeroFilas];
    productoTabla = new String[numeroFilas];
    precioTabla = new String[numeroFilas];
    totalTabla = new String[numeroFilas];
    descripcionTabla = new String[numeroFilas];

    PdfPTable tabla = new PdfPTable(5);
    tabla.setWidthPercentage(100);//from w w  w. j av a 2 s.  c o  m

    PdfPCell celda = new PdfPCell(new Paragraph("Producto"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("Descripcin"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("P/U"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("Cantidad"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("Total"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    for (int i = 0; i < numeroFilas; i++) {
        productoTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 0);
        tabla.addCell("   " + productoTabla[i]);
        descripcionTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 1);
        tabla.addCell("" + descripcionTabla[i]);
        precioTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 2);
        tabla.addCell("$  " + precioTabla[i]);
        cantidadTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 3);
        tabla.addCell("   " + cantidadTabla[i]);
        totalTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 4);
        tabla.addCell("$  " + totalTabla[i]);
    }
    agregarLineasEnBlanco(subCatPart, 1);
    subCatPart.add(tabla);
}

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosPreciosTotales(Paragraph datosDerecha2) throws BadElementException {
    subtotal = PanelCotizacion.cajaSubtotal.getText();
    iva = PanelCotizacion.cajaIVA.getText();
    descuento = PanelCotizacion.cajaDescuento.getText();
    total = PanelCotizacion.cajaTotal.getText();

    PdfPTable table2 = new PdfPTable(2);
    table2.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    table2.addCell("Subtotal");
    table2.addCell("$  " + subtotal);
    table2.addCell("IVA");
    table2.addCell(iva);/*from   w  w w.j av  a2 s . c o  m*/
    table2.addCell("Descuento");
    table2.addCell(descuento);
    table2.addCell("Total");
    table2.addCell("$  " + total);
    table2.setWidthPercentage(30);
    table2.setHorizontalAlignment(350);
    table2.setHorizontalAlignment(Element.ALIGN_RIGHT);
    agregarLineasEnBlanco(datosDerecha2, 1);
    datosDerecha2.add(table2);
}

From source file:CPS.Core.TODOLists.PDFExporter.java

License:Open Source License

private Document prepareDocument(String filename, final String title, final String author, final String creator,
        final Rectangle pageSize) {

    System.out.println("DEBUG(PDFExporter): Creating document: " + filename);

    Document d = new Document();

    d.setPageSize(pageSize);//from w  w  w .j a va  2 s.  co  m
    // TODO alter page orientation?  maybe useful for seed order worksheet

    d.addTitle(title);
    d.addAuthor(author);
    //        d.addSubject( );
    //        d.addKeywords( );
    d.addCreator(creator);

    // left, right, top, bottom - scale in points (~72 points/inch)
    d.setMargins(35, 35, 35, 44);

    try {
        PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream(filename));
        // add header and footer
        writer.setPageEvent(new PdfPageEventHelper() {
            public void onEndPage(PdfWriter writer, Document document) {
                try {
                    Rectangle page = document.getPageSize();

                    PdfPTable head = new PdfPTable(3);
                    head.getDefaultCell().setBorderWidth(0);
                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    head.addCell(new Phrase(author, fontHeadFootItal));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    head.addCell(new Phrase(title, fontHeadFootReg));

                    head.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    head.addCell("");

                    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);

                    foot.getDefaultCell().setBorderWidth(0);
                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    foot.addCell(new Phrase(creator, fontHeadFootItal));

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    foot.addCell("");

                    foot.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    foot.addCell(new Phrase("Page " + document.getPageNumber(), fontHeadFootReg));

                    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);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

    return d;
}

From source file:CPS.Core.TODOLists.PDFExporter.java

License:Open Source License

/**
 * @param args the command line arguments
 *//*from  w w w. jav a 2s. c  o  m*/
public PdfPTable convertJTable(JTable jtable) {

    boolean tableIncludesNotes = false;
    boolean rowHasNotes = false;
    String notesValue = "";
    int notesIndex = -1;

    // find Notes column (if there is one)
    for (int col = 0; col < jtable.getColumnCount(); col++) {
        String headName;
        if (jtable instanceof CPSTable)
            headName = jtable.getColumnModel().getColumn(col).getHeaderValue().toString();
        else
            headName = jtable.getColumnName(col);
        if (headName.equalsIgnoreCase("Planting Notes")) {
            tableIncludesNotes = true;
            notesIndex = col;
        }
    }

    int colCount = (tableIncludesNotes) ? jtable.getColumnCount() - 1 : jtable.getColumnCount();
    PdfPTable table = new PdfPTable(colCount);

    // create header row
    for (int col = 0; col < jtable.getColumnCount(); col++) {
        String headName;
        if (jtable instanceof CPSTable)
            headName = jtable.getColumnModel().getColumn(col).getHeaderValue().toString();
        else
            headName = jtable.getColumnName(col);
        if (!tableIncludesNotes || col != notesIndex) {
            HeadCell hc = new HeadCell(headName);

            if (jtable.getColumnClass(col).equals(Boolean.TRUE.getClass())
                    || jtable.getColumnClass(col).equals(new Integer(0).getClass())
                    || jtable.getColumnClass(col).equals(new Double(0).getClass())
                    || jtable.getColumnClass(col).equals(new Float(0).getClass())) {
                hc.setRotation(90);
                hc.setFixedHeight(60f);
            }

            table.addCell(hc);
        }
    }
    table.setHeaderRows(1);

    // now fill in the rest of the table
    for (int row = 0; row < jtable.getRowCount(); row++) {
        rowHasNotes = false;

        for (int col = 0; col < jtable.getColumnCount(); col++) {
            Object o = jtable.getValueAt(row, col);

            if (o == null) {
                if (!tableIncludesNotes || col != notesIndex)
                    table.addCell(new RegCell(""));
            }

            else if (o instanceof Date)
                table.addCell(new RegCell(
                        CPSDateValidator.format((Date) o, CPSDateValidator.DATE_FORMAT_SHORT_DAY_OF_WEEK)));

            else if (o instanceof Boolean)
                if (((Boolean) o).booleanValue())
                    table.addCell(new CenterCell("X"));
                else
                    table.addCell(new RegCell(""));

            else if (o instanceof Float)
                table.addCell(new RegCell(CPSRecord.formatFloat(((Float) o).floatValue(), 3)));

            else if (o instanceof Double)
                table.addCell(new RegCell(CPSRecord.formatFloat(((Double) o).floatValue(), 3)));

            else {

                if (tableIncludesNotes && col == notesIndex) {
                    if (o == null || o.equals(""))
                        rowHasNotes = false;
                    else {
                        rowHasNotes = true;
                        notesValue = o.toString();
                    }
                } else
                    table.addCell(new RegCell(o.toString()));
            }
        }

        // now deal w/ the Notes data
        if (tableIncludesNotes && rowHasNotes) {
            table.addCell(new NoteHeadCell());
            NoteCell c = new NoteCell(notesValue);
            // reset the font to be smaller
            c.setPhrase(new Phrase(notesValue, fontHeadFootReg));
            c.setColspan(colCount - 1);
            table.addCell(c);
        }
    }

    // set the widths for the columns
    float[] widths = new float[colCount];
    for (int col = 0; col < colCount; col++) {
        if (tableIncludesNotes && col == notesIndex)
            continue;
        else if (jtable.getColumnClass(col).equals(new Boolean(true).getClass()))
            widths[col] = 2.25f;
        else if (jtable.getColumnClass(col).equals(new Integer(0).getClass())
                || jtable.getColumnClass(col).equals(new Double(0).getClass())
                || jtable.getColumnClass(col).equals(new Float(0).getClass()))
            widths[col] = 5f;
        else // String, Date, etc
            widths[col] = 10f;
    }

    try {
        table.setWidths(widths);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return table;
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Set the logo of Humboldt on the left corner and the current date on the
 * right corner/* w w  w.j a va 2s.c o  m*/
 * 
 * @param document
 *            reference of the pdfDocument object
 */
protected void addHeading(Document document) {
    Paragraph paragraph = new Paragraph();
    PdfPTable table = createMyStandardTable(2);

    table.setTotalWidth(TABLEWIDTH);
    PdfPCell cell;

    Image img = new ResourceLoader("pdf/humboldt_logo.png").getImage();
    img.setAlignment(Element.ALIGN_BOTTOM);
    img.scaleToFit(205f, 65f);
    cell = new PdfPCell(img);

    cell.setBorder(0);
    table.addCell(cell);

    String date = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN).format(Calendar.getInstance().getTime());

    cell = new PdfPCell(new Phrase(date));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);

    paragraph.add(table);
    addEmptyLine(paragraph, 1);

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Adds a signature field with a date field to the document. Should be the
 * last part that is added to the document.
 * //from  w  w w . j  av a2 s . com
 * @param document
 *            represents the PDF before it is saved
 * @param role
 *            word for the kind of person that shall sign the paper
 */
protected void addSignatureField(Document document, String role) {
    Paragraph paragraph = new Paragraph();

    //this table contains the signatureTable and the dataTable.
    // this purpose makes it easier to format
    PdfPTable table = createMyStandardTable(2);

    //the first column is double times greater than the second column
    try {
        table.setWidths(new float[] { 10f, 20f });
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    //create and fill date table
    PdfPTable dateTable = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for date)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    dateTable.addCell(cell);

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

    dateTable.addCell(cell);

    //put date table into the 'parent' table
    cell = new PdfPCell(dateTable);
    cell.setBorder(0);
    table.addCell(cell);

    //create and fill signature table
    PdfPTable signatureTable = new PdfPTable(1);
    cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for signature)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    signatureTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Unterschrift " + role));
    cell.setBorder(0);

    signatureTable.addCell(cell);

    //put signature table into the 'parent' table
    cell = new PdfPCell(signatureTable);
    cell.setBorder(0);
    table.addCell(cell);

    paragraph.add(table);
    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java

License:Open Source License

/**
 * //from  w ww.  jav  a 2 s  .c  o  m
 * @return 3x3 Tabelle gefllt mit Kandidaten 1-9
 */
private PdfPTable buildCandidates() {
    final float CANDIDATE_FONT_SIZE = 6f;
    final float CANDIDATE_PADDING = 1f;
    PdfPTable candidates = new PdfPTable(3);
    PdfPCell[][] candidate = new PdfPCell[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            Paragraph p = new Paragraph(String.valueOf(i * 3 + j + 1));
            p.getFont().setSize(CANDIDATE_FONT_SIZE);
            candidate[i][j] = new PdfPCell(p);
            candidate[i][j].setPadding(CANDIDATE_PADDING);
            candidate[i][j].setHorizontalAlignment(Element.ALIGN_CENTER);
            candidate[i][j].setVerticalAlignment(Element.ALIGN_MIDDLE);
            candidate[i][j].setBorderColor(new Color(PdfConstants.RAHMEN_FARBE[0], PdfConstants.RAHMEN_FARBE[1],
                    PdfConstants.RAHMEN_FARBE[2]));
            candidate[i][j].setBorderWidth(PdfConstants.RAHMEN_KEIN);
            if (i > 0) {
                candidate[i][j].setBorderWidthTop(PdfConstants.RAHMEN_DUENN);
            }
            if (j > 0) {
                candidate[i][j].setBorderWidthLeft(PdfConstants.RAHMEN_DUENN);
            }
            candidates.addCell(candidate[i][j]);
        }
    }
    return candidates;
}