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

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

Introduction

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

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

/**
 * Esta funcin convierte un arrayList en una PdfPTable y, agrega una columna
 * de estadisticas a esta. Funcionar si el arrayList tiene en su ultima columna
 * numeros//from   w  w w.  j a  v  a 2s.c  o  m
 * @param entrada Matriz con los datos estadisticos de la base de datos
 * @param total La suma de todos los datos de la ultima columna
 * @param rows El numero de columnas que se mostrarn en la PdfPTable
 * @return PdfPTable Contiene los datos del ArrayList ms los porcentajes.
 */
static public PdfPTable arrayListToStatisticTable(ArrayList<ArrayList<String>> entrada, int total, int rows) {
    PdfPTable salida = null;

    salida = new PdfPTable(entrada.get(0).size() + 1);
    for (int i = 0; i < entrada.get(0).size(); i++) {
        salida.addCell(entrada.get(0).get(i));
    }
    salida.addCell("Porcentaje");
    salida.setHeaderRows(1);
    int counter = 0;
    for (int j = 1; j < entrada.size() && counter < rows; j++) {
        for (int i = 0; i < entrada.get(j).size(); i++) {
            salida.addCell(entrada.get(j).get(i));
            if (i == entrada.get(j).size() - 1) {
                int porcentaje = (int) (Integer.parseInt(entrada.get(j).get(i)) * 100) / total;
                salida.addCell(porcentaje + "%");
            }
        }
        counter++;
    }
    if (entrada.size() - 1 > rows) {
        int otros = 0, otrospor;
        for (int i = counter; i < entrada.size(); i++) {
            otros += Integer.parseInt(entrada.get(i).get(entrada.get(i).size() - 1));
        }
        otrospor = otros * 100;
        otrospor /= total;
        salida.addCell("-");
        salida.addCell("Otros");
        salida.addCell(otros + "");
        salida.addCell(otrospor + "%");
    }
    return salida;
}

From source file:billerfx.FXMLBillController.java

File generatePDF() {
    File fi = null;//www .j  a va2 s.co m
    try {
        Stage gg = ((Stage) imv.getParent().getScene().getWindow());
        fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf");
        fi.deleteOnExit();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(fi));
        Rectangle r = new RectangleReadOnly(207, 575);
        document.setPageSize(r);
        document.setMargins(15, 15, 0, 0);
        document.open();
        Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL);
        Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL);

        String[] ll = Database.getCurrentSettings();
        String ss = "-----------------------------------------------------\n";
        ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n";
        String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM"
                : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : "");
        ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH))
                + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at "
                + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE)
                + " " + kk + "\n";
        ss += "Table No. " + c.getText() + "     Bill No. " + a.getText() + "\n";
        ss += "-----------------------------------------------------\n";
        Paragraph para = new Paragraph(ss, fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        float[] columnWidths = { 3f, 1f };
        table.setWidths(columnWidths);
        PdfPCell defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        ObservableList ob = map.get(Integer.parseInt(gg.getTitle()));
        for (int i = 0; i < ob.size(); i++) {
            Item2 ii = (Item2) ob.get(i);
            String s1 = ii.getQuantity() + " x " + ii.getName();
            String s2 = "Rs. " + ii.getTotal();
            Paragraph para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            Paragraph para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            PdfPCell cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }
        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(columnWidths);
        defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        String s1 = "Total:";
        String s2 = "Rs. " + h.getText();
        Paragraph para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        Paragraph para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        PdfPCell cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) {
            s1 = "Discount:";
            s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()));
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[7].equals("1")) {
            s1 = ll[3];
            s2 = "Rs. " + k.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[8].equals("1")) {
            s1 = ll[4];
            s2 = "Rs. " + l.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        s1 = "Grand Total:";
        s2 = "Rs. " + m.getText();
        para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL);
        para = new Paragraph(
                "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n",
                fontbold2);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        document.close();
    } catch (Exception mm) {
    }
    return fi;
}

From source file:bl.pdf.PDFFile.java

