Example usage for com.itextpdf.text FontFactory HELVETICA

List of usage examples for com.itextpdf.text FontFactory HELVETICA

Introduction

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

Prototype

String HELVETICA

To view the source code for com.itextpdf.text FontFactory HELVETICA.

Click Source Link

Document

This is a possible value of a base 14 type 1 font

Usage

From source file:bouttime.report.award.AwardReport.java

License:Open Source License

/**
 * Generate an award report.//from   w w w .ja  v a 2s  .co  m
 * @param dao Dao object to use to retrieve data.
 * @param session Session to generate the report for.
 * @param group Group to generate report for.  This takes precedence, so
 * if not null, then the report will be generated for this group.
 * @return True if the report was generated.
 */
private static boolean doReport(Dao dao, String session, Group group) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Award Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<Group> groups;
        if (group != null) {
            groups = new ArrayList<Group>();
            groups.add(group);
        } else if (session != null) {
            groups = dao.getGroupsBySession(session);
        } else {
            groups = dao.getAllGroups();
        }

        for (Group g : groups) {

            // create and add the table
            PdfPTable datatable = new PdfPTable(4);
            int colWidths[] = { 30, 30, 30, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the group name
            headerCell.setPhrase(new Phrase(g.toString(), headerFont));
            headerCell.setColspan(4);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            List<Wrestler> wList = getSortedAwardList(g);

            int i = 0;
            for (Wrestler w : wList) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                Integer place = w.getPlace();
                String placeStr = (place == null) ? "" : place.toString();
                datatable.addCell(new Phrase(placeStr, detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.boutsequence.BoutSequenceReport.java

License:Open Source License

private static void addHeader(Dao dao, Document document, String team, String session)
        throws DocumentException {
    Paragraph p1 = new Paragraph(new Paragraph(
            String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
            FontFactory.getFont(FontFactory.HELVETICA, 10)));
    document.add(p1);//from w  w  w . j a va  2  s.  c o m

    String instructions = "1) The first bout is the first number found in square brackets '[ ]'.\n"
            + "2) If this bout is won, the next bout is the next number found in square brackets.\n"
            + "3) If a bout in square brackets is lost, the next bout is to the LEFT (unless Round Robin).  From this point, go RIGHT-to-LEFT.\n";
    if (dao.isFifthPlaceEnabled()) {
        instructions += "4) Fifth place bouts are in angle brackets '< >'.\n";
    }
    Paragraph p2 = new Paragraph(new Paragraph(instructions, FontFactory.getFont(FontFactory.HELVETICA, 8)));
    document.add(p2);

    StringBuilder sb = new StringBuilder(team);
    if (session != null) {
        sb.append("  /  Session : ");
        sb.append(session);
    }
    Paragraph p3 = new Paragraph(new Paragraph(sb.toString(), FontFactory.getFont(FontFactory.HELVETICA, 12)));
    document.add(p3);
}

From source file:bouttime.report.matkey.MatKeyReport.java

License:Open Source License

/**
 * Generate the Mat Key report.//from  w w  w  .  ja  va  2s .c om
 * This is a color-coded report that maps the groups to a mat.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 */
public static boolean doReport(Dao dao) {
    if (!dao.isOpen()) {
        logger.warn("Cannot create report : DAO not open");
        return false;
    }

    String matValues = dao.getMatValues();
    if ((matValues == null) || matValues.isEmpty()) {
        JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame();
        JOptionPane.showMessageDialog(mainFrame,
                "Mat values are not configured." + "\nSet the mat values in 'Edit -> Configuration'",
                "Mat Key Report error", JOptionPane.WARNING_MESSAGE);
        logger.warn("Cannot create report : mat values not configured");
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Mat Key Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        int cols = 4; // Class, Div, Weight, Mat

        // create and add the table
        PdfPTable datatable = new PdfPTable(cols);
        //int colWidths[] = { 55, 15, 15, 15 };   // percentage
        //datatable.setWidths(colWidths);
        datatable.getDefaultCell().setPadding(3);
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        datatable.addCell("Class");
        datatable.addCell("Div");
        datatable.addCell("Weight");
        datatable.addCell("Mat");
        datatable.setHeaderRows(1); // this is the end of the table header

        datatable.getDefaultCell().setBorderWidth(1);

        // Prepare the list of groups
        List<Group> groups = dao.getAllGroups();
        Collections.sort(groups, new GroupClassDivWtSort());

        // Prepare the list of mat values
        String[] mats = matValues.split(",");
        List<String> matList = new ArrayList<String>();
        for (String m : mats) {
            matList.add(m.trim());
        }

        for (Group g : groups) {
            String mat = g.getMat();
            int idx = matList.indexOf(mat);
            datatable.getDefaultCell().setBackgroundColor(colorMap.get(idx));

            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            datatable.addCell(g.getClassification());
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            datatable.addCell(g.getAgeDivision());
            datatable.addCell(g.getWeightClass());
            datatable.addCell(g.getMat());
        }

        datatable.setSpacingBefore(15f); // space between title and table
        document.add(datatable);

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.team.TeamReport.java

License:Open Source License

/**
 * Generate a summary report of the teams in the tournament.
 * This report lists the teams and the number of wresters on the team.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 *//*from  w  w  w  .  j a  v a  2  s  . c  o  m*/
public static boolean doSummary(Dao dao) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Team Summary Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        int cols = 2; // Team name and Total
        String classVals = dao.getClassificationValues();
        String[] classes = null;
        if (classVals != null) {
            if (classVals.length() > 0) {
                classes = classVals.split(",");
                cols += classes.length;
            }
        }

        // create and add the table
        PdfPTable datatable = new PdfPTable(cols);
        //int colWidths[] = { 55, 15, 15, 15 };   // percentage
        //datatable.setWidths(colWidths);
        datatable.getDefaultCell().setPadding(3);
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        datatable.addCell("Team Name");

        // Make a column for each classification value
        int[] classesTotals = null;
        if (classes != null) {
            for (String c : classes) {
                datatable.addCell(c.trim());
            }
            classesTotals = new int[classes.length];
            for (int i = 0; i < classesTotals.length; i++) {
                classesTotals[i] = 0;
            }
        }
        datatable.addCell("Total");
        datatable.setHeaderRows(1); // this is the end of the table header

        datatable.getDefaultCell().setBorderWidth(1);

        List<String> teams = dao.getTeams();

        int total = 0; // total count of all wrestlers in this method
        int i = 0;
        for (String t : teams) {
            if ((i++ % 2) == 0) {
                datatable.getDefaultCell().setGrayFill(0.9f);
            } else {
                datatable.getDefaultCell().setGrayFill(1);
            }

            List<Wrestler> wrestlers = dao.getWrestlersByTeam(t);
            int count = wrestlers.size();
            int rowTotal = 0;
            total += count;

            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            datatable.addCell(t);
            if (classes != null) {
                //for (String c : classes) {
                for (int idx = 0; idx < classes.length; idx++) {
                    String c = classes[idx].trim();
                    List<Wrestler> wrestlers2 = dao.getWrestlersByTeamClass(t, c);
                    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                    int count2 = wrestlers2.size();
                    datatable.addCell(Integer.toString(count2));
                    classesTotals[idx] += count2;
                    rowTotal += count2;
                }
            }

            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
            datatable.addCell(Integer.toString(count));

            // Check if there is an error in the counts.
            if ((classes != null) && (rowTotal != count)) {
                JFrame mainFrame = BoutTimeApp.getApplication().getMainFrame();
                JOptionPane.showMessageDialog(mainFrame,
                        "There is an error" + " with the total count for team '" + t + "'.\n" + "This is "
                                + "most likely due to an incorrect classification value\nfor "
                                + "one or more wrestlers.",
                        "Team count error", JOptionPane.WARNING_MESSAGE);
            }
        }

        // Add totals row
        datatable.getDefaultCell().setGrayFill(0.7f);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell("Total");
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        if (classes != null) {
            for (int idx = 0; idx < classesTotals.length; idx++) {
                datatable.addCell(Integer.toString(classesTotals[idx]));
            }
        }

        datatable.addCell(Integer.toString(total));

        datatable.setSpacingBefore(15f);
        document.add(datatable);

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.team.TeamReport.java

License:Open Source License

/**
 * Generate a detail report of the teams in the tournament.
 * This report includes the teams and all of the wrestlers on the team.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 *//*from w w  w  .j  a va  2  s . co  m*/
public static boolean doDetail(Dao dao) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<String> teams = dao.getTeams();

        for (String t : teams) {

            List<Wrestler> wrestlers = dao.getWrestlersByTeam(t);
            int count = wrestlers.size();

            // create and add the table
            PdfPTable datatable = new PdfPTable(5);
            int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the team name and the number of entries
            headerCell.setPhrase(new Phrase(t, headerFont));
            headerCell.setColspan(3);
            datatable.addCell(headerCell);

            headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont));
            headerCell.setColspan(2);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.weighin.WeighInReport.java

License:Open Source License

/**
 * Generate a report of the entries in the tournament for weigh-in.
 * @param sections List of sections for the report.  Each section will start
 *     on a new page.//from   ww w  .  j a va  2 s . c o m
 * @param headerString String to be used for the header of each page of the report.
 * @return True if the report was generated.
 */
public static boolean doReport(List<List<Wrestler>> sections, String headerString) {
    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        if (headerString != null) {
            Paragraph p1 = new Paragraph(
                    new Paragraph(headerString, FontFactory.getFont(FontFactory.HELVETICA, 10)));
            document.add(p1);
        }

        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);

        for (List<Wrestler> wrestlers : sections) {
            // create and add the table
            PdfPTable datatable = new PdfPTable(7);
            int colWidths[] = { 20, 20, 20, 10, 10, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            //datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
                datatable.addCell(new Phrase()); // actual weight
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
            document.newPage();
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportPN(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/* ww w .  ja  v  a 2 s  .  com*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuNhap_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data

        PdfPTable t = new PdfPTable(7);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu nhp", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Nh cung cp", f));
        t.addCell(c6);
        PdfPCell c7 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c7);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(new Phrase(al.get(i)[4], f));
            t.addCell(al.get(i)[5]);
        }
        document.add(t);
        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportPX(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from  w  ww  .  java 2  s. co m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuXuat_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(5);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu xut", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
        }
        document.add(t);

        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportHD(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//w w w .  j a v a  2  s  .c  om
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "Hoadon_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(6);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M ha n", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Tn khch hng", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c6);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(new Phrase(al.get(i)[1], f));
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(al.get(i)[4]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKDT(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*w w w.ja va2 s.  c  o  m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nam can bao cao
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\barChart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(4);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("Thng", f));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Li", f));
        t.addCell(c4);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(al.get(i)[2]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}