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

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

Introduction

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

Prototype

public void setHorizontalAlignment(int horizontalAlignment) 

Source Link

Document

Sets the horizontal alignment for the cell.

Usage

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 w w. ja v a2  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  a va  2  s.c om*/
        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_Apoteker.Panel_Detil_PO.java

private PdfPTable createTableBulanan(List<detil_pesan_obat> a) {
    PdfPTable tabel = new PdfPTable(2);
    PdfPCell cell;
    cell = new PdfPCell(new Phrase(("Nama Obat"), font6));
    cell.setRowspan(2);//from  ww  w  .j a v  a2  s.  co m
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    tabel.addCell(cell);
    cell = new PdfPCell(new Phrase(("Jumlah Obat yang dipesan"), font6));
    cell.setRowspan(2);
    cell.setBorder(Rectangle.BOX);
    cell.setBorderWidth(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    tabel.addCell(cell);
    for (int i = 0; i < a.size(); i++) {
        cell = new PdfPCell(new Phrase(("" + a.get(i).getNama_Obat()), font5));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        tabel.addCell(cell);

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

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 ww w .  java 2 s  .  c  o  m
    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:has.GenerateReceipt.java

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

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //   addEmptyLine(preface, 2);
    PdfPCell c1 = new PdfPCell(new Phrase("slno"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);//from  w  ww .j a v a2s . co m

    c1 = new PdfPCell(new Phrase("Date"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Item"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("price"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    table.setHeaderRows(1);

    CateringObject obj = (CateringObject) Catering.elementAt(0);
    float Totalbill = (float) obj.bill;
    //    tb.addRow(new Object[]{new String(rs.getString("Name")),new String(rs.getString("I")),new String(obj.date),new String(obj.item),new Double(obj.bill) });
    for (int f = 1; f < Catering.size(); f++) {
        obj = (CateringObject) Catering.elementAt(f);
        table.addCell("" + obj.date);
        table.addCell("" + obj.item);
        table.addCell("" + obj.bill);

        //  tb.addRow   (new Object[]{new String(""),new String(""),new String(obj.date),new String(obj.item),new Double(obj.bill) });
        Totalbill = (float) (Totalbill + obj.bill);
    }

    /*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:hsa.awp.admingui.report.printer.PdfPrinter.java

License:Open Source License

@Override
public void print(ExportList list) {

    if (outputStream == null) {
        throw new IllegalArgumentException("OutputStream undefined, please use setOutputStream()");
    }/*from w  w  w  .  j  a v  a  2 s. c o m*/

    if (!(list instanceof PdfPrintable)) {
        throw new IllegalArgumentException("PdfPrinter can only print PdfPrintables");
    }

    PdfPrintable pdfPrintable = (PdfPrintable) list;
    Document document = setUpDocument(pdfPrintable);

    try {
        document.open();

        int numberOfColumns = pdfPrintable.getPdfProperties().getCellProperties().size();
        int numberOfRows = list.getRows().size();

        PdfPTable table = new PdfPTable(numberOfColumns);

        float[] widths = new float[numberOfColumns];

        for (int i = 0; i < widths.length; i++) {
            widths[i] = pdfPrintable.getPdfProperties().getCellProperties().get(i).getWidth();
        }

        table.setWidths(widths);

        /* header */
        for (PdfCellProperties cellProperties : pdfPrintable.getPdfProperties().getCellProperties()) {
            PdfPCell cell = new PdfPCell(
                    new Phrase(cellProperties.getHeadline(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
        }

        /* content */
        int rowIndex = 0;
        for (Row row : list.getRows()) {
            int columnIndex = 0;
            for (String content : row.getContent()) {
                if (content != null) {
                    PdfPCell cell = new PdfPCell(
                            new Phrase(content, FontFactory.getFont(FontFactory.HELVETICA)));
                    cell.setHorizontalAlignment(pdfPrintable.getPdfProperties().getCellProperties()
                            .get(columnIndex).getAlignment().getPdfAlign());
                    table.addCell(cell);
                } else {
                    table.addCell("");
                }
                columnIndex++;
            }
            rowIndex++;
        }

        //      /* footer */
        //      if (footerFound) {
        //        for (PdfTableColumn tableColumn : cols) {
        //          table.addCell(tableColumn.getFooter());
        //        }
        //      }

        document.add(table);

        document.add(new Phrase(" "));

        document.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

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++;/*  www .  jav  a  2s  .  co m*/

        }

        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  w  w.j a  v  a2s .  co 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 a va  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

public PdfPCell getNepaliPhrase(String word) {
    PdfPCell cell = new PdfPCell(new Phrase(new Chunk(word, fontNormal)));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    return cell;/*from w  ww .ja v  a2 s.co m*/
}