Example usage for com.itextpdf.text.pdf PdfPCell setColspan

List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setColspan.

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java

License:Open Source License

private void addMainHeaderCell(PdfPTable table, int index, String mainHeadingKey, int colspan) {
    PdfPCell headerCell = createCell();
    headerCell.setBackgroundColor(TABLE_HEADER_COLOR);
    headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerCell.setColspan(colspan);
    Phrase headerContents = new Phrase(getHeadingChunk(index, mainHeadingKey));
    headerCell.setPhrase(headerContents);
    addToTable(table, headerCell);/*from  w  w  w  .jav  a2s .  c  o m*/
}

From source file:Gui.admin.NouveauConsulterinfoAdherent.java

private void RapportBouttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RapportBouttonActionPerformed

        String value1 = idadherenttxt.getText();
        String value2 = nomadherentTxt.getText();
        String value3 = prenomAdhrentTxt.getText();
        String value4 = adresseAdherentTxt.getText();
        String value5 = mdpAdherentTXT.getText();
        String value6 = telAdherentTXT.getText();
        String value7 = nbrReclamationsTxt.getText();

        try {//  w ww .java  2s .  c om
            // pagesize.A4.rotate() pour voir le rapport dans IDE 
            com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("rapport.pdf"));

            if ((new File("rapport.pdf")).exists()) {

                Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler rapport.pdf");
                p.waitFor();

            } else {

                System.out.println("File is not exists");

            }

            document.open();
            // Date
            document.add(new Paragraph(new Date().toString()));
            document.add(new Paragraph("Rapport Statistiques",
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
            document.add(new Paragraph(
                    "--------------------------------------------------------------------------------------------------------------------------------------------------------------------"));

            // ajoute un tableau dans le rapport 

            //                  PdfPTable table = new PdfPTable(4);
            //                  
            //                   PdfPCell cell = new PdfPCell(new Paragraph("Informations Adhrents"));
            //                     // le titre du tableau 
            //                  cell.setColspan(10);
            //                  cell.setBackgroundColor(BaseColor.GREEN);
            //                  table.addCell(cell);

            //                  table.addCell("Id Adhrent");
            //                  table.addCell("Nom de l'adhrent");
            //                  table.addCell("Prnom de l'adhrent");
            //                  table.addCell("Numro de l'adhrent");
            //                  document.add(table);
            // le titre du tableau 

            // ajouter l'image dans le fichier pdf 
            Image image = Image.getInstance("statistiques.png");
            document.add(new Paragraph("statistiques.png"));
            document.add(image);

            // document.add(new Paragraph("Salut sindoud", FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD, BaseColor.BLUE)));

            //document.add(new Paragraph (new Date().toString()));

            PdfPTable table = new PdfPTable(6);
            PdfPCell cell = new PdfPCell(new Paragraph("Titre"));
            cell.setColspan(4);
            //  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(BaseColor.GREEN);
            table.addCell("id de l'adherent");
            table.addCell(value1);
            table.addCell("Nom de l'adhrent");
            table.addCell(value2);
            table.addCell("Prnom de l'adhrent");
            table.addCell(value3);
            table.addCell("adresse de l'adhrent");
            table.addCell(value4);
            table.addCell("mot de passe de l'adherent");
            table.addCell(value5);
            table.addCell("tel de l'adherent ");
            table.addCell(value6);
            table.addCell("nombre de reclamations");
            table.addCell(value7);

            document.add(table);

            document.close();
            //com.itextpdf.text.Image image1= com.itextpdf.text.Image.getInstance("statistiques.png");
            // image1.scaleAbsolute(400,300);
            //document.add(image1);
            //PdfContentByte cb= writer.getDirectContent();
            JOptionPane.showMessageDialog(null, "rapport enregistr");
        }

        catch (DocumentException | IOException | InterruptedException | HeadlessException e) {

            JOptionPane.showMessageDialog(null, e);

        }
        //
    }

From source file:GUI.FrameUserPanier.java

