Example usage for com.itextpdf.layout.element Table addHeaderCell

List of usage examples for com.itextpdf.layout.element Table addHeaderCell

Introduction

In this page you can find the example usage for com.itextpdf.layout.element Table addHeaderCell.

Prototype

public Table addHeaderCell(String content) 

Source Link

Document

Adds a new cell with received string as a content to the header of the table.

Usage

From source file:com.isw.cec.Servlet.GenerarFoliosServlet.java

License:Open Source License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String appPath = request.getServletContext().getRealPath("");
    String savePath = appPath + File.separator + SAVE_DIR;

    File fileSaveDir = new File(savePath);
    if (!fileSaveDir.exists())
        fileSaveDir.mkdirs();//from w ww.ja v a  2s . com

    String fileName = java.util.UUID.randomUUID().toString() + ".pdf";
    Curso curso = (Curso) request.getAttribute("curso");
    List<Entry<String, String>> alum_fol = Reader.getAlumFolios(curso.getID());

    OutputStream fos = new FileOutputStream(savePath + File.separator + fileName);
    PdfWriter writer = new PdfWriter(fos);

    PdfDocument pdf = new PdfDocument(writer);

    Document document = new Document(pdf, PageSize.A4);
    document.setMargins(85, 57, 71, 71);

    PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
    PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);

    Paragraph p = new Paragraph("Folios de los alumnos inscritos al curso");
    p.setTextAlignment(TextAlignment.CENTER);
    document.add(p);

    p = new Paragraph(curso.getNombre());
    p.setFont(bold);
    p.setTextAlignment(TextAlignment.CENTER);
    p.setMarginBottom(70);
    document.add(p);

    Table table = new Table(new float[] { 1, 1 });
    table.setWidthPercent(100);

    Cell c = new Cell().add(new Paragraph("ALUMNO").setFont(bold));
    c.setTextAlignment(TextAlignment.CENTER);
    table.addHeaderCell(c);

    c = new Cell().add(new Paragraph("FOLIO").setFont(bold));
    c.setTextAlignment(TextAlignment.CENTER);
    table.addHeaderCell(c);

    for (Entry<String, String> e : alum_fol) {
        table.addCell(new Cell().add(new Paragraph(e.getKey()).setFont(font)));
        table.addCell(new Cell().add(new Paragraph(e.getValue()).setFont(font)));
    }

    document.add(table);

    document.close();

    Writer.openCurso(curso.getID(), fileName);
    response.getWriter().println("OK");
}

From source file:com.tcay.slalom.UI.PDF.PDF_Results.java

License:Open Source License

