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

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

Introduction

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

Prototype

public PdfPTable(PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosEspecificaciones(Paragraph datosNormal) throws BadElementException {
    Connection conexion = null;//from ww w  .j  a v a2  s . c o 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 ww.ja v  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  ww  .java2s  . 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  ww  .j a va2 s.  com*/
    // 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
 */// w w w.ja  va2s .  c  om
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

/**
 * Adds a signature field with a date field to the document. Should be the
 * last part that is added to the document.
 * // w  w w  .ja v  a2s. c  o  m
 * @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.dhbw.humbuch.util.PDFHandler.java

/**
 * Create a standard table with constant table width.
 * /*  ww w .j a  v  a2  s. c  om*/
 * @param columnNumber
 *            set how many columns the table will have
 * @return table
 */
protected static PdfPTable createMyStandardTable(int columnNumber) {
    PdfPTable table = new PdfPTable(columnNumber);
    table.setLockedWidth(true);
    table.setTotalWidth(TABLEWIDTH);

    return table;
}

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

/**
 * Create a standard table with constant table width.
 * /*from  w  w w  .  j  ava2  s .  com*/
 * @param columnNumber
 *            set how many columns the table will have
 * @param columnWidths
 *            set the ratio between the columns. If null, all columns will
 *            be equal.
 * @return table
 */
protected static PdfPTable createMyStandardTable(int columnNumber, float[] columnWidths) {
    PdfPTable table = new PdfPTable(columnNumber);
    table.setLockedWidth(true);
    table.setTotalWidth(TABLEWIDTH);

    if (!(columnWidths == null) && (columnWidths.length != 0)) {
        try {
            table.setWidths(columnWidths);
        } catch (DocumentException e) {
            System.err.println("Could not set columnWidths of standardTable " + e.getStackTrace());
        }
    }

    return table;
}

From source file:de.ipbhalle.metfrag.tools.renderer.WritePDFTable.java

License:Open Source License

/**
 * Instantiates a new write pdf table. This is mainly for debugging the gasteiger marsili charges
 * /*from   ww  w . java  2 s  .  c  om*/
 * @param odir the odir
 * @param width the width
 * @param height the height
 * @param chargeResults the charge results
 */
public WritePDFTable(String odir, int width, int height, List<ChargeResult> chargeResults) {

    this.width = width;
    this.height = height;

    try {
        File file = new File(odir);
        document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));

        float[] widths = new float[ncol];
        for (int i = 0; i < ncol; i += 3) {
            widths[i] = 2.5f;
            widths[i + 1] = 0.75f;
            widths[i + 2] = 0.75f;
        }
        table = new PdfPTable(widths);
        document.open();

        boolean drawPartialCharges = true;

        for (ChargeResult result : chargeResults) {

            if (drawPartialCharges) {
                PdfPCell cellBonds = new PdfPCell();
                PdfPCell cellBondsDist = new PdfPCell();
                Phrase phraseBonds = new Phrase();
                Phrase phraseBondsDist = new Phrase();

                com.lowagie.text.Image image = com.lowagie.text.Image
                        .getInstance(writeMOL2PNGFile(result.getOriginalMol()).getAbsolutePath());
                image.setAbsolutePosition(0, 0);
                table.addCell(image);

                String stringAtoms = "";
                String stringAtomsCharge = "";
                for (IAtom atom : result.getOriginalMol().atoms()) {
                    if (!atom.getSymbol().equals("H") && !atom.getSymbol().equals("C")) {
                        stringAtoms += atom.getSymbol() + (Integer.parseInt(atom.getID()) + 1) + "\n";
                        stringAtomsCharge += Math.round(atom.getCharge() * 100.0) / 100.0 + "\n";
                    }
                }

                addProperty(phraseBonds, stringAtoms);
                addProperty(phraseBondsDist, stringAtomsCharge);
                cellBonds.addElement(phraseBonds);
                cellBondsDist.addElement(phraseBondsDist);
                table.addCell(cellBonds);
                table.addCell(cellBondsDist);
                drawPartialCharges = false;
            }

            PdfPCell cellBonds = new PdfPCell();
            PdfPCell cellBondsDist = new PdfPCell();
            Phrase phraseBonds = new Phrase();
            Phrase phraseBondsDist = new Phrase();

            com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(
                    writeMOL2PNGFile(result.getOriginalMol(), result.getMolWithProton()).getAbsolutePath());
            image.setAbsolutePosition(0, 0);
            table.addCell(image);

            String stringPDFBonds = "";
            String stringPDFBondsDist = "";
            String[] lines = result.getChargeString().split("\n");
            for (int i = 0; i < lines.length; i++) {
                boolean carbonHydrogenBond = lines[i].matches("[A-Z]+[0-9]+-H[0-9]+.*");
                if (!carbonHydrogenBond) {
                    String[] linesArr = lines[i].split("\t");
                    stringPDFBondsDist += linesArr[1] + "\n";
                    stringPDFBonds += linesArr[0] + "\n";
                }
            }

            addProperty(phraseBonds, stringPDFBonds);
            addProperty(phraseBondsDist, stringPDFBondsDist);
            cellBonds.addElement(phraseBonds);
            cellBondsDist.addElement(phraseBondsDist);
            table.addCell(cellBonds);
            table.addCell(cellBondsDist);
        }

        document.add(table);
        document.close();

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

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

License:Open Source License

@Override
public void initialize() {
    table = new PdfPTable(getSudokuSize().getHouseSize());
}