private void BtnValiderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnValiderActionPerformed

    jLabel8.setText("" + CalculSomme());

    String val1 = TFidpan.getText();
    String val2 = TFnomut.getText();
    String val3 = TFNomprod.getText();
    String val4 = TFnombreprod.getText();
    String val5 = TFdescription.getText();
    try {/*from w ww  . j a va2  s. c o m*/

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("Report.pdf"));
        document.open();
        document.add(new Paragraph("VotrePanier",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLUE)));
        document.add(new Paragraph(new Date().toString()));
        PdfPTable table = new PdfPTable(5);

        PdfPCell cell = new PdfPCell(new Paragraph("Mes achats"));

        cell.setColspan(5);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.BLUE);
        table.addCell(cell);

        table.addCell("IdPanier");
        table.addCell("NomUtilsateur");
        table.addCell("Nomprod");
        table.addCell("Nombreprod");
        table.addCell("Description");
        cell.setBackgroundColor(BaseColor.BLUE);

        int i = TablePanier.getRowCount();
        TableModel model = TablePanier.getModel();

        for (int j = 0; j < i; j++) {
            val1 = model.getValueAt(j, 0).toString();
            val2 = model.getValueAt(j, 2).toString();
            val3 = model.getValueAt(j, 4).toString();
            val4 = model.getValueAt(j, 5).toString();
            val5 = model.getValueAt(j, 6).toString();

            table.addCell(val1);
            table.addCell(val2);
            table.addCell(val3);
            table.addCell(val4);
            table.addCell(val5);

        }
        int z = TablePanier.getRowCount();
        model = TablePanier.getModel();
        float sum = 0;
        int bonus = 0;
        float net = 0;
        for (int j = 0; j < z; j++) {
            String x = model.getValueAt(j, 3).toString();
            int idprod = Integer.parseInt(x);
            String q = model.getValueAt(j, 5).toString();
            int qu = Integer.parseInt(q);
            Produit p = pdao.findByprodId(idprod);
            sum += p.getPrix() * qu;
            bonus += (p.getPtbonus() * qu);
            net += sum - (p.getReduction() * qu);
        }

        table.addCell("Somme: " + sum);
        table.addCell("");

        table.addCell("Net: " + net);
        table.addCell("");
        table.addCell("Bonus :" + bonus);

        document.add(table);
        document.close();
        JOptionPane.showMessageDialog(null, "Report Saved");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:gui.KlientiForm.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    String value2 = txt_Emri.getText();
    String value3 = txt_Mbiemri.getText();
    String value5 = cmb_GrupiK.getSelectedItem().toString();
    String value7 = txt_Adresa.getText();
    String value8 = txt_Email.getText();
    String value9 = txt_Telefoni.getText();

    try {//from  ww w  . j av  a2s  . c  o  m
        Document document = new Document(PageSize.A4.rotate()) {
        };
        PdfWriter.getInstance(document, new FileOutputStream("Raport-Klienti.pdf"));
        document.open();
        document.add(new Paragraph(new Date().toString()));
        document.add(new Paragraph(""));
        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell(new Paragraph("Profili i Klientit"));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        table.addCell("Emri");
        table.addCell(value2);
        table.addCell("Mbiemri");
        table.addCell(value3);
        table.addCell("Adresa");
        table.addCell(value7);
        table.addCell("Email");
        table.addCell(value8);
        table.addCell("Telefoni");
        table.addCell(value9);
        table.addCell("Grupi");
        table.addCell(value5);
        document.add(table);
        document.close();
        JOptionPane.showMessageDialog(null, "Raporti u ruajt");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:GUI_StafKlinik.Panel_Laporan_Keuangan.java

private PdfPTable createTableLaporan(List<Laporan_Keuangan> list) {
    PdfPTable tabel = new PdfPTable(6);
    PdfPCell cell;
    cell = new PdfPCell(new Phrase(("Tanggal"), font6));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setRowspan(1);/*from w ww  .j ava 2 s  .  com*/
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    tabel.addCell(cell);
    cell = new PdfPCell(new Phrase(("Keterangan"), font6));
    cell.setRowspan(1);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    tabel.addCell(cell);
    cell = new PdfPCell(new Phrase(("Ref"), font6));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setRowspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    tabel.addCell(cell);
    cell = new PdfPCell(new Phrase(("Pemasukan"), font6));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setRowspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    tabel.addCell(cell);
    cell = new PdfPCell(new Phrase(("Pengeluaran"), font6));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setRowspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    tabel.addCell(cell);
    cell = new PdfPCell(new Phrase(("Saldo"), font6));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    tabel.addCell(cell);

    for (int i = 0; i < list.size(); i++) {
        cell = new PdfPCell(new Phrase(("" + list.get(i).getTanggal()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabel.addCell(cell);

        cell = new PdfPCell(new Phrase(("" + list.get(i).getKeterangan()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        tabel.addCell(cell);

        cell = new PdfPCell(new Phrase(("" + list.get(i).getRef()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabel.addCell(cell);

        cell = new PdfPCell(new Phrase(("" + list.get(i).getPemasukan()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabel.addCell(cell);

        cell = new PdfPCell(new Phrase(("" + list.get(i).getPengeluaran()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabel.addCell(cell);

        cell = new PdfPCell(new Phrase(("" + list.get(i).getSaldo()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabel.addCell(cell);
    }
    return tabel;
}

From source file:GUI_StafKlinik.Panel_Penggajian.java

private PdfPTable createTableLaporan(Penggajian p) {
    PdfPTable tabel = new PdfPTable(2);
    PdfPCell cell;

    cell = new PdfPCell(new Phrase(("Nama Pegawai"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);// ww  w. j  av  a  2s. c  o  m
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("" + p.getNamaPegawai()), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("ID Pegawai"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("" + p.getIdPegawai()), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("Alamat"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase((""), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("Telepon"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase((""), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("Jabatan"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase((""), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("Gaji Pokok"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("" + p.getGajiPokok()), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("Gaji Tambahan"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("" + p.getGajiTambahan()), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("Total Gaji"), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setColspan(1);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    cell = new PdfPCell(new Phrase(("" + p.getTotalGaji()), font2));
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setBorderWidth(1);
    cell.setBorderColor(BaseColor.WHITE);
    tabel.addCell(cell);

    return tabel;
}

From source file:htmlparser.pdf.PDFFile.java

public void createScoreTable(Color oddrow_color, Color title_bg_color, Color title_font_color, int highlight) {
    if (this.opened) {

        int columnNumber = 0;
        for (String s : this.parser.getTeams().get(0).getData()) {

            columnNumber++;/*from  w ww. j  a  v a 2s. c om*/

        }

        PdfPTable table = new PdfPTable(columnNumber + 1);

        Font f = new Font(this.fonttype, 13);

        int row = 1;

        Font headline = new Font(f);
        headline.setStyle("bold");
        headline.setSize(16);
        headline.setColor(new BaseColor(title_bg_color.getRGB()));

        PdfPCell headcell = new PdfPCell(new Paragraph(this.parser.getCompetitionName(), headline));
        headcell.setColspan(columnNumber + 1);
        headcell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(headcell);

        Font title = new Font(f);
        title.setStyle("bold");
        title.setColor(new BaseColor(title_font_color.getRGB()));

        for (String s : this.shColNms) {

            PdfPCell cell = new PdfPCell(new Paragraph(s, title));
            cell.setBackgroundColor(new BaseColor(title_bg_color.getRGB()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell);
        }

        row++;

        int order = 1;

        Font tfont = f;
        Font bold = new Font(f);
        bold.setStyle("bold");

        for (Team t : this.parser.getTeams()) {

            if (highlight >= 0) {
                if (order == highlight + 1) {
                    tfont = bold;
                } else {
                    tfont = f;
                }
            }

            PdfPCell ordercell = new PdfPCell(new Paragraph(Integer.toString(order), tfont));
            ordercell.setHorizontalAlignment(Element.ALIGN_CENTER);

            if (row % 2 == 0) {
                ordercell.setBackgroundColor(new BaseColor(oddrow_color.getRGB()));
            }

            table.addCell(ordercell);

            for (String s : t.getData()) {

                PdfPCell cell = new PdfPCell(new Paragraph(s, tfont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);

                if (row % 2 == 0) {
                    cell.setBackgroundColor(new BaseColor(oddrow_color.getRGB()));
                }

                table.addCell(cell);

            }

            order++;
            row++;

        }

        try {
            float[] widths = { 12f, 40f, 13f, 5f, 5f, 5f, 10f, 10f };
            table.setWidths(widths);

            this.document.add(table);

        } catch (DocumentException ex) {
            System.out.println("Content exception");
        }

    }
}

From source file:htmlparser.pdf.PDFFile.java

public void createMatchTable(Color oddrow_color, Color title_bg_color, Color title_font_color) {

    if (this.opened) {

        this.document.newPage();

        int columnNumber = 0;
        for (String s : this.parser.getMatches().get(0).getData()) {

            columnNumber++;//from w  ww .  j a  v a  2  s.  c  o  m

        }

        PdfPTable table = new PdfPTable(columnNumber);

        Font f = new Font(this.fonttype, 13);

        int row = 1;

        Font headline = new Font(f);
        headline.setStyle("bold");
        headline.setSize(16);
        headline.setColor(new BaseColor(title_bg_color.getRGB()));

        PdfPCell headcell = new PdfPCell(new Paragraph(this.parser.getTeamName(), headline));
        headcell.setColspan(columnNumber);
        headcell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(headcell);

        Font title = new Font(f);
        title.setStyle("bold");
        title.setColor(new BaseColor(title_font_color.getRGB()));

        for (String s : this.mhColNms) {

            PdfPCell cell = new PdfPCell(new Paragraph(s, title));
            cell.setBackgroundColor(new BaseColor(title_bg_color.getRGB()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            table.addCell(cell);
        }

        row++;

        for (Match t : this.parser.getMatches()) {

            for (String s : t.getData()) {

                PdfPCell cell = new PdfPCell(new Paragraph(s, f));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);

                if (row % 2 == 0) {
                    cell.setBackgroundColor(new BaseColor(oddrow_color.getRGB()));
                }

                table.addCell(cell);

            }

            row++;

        }

        try {
            float[] widths = { 26f, 26f, 20f, 8f, 20f };
            table.setWidths(widths);

            this.document.add(table);

        } catch (DocumentException ex) {

        }

    }

}

From source file:ics4u.ics4u_final_project.Recipe.java

License:Open Source License

private void addData(Document doc) {
    //create the format for the % Daily Value
    DecimalFormat onePer = new DecimalFormat("#,##0%");
    try {//from w w  w  . j  av  a  2 s .  c om
        //add the title of the recipe
        doc.add(new Paragraph(title, TITLE_FONT));
        //add each of the ingredients
        for (int i = 0; i < ingredients.size(); i++) {
            doc.add(new Paragraph(ingredients.get(i).getFormattedName(), LABEL_NORMAL));
        }
        //add the instructions
        Paragraph p = new Paragraph();
        if (!instructions.equals("")) {
            p = new Paragraph(new Phrase("Instructions:\n", LABEL_FONT));
            doc.add(p);
            p = new Paragraph();
            p.add(new Phrase(instructions + "\n", LABEL_NORMAL));
        } else {
            p.add(new Phrase("\n"));
        }
        //create the nutrient value table
        PdfPTable label = new PdfPTable(10);
        label.setWidthPercentage(30);
        //Top
        PdfPCell c = new PdfPCell(new Phrase("Nutrition Facts", LABEL_FONT));
        c.setColspan(10);
        c.setBorderWidthBottom(0);
        label.addCell(c);
        c = new PdfPCell(new Phrase("Per " + servingName, LABEL_BOLD));
        c.setColspan(10);
        c.setBorderWidthTop(0);
        label.addCell(c);
        //Amount
        PdfPCell c2a = new PdfPCell(new Phrase("Amount", LABEL_SMALL));
        c2a.setColspan(3);
        c2a.setBorderWidthRight(0);
        PdfPCell c2b = new PdfPCell(new Phrase("% Daily Value", LABEL_SMALL));
        c2b.setColspan(10);
        c2b.setHorizontalAlignment(Element.ALIGN_RIGHT);
        c2b.setBorderWidthLeft(0);
        label.addCell(c2a);
        label.addCell(c2b);
        //Calories
        c = new PdfPCell(new Phrase("Calories " + (int) (nutrients[208] / servings), LABEL_BOLD));
        c.setColspan(10);
        c.setBorderWidthTop(2);
        label.addCell(c);
        //Fat
        PdfPCell ca = new PdfPCell(new Phrase("Fat " + (int) (nutrients[204] / servings) + "g", LABEL_BOLD));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        PdfPCell cb = new PdfPCell(new Phrase(onePer.format((nutrients[204] / servings) / 60.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //fat 2
        ca = new PdfPCell(new Phrase("Saturated " + ((int) (nutrients[606] / servings)) + "g\n\t+ Trans "
                + ((int) (nutrients[605] / servings)) + "g", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setIndent(16);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[606] / servings) / 20.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Cholesterol
        c = new PdfPCell(new Phrase("Cholesterol " + ((int) (nutrients[601] / servings)) + "mg", LABEL_BOLD));
        c.setColspan(10);
        label.addCell(c);
        //Sodium
        ca = new PdfPCell(new Phrase("Sodium " + (int) (nutrients[307] / servings) + "mg", LABEL_BOLD));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[307] / servings) / 2400.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Carbs
        ca = new PdfPCell(new Phrase("Carbohydrate " + (int) (nutrients[205] / servings) + "g", LABEL_BOLD));
        ca.setColspan(7);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[205] / servings) / 300.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Fibre
        ca = new PdfPCell(new Phrase("Fibre " + (int) (nutrients[291] / servings) + "g", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setIndent(16);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[291] / servings) / 25.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Sugar
        ca = new PdfPCell(new Phrase("Sugars " + (int) (nutrients[269] / servings) + "g", LABEL_NORMAL));
        ca.setColspan(10);
        ca.setIndent(16);
        label.addCell(ca);
        //Protein
        ca = new PdfPCell(new Phrase("Protein " + (int) (nutrients[203] / servings) + "g", LABEL_BOLD));
        ca.setColspan(10);
        label.addCell(ca);
        //Vit A
        ca = new PdfPCell(new Phrase("Vitamin A", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        ca.setBorderWidthTop(2);
        cb = new PdfPCell(cb = new PdfPCell(new Phrase(
                onePer.format(
                        ((nutrients[319] + (nutrients[321] / 12) + (nutrients[834] / 24)) / servings) / 1000),
                LABEL_NORMAL)));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        cb.setBorderWidthTop(2);
        label.addCell(ca);
        label.addCell(cb);
        //Vit C
        ca = new PdfPCell(new Phrase("Vitamin C", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[401] / servings) / 60.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Calcium
        ca = new PdfPCell(new Phrase("Calcium", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[301] / servings) / 1100.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Iron
        ca = new PdfPCell(new Phrase("Iron", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[303] / servings) / 14.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Add to the table
        label.setHorizontalAlignment(Element.ALIGN_LEFT);
        p.add(label);
        //add to the document
        doc.add(p);

    } catch (DocumentException ex) {
        System.out.println("Error: " + ex.toString());
    }
}

From source file:ictproject.ReportGenerator.java

private PdfPTable janajatiAnusar(String name) throws Exception {
    PdfPTable table = new PdfPTable(8);
    table.setWidths(new int[] { 1, 1, 2, 2, 2, 2, 2, 2 });
    PdfPCell cell;
    cell = new PdfPCell(getNepaliPhrase("l;=g+="));//s.no
    cell.setRowspan(2);/*  w w w . j a v  a 2s.  c  o m*/
    table.addCell(cell);

    cell = new PdfPCell(getNepaliPhrase("j8f g+="));//ward no
    cell.setRowspan(2);
    table.addCell(cell);
    cell = new PdfPCell(getNepaliPhrase("hfthftL cg';f/sf] 3/w'/Lsf] ljj/0f ;+Vof"));// ? ?  ?"));
    cell.setColspan(5);
    table.addCell(cell);
    cell = new PdfPCell(getNepaliPhrase("s}lkmot"));//"));
    cell.setRowspan(2);
    table.addCell(cell);
    table.addCell(getNepaliPhrase("blnt"));//"));
    table.addCell(getNepaliPhrase("cflbjf;LhghftL"));///"));
    table.addCell(getNepaliPhrase("d'lZnd"));//muslim
    table.addCell(getNepaliPhrase("cGo"));//?"));
    table.addCell(getNepaliPhrase("hDdf"));//?"));
    try {
        Statement stmt = conn.createStatement();
        String sql;
        sql = "SELECT * from  janajatianusarkogharduri where name='" + name + "'";
        ResultSet rs = stmt.executeQuery(sql);

        //STEP 5: Extract data from result set
        while (rs.next()) {
            table.addCell(numberConverterToUnicode(rs.getString("sno")));
            table.addCell(numberConverterToUnicode(rs.getString("wardNo")));
            table.addCell(numberConverterToUnicode(rs.getString("dalit")));
            table.addCell(numberConverterToUnicode(rs.getString("adiwsi")));
            table.addCell(numberConverterToUnicode(rs.getString("muslim")));
            table.addCell(numberConverterToUnicode(rs.getString("anya")));
            table.addCell(numberConverterToUnicode(rs.getString("jamma")));
            table.addCell(getNepaliPhrase(converter(rs.getString("remarks"))));

        }

    } catch (SQLException se) {
        //Handle errors for JDBC
        se.printStackTrace();
    }
    table.addCell(getNepaliPhrase("hDdf"));//jamma
    table.addCell("");
    table.addCell(getSum(name, "dalit", "janajatianusarkogharduri"));
    table.addCell(getSum(name, "adiwsi", "janajatianusarkogharduri"));
    table.addCell(getSum(name, "muslim", "janajatianusarkogharduri"));
    table.addCell(getSum(name, "anya", "janajatianusarkogharduri"));
    table.addCell(getSum(name, "jamma", "janajatianusarkogharduri"));
    table.addCell("");

    return table;
}