public void doit(String title, ArrayList<RaceRun> runs, boolean breakOnClassChange) {
    Document doc = null;//from w w w .ja  v  a2s.  c o m
    Table table = null;

    try {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        // new PDF_Results().manipulatePdf(DEST);

        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST));
        //Document
        doc = new Document(pdfDoc);

        table = new Table(9); // # of columns
        // for (int i = 0; i < 16; i++) {
        //     table.addCell("hi");
        // }

    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
    }

    String lastBoatClass = null;
    for (RaceRun r : runs) {

        float totalTime;

        if (breakOnClassChange) {
            if (lastBoatClass != null) {
                if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0)
                    ;
                //   log.info("---");
            }
            lastBoatClass = r.getBoat().getBoatClass();
        }
        totalTime = (float) r.getTotalPenalties();
        totalTime += r.getElapsed();
    }

    try {

        ArrayList<Result> sorted = Race.getInstance().getTempResults();
        for (Result r : sorted) {
            if (true || breakOnClassChange) { //Fixme  constant true
                if (lastBoatClass != null) {
                    if (lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0)
                        ;
                    //                            output.newLine();
                }
                if (lastBoatClass == null || lastBoatClass.compareTo(r.getBoat().getBoatClass()) != 0) {
                    //                        output.write(r.getBoat().getBoatClass());
                    //                        output.newLine();
                }
                lastBoatClass = r.getBoat().getBoatClass();
            }
            String s1;

            //                Cell cell23 = new Cell(1, 6).add("a Class ???multi 1,3 and 1,4");
            //                table.addCell(cell23);
            //                table.startNewRow();

            s1 = String.format("%1$3s", r.getBoat().getRacer().getBibNumber());
            table.addCell(s1);

            String s = r.getBoat().getRacer().getShortName();
            s1 = String.format("%1$-15s", s);
            table.addCell(s1);

            s1 = r.getRun1().getResultString();
            table.addCell(s1);

            s1 = r.getRun1().getPenaltyString();
            table.addCell(s1);

            s1 = r.getRun1().getTotalTimeString();
            table.addCell(s1);

            if (r.getRun2() != null) {
                table.startNewRow();

                table.addCell(".");
                table.addCell("..");
                s1 = r.getRun2().getResultString();
                table.addCell(s1);

                s1 = r.getRun2().getPenaltyString();
                table.addCell(s1);

                s1 = r.getRun2().getTotalTimeString();
                table.addCell(s1);

            }
            //                else {
            //    table.addCell("")//;

            //}

            table.startNewRow();

            /// todo must integrate TH results before sort  - DONE VERIFY 10/11/2013
            //                output.write("   best=");
            //                s1 = r.getBestRun() != null ? r.getBestRun().formatTimeTotalOnly() : RaceRun.TIME_ONLY_FILL;
            //                output.write(s1);

            //                if (r.getBestRun().getPhotoCellRaceRun() != null) {    /// todo must integrate TH results before sort
            //                    output.write(ResultsTable.TIMINGMODE_AUTOMATIC);
            //                }
            //                output.newLine();
        }

        PdfFont f = PdfFontFactory.createFont(FontConstants.HELVETICA);
        Cell cell = new Cell(1, 3);

        cell.add(new Paragraph("Class K1 ... or whateever")).setFont(f).setFontSize(13)
                .setFontColor(DeviceGray.WHITE).setBackgroundColor(DeviceGray.BLACK);
        //  .setTextAlignment(TextAlignment.CENTER);

        table.addHeaderCell(cell);

        /*            for (int i = 0; i < 2; i++) {
        Cell[] headerFooter = new Cell[] {
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("#"),
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Key"),
                new Cell().setBackgroundColor(new DeviceGray(0.75f)).add("Value")
        };
        for (Cell hfCell : headerFooter) {
            if (i == 0) {
                table.addHeaderCell(hfCell);
            } else {
                table.addFooterCell(hfCell);
            }
        }
                    }
                    for (int counter = 1; counter < 20; counter++) {
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add(String.valueOf(counter)));
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("key " + counter));
        table.addCell(new Cell().setTextAlignment(TextAlignment.CENTER).add("value " + counter));
                    }
                
        */

        doc.add(table);

        doc.close();

    } catch (Exception e) {
        System.out.println(e);
        System.out.println(e.getStackTrace());
        e.printStackTrace();

        //           log.write(e);
    } finally {
        try {
            //                output.close();
        } catch (Exception ex) {
            System.out.println(ex);
            System.out.println(ex.getStackTrace());

            ex.printStackTrace();

        }
    }

}

From source file:model.PrintPDF.java

