Example usage for com.itextpdf.text Phrase Phrase

List of usage examples for com.itextpdf.text Phrase Phrase

Introduction

In this page you can find the example usage for com.itextpdf.text Phrase Phrase.

Prototype

private Phrase(final boolean dummy) 

Source Link

Document

Constructs a Phrase that can be used in the static getInstance() method.

Usage

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private PdfPTable createOrderButton(Model model) throws IOException, BadElementException {

    final Chunk chunk = new Chunk("Order on taconic.com", iTextUtil.getFontButton());
    chunk.setAction(/*from   w  w  w .  j  av  a2s  .c  o m*/
            new PdfAction("http://www.taconic.com/start-an-order?modelNumber=" + model.getModelNumber()));

    final PdfPCell cell = cell(new Phrase(chunk));
    cell.setBackgroundColor(iTextUtil.getTaconicRed());
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(8);

    final PdfPTable button = new PdfPTable(new float[] { 80f, 20f });
    button.addCell(cell(new Phrase(" "), 2));
    button.addCell(cell);
    button.addCell(cell(new Phrase(" ")));
    button.addCell(cell(new Phrase(" "), 2));

    return button;
}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] stampTableOfContents(byte[] pdf, Toc tableOfContents) throws IOException, DocumentException {

    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {

        final PdfReader reader = new PdfReader(pdf);
        final PdfStamper stamper = new PdfStamper(reader, bos);

        // stamp the named destinations
        for (int pageNumber = 1; pageNumber <= reader.getNumberOfPages(); pageNumber++) {
            stamper.addNamedDestination("page" + pageNumber, pageNumber,
                    new PdfDestination(PdfDestination.XYZ, 80f, 800f, 0));
        }//from  ww  w  . ja  v a 2 s  .c o  m

        // create the table of contents
        final Chunk tocTitle = new Chunk("TABLE OF CONTENTS", iTextUtil.getFontTocTitle());

        int currentTocPage = tableOfContents.getFirstPageOfToc();
        int firstTocPage = currentTocPage;
        PdfContentByte canvas = stamper.getOverContent(currentTocPage);

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(tocTitle), 55, 470, 0);

        final List<TocEntry> entriesSorted = tableOfContents.getEntriesSorted();
        int tocEntryNumber = 0;
        for (TocEntry tocEntry : entriesSorted) {

            if (tocEntry.isIncludedInToc()) {
                tocEntryNumber++;

                // take the right TOC page to stamp the TOC entry on (needed for TOC's with multiple pages)
                if (tocEntryNumber == getNumberOfItemsPerTocPage(0)
                        || (tocEntryNumber > getNumberOfItemsPerTocPage(0)
                                && (tocEntryNumber - getNumberOfItemsPerTocPage(0))
                                        % getNumberOfItemsPerTocPage(currentTocPage - firstTocPage) == 0)) {
                    currentTocPage++;
                    canvas = stamper.getOverContent(currentTocPage);
                }

                Font font = iTextUtil.getFontToc();
                if (tocEntry.getLevel() == 1) {
                    font = iTextUtil.getFontTocBold();
                }

                final Phrase p = processHtmlCodes(tocEntry.getLevelString() + tocEntry.getName(), font,
                        iTextUtil.getFontTocSymbol());
                p.add(new Chunk("", iTextUtil.getFontToc()));
                if (tocEntry.isShowingPageNumber()) {
                    p.add(new Chunk(new DottedLineSeparator()));
                    p.add(new Chunk("  " + String.valueOf(tocEntry.getFinalPageNumber()),
                            iTextUtil.getFontToc()));
                }

                for (Chunk chunk : p.getChunks()) {
                    chunk.setAction(PdfAction.gotoLocalPage("page" + tocEntry.getFinalPageNumber(), false));
                }

                int y;
                if (tocEntryNumber < getNumberOfItemsPerTocPage(0)) {
                    y = 460 - (16 * (tocEntryNumber % getNumberOfItemsPerTocPage(0)));
                } else {
                    y = 680 - (16 * ((tocEntryNumber - getNumberOfItemsPerTocPage(0))
                            % getNumberOfItemsPerTocPage(currentTocPage - firstTocPage)));
                }

                final ColumnText ct = new ColumnText(canvas);
                ct.setSimpleColumn(p, 52, y, 555, 70, 0, Element.ALIGN_JUSTIFIED);
                ct.go();

            }
        }

        stamper.close();
        reader.close();

        return bos.toByteArray();

    }

}

From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java

License:Open Source License

private byte[] enableLinkToWebsite(byte[] pdf, Toc tableOfContents) throws IOException, DocumentException {

    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {

        final PdfReader reader = new PdfReader(pdf);

        final PdfStamper stamper = new PdfStamper(reader, bos);

        for (int i = tableOfContents.getFirstPageOfToc(); i <= tableOfContents
                .getLastPageNumberOfModelPages(); i++) {

            final Chunk websiteChunk = new Chunk("..................");
            websiteChunk.setAction(new PdfAction(websiteLink));

            ColumnText ct = new ColumnText(stamper.getUnderContent(i));
            ct.setSimpleColumn(335, 10, 400, 35);
            ct.addText(new Phrase(websiteChunk));
            ct.go();/*from  ww  w  .  j a va2 s  .c o m*/

            final Chunk emailChunk = new Chunk(".........................................");
            emailChunk.setAction(new PdfAction(emailLink));

            ct = new ColumnText(stamper.getUnderContent(i));
            ct.setSimpleColumn(240, 10, 330, 35);
            ct.addText(new Phrase(emailChunk));
            ct.go();

        }

        stamper.close();
        reader.close();
        return bos.toByteArray();

    }

}