private PdfPTable getTable(EntityTableModel tModel) {
    String[] headers = tModel.getColumnNames();

    PdfPTable table = new PdfPTable(headers.length);
    table.setHeaderRows(1);/*www.  j a v a2s.co m*/
    table.setWidthPercentage(100);
    for (String header : headers) {
        PdfPCell c1 = new PdfPCell(new Phrase(header));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    ArrayList<DBEntity> entries = tModel.getEntries();
    if (entries.isEmpty()) {
        PdfPCell c = new PdfPCell(new Phrase("Keine Eintrge vorhanden"));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        c.setColspan(headers.length);
        table.addCell(c);
        return table;
    }
    for (DBEntity entry : entries) {
        for (String header : headers) {
            Method method;

            Object a;
            try {
                method = entry.getClass().getMethod("get" + header, new Class<?>[0]);
                a = method.invoke(entry, new Object[0]);
                table.addCell(String.valueOf(a));
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (SecurityException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            } catch (InvocationTargetException e) {
                e.printStackTrace();
                table.addCell(new String(""));
            }
        }
    }
    return table;
}

From source file:bl.pdf.PDFFile.java

private PdfPTable getRechnungszeileTable(Rechnung r) throws DALException {
    String[] headers;/*from   w  w w  .ja v  a2  s  .  co  m*/
    if (r instanceof Eingangsrechnung) {
        String[] h = { "Rechnungszeile", "Kommentar", "Steuersatz", "Betrag", "ohne Steuer" };
        headers = h;
    } else {
        String[] h = { "Rechnungszeile", "Kommentar", "AngebotID", "Steuersatz", "Betrag", "ohne Steuer" };
        headers = h;
    }
    PdfPTable table = new PdfPTable(headers.length);
    table.setHeaderRows(1);
    table.setWidthPercentage(100);
    for (String header : headers) {
        PdfPCell c1 = new PdfPCell(new Phrase(header));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }

    ArrayList<Rechnungszeile> rechnungszeilen = BL.getRechnungszeileListe(r.getRechnungID());
    if (rechnungszeilen.isEmpty()) {
        PdfPCell c = new PdfPCell(new Phrase("Keine Rechnungszeilen vorhanden"));
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        if (r instanceof Ausgangsrechnung) {
            c.setColspan(6);
        } else {
            c.setColspan(5);
        }
        table.addCell(c);
        return table;
    }
    double summe = 0;
    double summeOhne = 0;
    for (Rechnungszeile rz : rechnungszeilen) {
        table.addCell(String.valueOf(rz.getRechnungszeileID()));
        table.addCell(String.valueOf(rz.getKommentar()));
        if (r instanceof Ausgangsrechnung) {
            table.addCell(String.valueOf(rz.getAngebotID()));
        }
        table.addCell(String.valueOf(rz.getSteuersatz()));
        table.addCell(String.valueOf(rz.getBetrag()));
        double betrag = rz.getBetrag();
        double steuersatz = rz.getSteuersatz();
        double betragOhne = betrag - (betrag / 100 * steuersatz);
        table.addCell(String.valueOf(betragOhne));
        summe += rz.getBetrag();
        summeOhne += betragOhne;
    }

    PdfPCell c = new PdfPCell(new Phrase("Summe"));
    c.setHorizontalAlignment(Element.ALIGN_RIGHT);
    if (r instanceof Ausgangsrechnung) {
        c.setColspan(4);
    } else {
        c.setColspan(3);
    }
    table.addCell(c);
    table.addCell(String.valueOf(summe));
    table.addCell(String.valueOf(summeOhne));

    return table;

}

From source file:bl.pdf.PDFFile.java

private void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);/* ww w . j  av a 2s.  c o m*/

    c1 = new PdfPCell(new Phrase("Table Header 3"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("1.0");
    table.addCell("1.1");
    table.addCell("1.2");
    table.addCell("2.1");
    table.addCell("2.2");
    table.addCell("2.3");

    subCatPart.add(table);

}

From source file:bladwin.web.reg.regPDF.java

private PdfPTable genSport(customerRegBean a) {
    float[] widths2 = { 0.33f, 0.33f, 0.33f };
    PdfPTable table = new PdfPTable(widths2);
    PdfPCell cell1 = new PdfPCell(), cell2 = new PdfPCell(), cell3 = new PdfPCell();
    cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell1.setPhrase(pdfRptMgr.getRptFont("Shirt Size", true));
    cell2.setPhrase(pdfRptMgr.getRptFont("Short Size", true));
    cell3.setPhrase(pdfRptMgr.getRptFont("Warmup Suit Size", true));

    table.addCell(cell1);
    table.addCell(cell2);/*from  w  w w. j  a v  a  2  s  .  co  m*/
    table.addCell(cell3);
    cell1.setPhrase(pdfRptMgr.getRptFont(a.getShirtSizeStr()));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getShortSideStr()));
    cell3.setPhrase(pdfRptMgr.getRptFont(a.getWarmupSuiteSizeStr()));
    table.addCell(cell1);
    table.addCell(cell2);
    table.addCell(cell3);
    return table;
}