public void inThongKeCanBo(ArrayList<CanBo> listCanBo, String pathName, String nam, int gt, String tongNhanVien,
        String soNVVH) {/*from w ww. ja v  a2  s  . c  o m*/
    PdfWriter pdfWriter = null;
    String gioiTinh = "";
    if (gt == 1) {
        gioiTinh = "n";
    } else {
        gioiTinh = "nam";
    }

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cn b " + gioiTinh + " nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S in thoi").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listCanBo.size(); i++) {
            table.addCell(new Paragraph((i + 1) + "").setFont(hfont).setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getMaCB()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getHoTen()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(dateFormat.format(listCanBo.get(i).getNgaySinh())).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
            table.addCell(new Paragraph(listCanBo.get(i).getSDT()).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER));
        }
        document.add(table);
        document.add(new Paragraph("\n\n Tng s nhn vin            :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" Tng s nhn vin sp v? hu :  " + tongNhanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));

        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:model.PrintPDF.java

public void thongKeDoanPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongDoanVien,
        String tienDoanPhi) {//from   w w  w. j av a 2s. c om
    PdfWriter pdfWriter = null;
    String gioiTinh = "";

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k on vin  " + gioiTinh + " nm " + nam + "\n\n")
                .setFont(hfont).setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S ti khon ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph("\n\n Tng s on vin           :  " + tongDoanVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" ?on ph (VN? / ?on Vin) :  " + tienDoanPhi + "VN?")
                .setFont(hfont).setTextAlignment(TextAlignment.LEFT));
        double tongTienDoanPhi = Integer.parseInt(tongDoanVien) * Integer.parseInt(tienDoanPhi);
        document.add(new Paragraph(" Tng s ti?n on ph            :  " + tongTienDoanPhi + " VND")
                .setFont(hfont).setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeCongDoanPhi(ArrayList<String> listDataTable, String pathName, String nam,
        String tongCongDoanVien, String tienCongDoanPhi) {
    PdfWriter pdfWriter = null;//ww  w.j  a  v  a  2  s  .c om

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cng on vin  nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 3, 3 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Chc v ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Cng on ph ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph("\n\n Tng s nhn vin           :  " + tongCongDoanVien)
                .setFont(hfont).setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(" Tng cng on ph  :  " + tienCongDoanPhi).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));

        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeDangPhi(ArrayList<String> listDataTable, String pathName, String nam, String tongDangVien) {
    PdfWriter pdfWriter = null;//ww w .jav  a 2s .c  o m

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k ng vin  " + " nm " + nam + "\n\n").setFont(hfont)
                .setBold().setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Chc v ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("?ng ph ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph("\n\n Tng s ng vin           :  " + tongDangVien).setFont(hfont)
                .setTextAlignment(TextAlignment.LEFT));
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeTienThi(ArrayList<String> listDataTable, String pathName) {
    PdfWriter pdfWriter = null;//from   ww  w  .  j a  va 2 s  .c om

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k ti?n thi ging vin  " + "\n\n").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 2, 4, 3, 4, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Mn h?c").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("S SV ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ph thi").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:model.PrintPDF.java

public void thongKeThieuNhi(ArrayList<String> listDataTable, String pathName) {
    PdfWriter pdfWriter = null;/*w ww .  jav  a  2 s . c  o m*/

    try {
        pdfWriter = new PdfWriter(pathName);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        Document document = new Document(pdfDocument, PageSize.A4.rotate());
        PdfFont hfont = PdfFontFactory.createFont("C:\\Windows\\Fonts\\tahoma.ttf", PdfEncodings.IDENTITY_H,
                true);
        document.setMargins(50, 50, 50, 50);
        document.add(new Paragraph("TRNG ?I HC B?CH KHOA H NI ").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(16));
        document.add(new Paragraph("Thng k cc chu thiu nhi   " + "\n\n").setFont(hfont).setBold()
                .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        float[] columnWidths = { 1, 3, 3, 3, 4 };
        Table table = new Table(columnWidths);
        table.setWidthPercent(100);
        table.addHeaderCell(new Paragraph("STT").setFont(hfont).setTextAlignment(TextAlignment.CENTER).setBold()
                .setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("Ngy sinh ").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("M cn b").setFont(hfont).setTextAlignment(TextAlignment.CENTER)
                .setBold().setFontSize(14));
        table.addHeaderCell(new Paragraph("H? v tn cn b ").setFont(hfont)
                .setTextAlignment(TextAlignment.CENTER).setBold().setFontSize(14));

        //  ni dung ca bng thng k
        for (int i = 0; i < listDataTable.size(); i++) {
            table.addCell(new Paragraph(listDataTable.get(i)).setFont(hfont)
                    .setTextAlignment(TextAlignment.CENTER).setFontSize(14));
        }

        document.add(table);
        document.add(new Paragraph(
                "\n\n\n H Ni, ngy    thng        nm     \n  Ng?i lp phiu \n  ( Ghi r h? tn) ")
                        .setFont(hfont).setTextAlignment(TextAlignment.RIGHT).setItalic().setMarginRight(40));
        document.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pdfWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(PrintPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:Utils.PdfUtil.java

private void addContent(Document document) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Paragraph paragraphCustomer = new Paragraph();
    paragraphCustomer.add(new Text("Khch hng ").setFont(mCommonFont));
    com.itextpdf.layout.element.List listCustomer = new com.itextpdf.layout.element.List().setSymbolIndent(12)
            .setListSymbol("\u2022").setFont(mCommonFont);
    listCustomer.add(new ListItem("H? tn: " + mCustomer.getFullname()))
            .add(new ListItem("Chng minh nhn dn: " + mCustomer.getIdentityCode()))
            .add(new ListItem("S in thoi: " + mCustomer.getPhoneNumber()));
    listCustomer.setMarginLeft(30).setFont(mCommonFont);

    Room objRoom = (new ModelRoom()).getItemById(mRoomStatus.getIdRoom());
    Paragraph paragraphRoom = new Paragraph();
    paragraphRoom.add(new Text("Phng").setFont(mCommonFont));
    com.itextpdf.layout.element.List listRoom = new com.itextpdf.layout.element.List().setSymbolIndent(12)
            .setListSymbol("\u2022").setFont(mCommonFont);
    listRoom.add(new ListItem("Tn phng: " + objRoom.getRoomName()))
            .add(new ListItem("Loi phng: " + Constant.ROOM_TYPE_NAME[objRoom.getType()]))
            .add(new ListItem("Gi: " + CommonFunction.convertDoubleToMoney(objRoom.getPrice()) + ""))
            .add(new ListItem("Ngy n: " + sdf.format(mRoomStatus.getDateCome())))
            .add(new ListItem("Ngy i: " + sdf.format(mRoomStatus.getDateLeave())));
    listRoom.setMarginLeft(30).setFont(mCommonFont);

    Paragraph paragraphService = new Paragraph();
    paragraphService.add(new Text("Dch v").setFont(mCommonFont));
    Table table = new Table(new float[] { 10f, 7f, 5f, 5f, 7f });
    table.setWidthPercent(100).setTextAlignment(TextAlignment.CENTER)
            .setHorizontalAlignment(HorizontalAlignment.CENTER);
    String[] header = { "Tn dch v", "Gi ti?n", "S lng", "Ngy s dng" };
    for (int i = 0, k = header.length; i < k; i++) {
        Cell cellHeader = new Cell();
        cellHeader.add(header[i]);/*from  w w w .j av  a2s  .c  o m*/
        cellHeader.setNextRenderer(new RoundedCornersCellRenderer(cellHeader));
        cellHeader.setPadding(5).setBorder(Border.NO_BORDER);
        table.addHeaderCell(cellHeader);
    }
    double total = 0;
    for (CustomerService objCustomerService : mListCustomerService) {
        total += (objCustomerService.getPrice() * objCustomerService.getNumber());
        for (int i = 0; i < 4; i++) {
            Cell cell = new Cell();
            switch (i) {
            case 0:
                cell.add(objCustomerService.getServiceName());
                break;
            case 1:
                cell.add(CommonFunction.convertDoubleToMoney(objCustomerService.getPrice()) + "");
                break;
            case 2:
                cell.add(objCustomerService.getNumber() + "");
                break;
            case 3:
                cell.add(sdf.format(objCustomerService.getDateUsed()));
                break;
            }
            table.addCell(cell);
        }
    }
    Cell cellFooter = new Cell(1, 3);
    cellFooter.add("Tng ti?n: ");
    table.addCell(cellFooter);
    cellFooter = new Cell();
    cellFooter.add(CommonFunction.convertDoubleToMoney(total) + "");
    table.addCell(cellFooter);

    document.add(paragraphCustomer).add(listCustomer);
    document.add(paragraphRoom).add(listRoom);
    document.add(paragraphService).add(table);
}