From source file:be.thomasmore.service.CreatePDFServiceImp.java

@Override
public void createPDF(List<Score> scores) {
    try {//from  w w  w.jav a2s .co  m
        OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        document.add(new Paragraph("Scores"));
        document.add(new Paragraph(new Date().toString()));

        document.addAuthor("Projectgroep 4");
        document.addCreator("Projectgroep 4");
        document.addTitle("ScoreTracker");

        //Create Paragraph
        Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));

        //New line
        paragraph.add(new Paragraph(" "));
        paragraph.add("Scores");
        paragraph.add(new Paragraph(" "));
        document.add(paragraph);

        //Create a table in PDF
        PdfPTable pdftabel = new PdfPTable(4);
        PdfPCell cell1 = new PdfPCell(new Phrase("Student"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Vak"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Test"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Score"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        pdftabel.setHeaderRows(1);

        for (Score score : scores) {
            pdftabel.addCell(score.getStudent().getNaam());
            pdftabel.addCell(score.getTest().getVak().getNaam());
            pdftabel.addCell(score.getTest().getNaam());
            int resultaat = score.getScore();
            pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal());
        }

        document.add(pdftabel);
        document.addCreationDate();
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:be.thomasmore.service.CreatePDFServiceImp.java

@Override
public void createPDFVoorStudent(ArrayList<ArrayList<Score>> puntenlijst, List<Double> gemiddeldelijst,
        Double totaalGemiddelde) {
    try {//from ww  w.  ja va2 s.  c  o m
        OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        document.add(new Paragraph("Scores"));
        document.add(new Paragraph(puntenlijst.get(0).get(0).getStudent().getNaam()));
        document.add(new Paragraph(new Date().toString()));

        document.addAuthor("Projectgroep 4");
        document.addCreator("Projectgroep 4");
        document.addTitle("ScoreTracker");

        //Create Paragraph
        Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));

        //New line
        paragraph.add(new Paragraph(" "));
        paragraph.add("Scores");
        paragraph.add(new Paragraph(" "));
        document.add(paragraph);

        for (int i = 0; i < puntenlijst.size(); i++) {
            //Create a table in PDF
            PdfPTable pdftabel = new PdfPTable(2);
            //vak invullen
            paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
            paragraph.add(new Paragraph(puntenlijst.get(i).get(0).getTest().getVak().getNaam()));
            document.add(paragraph);

            PdfPCell cell1 = new PdfPCell(new Phrase("Test"));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdftabel.addCell(cell1);

            cell1 = new PdfPCell(new Phrase("Score"));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdftabel.addCell(cell1);

            pdftabel.setHeaderRows(1);

            for (Score score : puntenlijst.get(i)) {
                pdftabel.addCell(score.getTest().getNaam());
                int resultaat = score.getScore();
                pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal());
            }

            document.add(pdftabel);

            //gemmidelde per vak invoeren
            paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
            paragraph.add(new Paragraph("Gemiddelde: " + gemiddeldelijst.get(i).toString()));
            document.add(paragraph);
        }
        paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        paragraph.add(new Paragraph("Algemeen gemiddelde: " + totaalGemiddelde));
        document.add(paragraph);
        document.addCreationDate();
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;/* w  ww. j av  a 2 s . c  o  m*/
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

                    mypdf.add(new Paragraph("  "));

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));
                    mypdf.add(new Paragraph("  "));

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

    } catch (DocumentException ex) {
        Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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);//  w w  w.  j ava 2  s  .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.j  ava2  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);/*from   w ww. ja v a  2s .  com*/

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

    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:bookshopautomationsoftware.GenerateReceipt.java

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

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    addEmptyLine(preface, 2);//from  ww  w .  ja va2 s .c  o m
    PdfPCell c1 = new PdfPCell(new Phrase("slno"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

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

    c1 = new PdfPCell(new Phrase("quantity"));
    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);

    try {
        Connection con = DriverManager.getConnection(DB_URL1, USER1, PASS1);
        Statement stmnt = con.createStatement();
        String sql = "SELECT slno,book,quantity FROM cart";
        Connection con1 = DriverManager.getConnection(DB_URL1, USER1, PASS1);
        Statement stmnt1 = con.createStatement();
        int count = 0;
        ResultSet rs = stmnt.executeQuery(sql);
        ResultSet rs1;
        float total = 0;
        while (rs.next()) {
            String sql1 = "SELECT isbn,price FROM booktable WHERE isbn = " + rs.getLong("book");
            rs1 = stmnt1.executeQuery(sql1);
            rs1.next();
            count++;
            table.addCell("" + rs.getInt("slno"));
            table.addCell("" + rs.getLong("book"));
            table.addCell("" + rs.getInt("quantity"));
            table.addCell("" + rs1.getFloat("price"));
            total += (rs1.getFloat("price")) * (rs.getInt("quantity"));

            //  model.addRow(new Object[]{(""+rs.getInt("slno")),""+rs.getLong("book"),""+rs.getInt("quantity")});
        }
        table.addCell("");
        table.addCell("");
        table.addCell("");
        table.addCell("" + total);
        if (count == 0) {
            // dispose();

            return;
        }

    } catch (Exception e) {
        System.out.println(" " + e + " is caught");
    }
    /*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);

}