From source file:bladwin.web.reg.regPDF.java

private PdfPTable genAthleteInfo(customerRegBean a, customerBean c) {
    float[] widths = { 0.30f, 0.70f };
    PdfPTable table = new PdfPTable(widths);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell1 = new PdfPCell(), cell2 = new PdfPCell();
    cell1.setPhrase(pdfRptMgr.getRptFont("Athlete Name", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getFullname()));

    table.addCell(cell1);
    table.addCell(cell2);//from w  w  w. ja va 2 s . c o  m
    cell1.setPhrase(pdfRptMgr.getRptFont("School", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getSchool()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Date of Birth", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getDobStr()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Cell #", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getCell()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("E-Mail", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getEMail()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Any Health Concerns?", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getRegNote()));
    table.addCell(cell1);
    table.addCell(cell2);

    cell1.setPhrase(pdfRptMgr.getRptFont("Emergency Contact", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(a.getContact()));
    table.addCell(cell1);
    table.addCell(cell2);

    return table;
}

From source file:bladwin.web.reg.regPDF.java

private PdfPTable genParentInfo(customerBean c) {
    float[] widths = { 0.20f, 0.80f };
    PdfPTable table = new PdfPTable(widths);
    table.getDefaultCell().setBorder(0);
    PdfPCell cell1 = new PdfPCell(), cell2 = new PdfPCell();
    cell1.setPhrase(pdfRptMgr.getRptFont("Parent Name", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getLastName() + ", " + c.getFirstName()));
    table.addCell(cell1);
    table.addCell(cell2);/* w ww  .  j a va2  s . c  o m*/
    cell1.setPhrase(pdfRptMgr.getRptFont("Address", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(getAddress(c)));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Cell #", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getCell()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("Home #", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getHmPhone()));
    table.addCell(cell1);
    table.addCell(cell2);
    cell1.setPhrase(pdfRptMgr.getRptFont("E-Mail", true));
    cell2.setPhrase(pdfRptMgr.getRptFont(c.getEMail()));
    table.addCell(cell1);
    table.addCell(cell2);
    return table;
}

From source file:bodyfitness.relatorios.Relatorio.java

public void GeraRelatorioAdimplente(String caminho) {
    Document documento = new Document();
    try {//w  w  w .ja  v a2  s .c o  m
        PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/Adimplentes.pdf"));
        documento.open();
        ClienteDAO dao = new ClienteDAO();
        List<Cliente> clientes = dao.consultarAdimplentes();
        PdfPTable tabela = new PdfPTable(2);
        tabela.addCell("ID");
        tabela.addCell("Nome");
        Paragraph p = new Paragraph("     Relatrio - Clientes Adimplentes\n\n\n");
        documento.add(p);
        for (Cliente c : clientes) {
            tabela.addCell(c.getId().toString());
            tabela.addCell(c.getNome());
        }
        documento.add(tabela);
        documento.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:bodyfitness.relatorios.Relatorio.java

public void GeraRelatorioInadimplente(String caminho) {
    Document documento = new Document();
    try {/*from w w w .  ja va2 s  . c o m*/
        PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/Adimplentes.pdf"));
        documento.open();
        ClienteDAO dao = new ClienteDAO();
        List<Cliente> clientes = dao.consultarInadimplentes();
        PdfPTable tabela = new PdfPTable(2);
        tabela.addCell("ID");
        tabela.addCell("Nome");
        Paragraph p = new Paragraph("     Relatrio - Clientes Inadimplentes\n\n\n");
        documento.add(p);
        for (Cliente c : clientes) {
            tabela.addCell(c.getId().toString());
            tabela.addCell(c.getNome());
        }
        documento.add(tabela);
        documento.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}