Example usage for com.itextpdf.text Font Font

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

Introduction

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

Prototype


public Font(final FontFamily family, final float size) 

Source Link

Document

Constructs a Font.

Usage

From source file:de.aidger.utils.pdf.BalanceReportConverter.java

License:Open Source License

/**
 * Creates a new group table with the title of the group. Adds the table and
 * its title to the group table vector./*  w  w w. jav  a2s.  c o m*/
 * 
 * @param course
 *            The course for which a group shall be created.
 * @return The PdfPTable of the group.
 */
@SuppressWarnings("unchecked")
private PdfPTable createGroup(Course course) {
    balanceReportGroupCreator = new BalanceReportGroupCreator(course, calculationMethod);
    List<Course> courses = null;
    sums = new ArrayList<Object>();
    try {
        if (course.getSemester() != null) {
            courses = (new Course()).getCoursesBySemester(course.getSemester());
        } else {
            courses = new ArrayList<Course>();
            List<Course> unsortedCourses = new Course().getAll();
            for (Course currentCourse : unsortedCourses) {
                if (currentCourse.getSemester() == null) {
                    courses.add(new Course(currentCourse));
                }
            }
        }
    } catch (SienaException e) {
        UI.displayError(e.toString());
    }
    List<Course> filteredCourses = balanceHelper.filterCourses(courses, filters);
    ArrayList<Long> addedCourses = new ArrayList<Long>();
    addedCourses.add(course.getId());
    for (Course filteredCourse : filteredCourses) {
        if (!addedCourses.contains(filteredCourse.getId())
                && filteredCourse.getGroup().equals(course.getGroup())) {
            balanceReportGroupCreator.addCourse(filteredCourse);
            addedCourses.add(filteredCourse.getId());
        }
    }
    ArrayList<Integer> costUnits = new ArrayList<Integer>();
    ArrayList<BalanceCourse> balanceCourses = balanceReportGroupCreator.getBalanceCourses();
    ArrayList<String> titles = new ArrayList<String>();
    String[] courseTitles = { _("Title"), _("Part"), _("Lecturer"), _("Target Audience"), _("Planned AWS"),
            _("Basic needed AWS") };
    for (int i = 0; i < courseTitles.length; i++) {
        titles.add(courseTitles[i]);
    }
    for (Object balanceCourse : balanceCourses) {
        for (BudgetCost budgetCost : ((BalanceCourse) balanceCourse).getBudgetCosts()) {
            int budgetCostId = budgetCost.getId();
            String budgetCostName = budgetCost.getName();
            if (!costUnits.contains(budgetCostId)) {
                costUnits.add(budgetCostId);
                titles.add(_("Budget costs from") + " " + budgetCostName);
            }
        }
    }
    int columnCount = titles.size();
    Font tableTitleFont;
    Font tableContentFont;
    try {
        tableContentFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED),
                9);
        tableTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 9);

        Font groupTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 11);
        Font groupNameFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 11);

        PdfPTable groupTable = new PdfPTable(1);
        PdfPTable groupNameTable = new PdfPTable(new float[] { 0.2f, 0.8f });
        PdfPCell groupTitle = new PdfPCell(new Phrase(_("Group"), groupTitleFont));
        groupTitle.setBorder(2);
        groupNameTable.addCell(groupTitle);
        PdfPCell groupName = new PdfPCell(new Phrase(course.getGroup(), groupNameFont));
        groupName.setBorder(2);
        groupNameTable.addCell(groupName);
        PdfPCell groupContent = new PdfPCell(groupNameTable);
        groupContent.setBorder(0);
        groupContent.setPaddingTop(3.0f);
        groupContent.setPaddingBottom(2.0f);
        groupTable.addCell(groupContent);
        float[] columnWidths = new float[columnCount];
        columnWidths[0] = (200 / columnCount);
        columnWidths[1] = (50 / columnCount);
        columnWidths[2] = (100 / columnCount);
        columnWidths[3] = (150 / columnCount);
        columnWidths[4] = (100 / columnCount);
        for (int i = 5; i < columnCount; i++) {
            columnWidths[i] = (100 / columnCount);
        }
        PdfPTable groupContentTable = new PdfPTable(columnWidths);
        /*
         * Create the titles of the table entries.
         */
        for (int i = 0; i < titles.size(); i++) {
            PdfPCell cell = new PdfPCell(new Phrase(titles.get(i), tableTitleFont));
            if (i != 0) {
                cell.setBorder(6);
            } else {
                cell.setBorder(2);
            }
            groupContentTable.addCell(cell);
        }

        PdfPCell cell = new PdfPCell(groupContentTable);
        cell.setBorder(0);
        groupTable.addCell(cell);
        sums.add(_("Sum"));
        sums.add("");
        sums.add("");
        sums.add("");
        sums.add(0.0);
        sums.add(0.0);
        for (Object balanceCourse : balanceCourses) {
            groupTable.addCell(addRow((BalanceCourse) balanceCourse, columnWidths, costUnits));
        }
        PdfPTable emptyRow = new PdfPTable(columnWidths);
        PdfPTable sumRow = new PdfPTable(columnWidths);
        for (int i = 0; i < sums.size(); i++) {
            cell = new PdfPCell(new Phrase(""));
            if (i != 0) {
                cell.setBorder(Rectangle.TOP + Rectangle.LEFT);
            } else {
                cell.setBorder(Rectangle.TOP);
            }
            emptyRow.addCell(cell);
            if (i < 4) {
                cell = new PdfPCell(new Phrase(new Phrase(sums.get(i).toString(), tableContentFont)));
            } else {
                /*
                 * Round to the configured precision.
                 */
                int decimalPlace = Integer.parseInt(Runtime.getInstance().getOption("rounding", "2"));
                double rounded = new BigDecimal((Double) sums.get(i))
                        .setScale(decimalPlace, BigDecimal.ROUND_HALF_EVEN).doubleValue();
                cell = new PdfPCell(
                        new Phrase(new BigDecimal(rounded).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(),
                                tableContentFont));
            }
            if (i != 0) {
                cell.setBorder(Rectangle.TOP + Rectangle.LEFT);
            } else {
                cell.setBorder(Rectangle.TOP);
            }
            sumRow.addCell(cell);
        }
        cell = new PdfPCell(emptyRow);
        cell.setBorder(0);
        groupTable.addCell(cell);
        cell = new PdfPCell(sumRow);
        cell.setBorder(0);
        groupTable.addCell(cell);
        groupTable.setKeepTogether(true);

        balanceReportGroups.add(new ArrayList<Object>());
        int i = balanceReportGroups.size() - 1;
        ((ArrayList) balanceReportGroups.get(i)).add(groupTable);
        ((ArrayList) balanceReportGroups.get(i)).add(course.getGroup());

        return groupTable;
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:de.aidger.utils.pdf.BudgetReportConverter.java

License:Open Source License

/**
 * Creates the titles of the table./*from ww w.ja v a 2  s  .c  o m*/
 * 
 * @return The table with the titles.
 */
private PdfPTable createTableHeader() {
    try {
        Font tableTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 9);
        PdfPTable tableHeader = new PdfPTable(new float[] { 0.3f, 0.15f, 0.15f, 0.15f, 0.15f, 0.10f });
        String[] titles = { _("Course"), _("Semester"), _("Lecturer"), _("Booked budgets"),
                _("Available budgets"), _("Total Budgets") };
        /*
         * Add the title of every column.
         */
        for (int i = 0; i < titles.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(titles[i], tableTitleFont));
            tableHeader.addCell(cell);
        }
        PdfPTable tableHeaderTable = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(tableHeader);
        cell.setPaddingBottom(1);
        cell.setBorder(0);
        tableHeaderTable.addCell(cell);
        return tableHeaderTable;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:de.aidger.utils.pdf.BudgetReportConverter.java

License:Open Source License

/**
 * Adds a row, containing a course budget, to the table.
 * /*from w  ww  .  ja  v a  2s  . c o  m*/
 * @param objectArray
 *            The course budget.
 * @return The table containing the row.
 */
private PdfPTable addRow(Object[] objectArray) {
    try {
        Font tableContentFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9);
        PdfPTable tableContent = new PdfPTable(new float[] { 0.3f, 0.15f, 0.15f, 0.15f, 0.15f, 0.10f });
        Color cellColor = new Color(255, 255, 255);
        if (Double.parseDouble(objectArray[4].toString()) == 0) {
            cellColor = new Color(252, 200, 150);
        }
        for (int i = 0; i < objectArray.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(objectArray[i].toString(), tableContentFont));
            cell.setBackgroundColor(new BaseColor(cellColor));
            cell.setPaddingBottom(5);
            tableContent.addCell(cell);
        }
        return tableContent;
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:de.aidger.utils.pdf.ControllingConverter.java

License:Open Source License

/**
 * Creates the table of assistants.//from w  w w .java2  s.c  o m
 */
private void createTable() {
    try {
        Font tableTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 9);
        String[] courseTitles = { _("Assistant"), _("Planned costs(pre-tax)"), _("Actual costs(pre-tax)"),
                _("Remark") };
        PdfPTable contentTable = new PdfPTable(1);
        PdfPTable titleTable = new PdfPTable(4);
        /*
         * Create the titles of the table entries.
         */
        for (int i = 0; i < courseTitles.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(courseTitles[i], tableTitleFont));
            titleTable.addCell(cell);
        }
        PdfPCell cell = new PdfPCell(titleTable);
        cell.setPaddingTop(10.0f);
        cell.setPaddingBottom(2.0f);
        cell.setBorder(0);
        contentTable.addCell(cell);
        document.add(contentTable);
        addRows();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.aidger.utils.pdf.ControllingConverter.java

License:Open Source License

/**
 * Adds the rows of assistants to the table.
 */// ww  w .j  ava 2s  .c  om
private void addRows() {
    try {
        Font tableContentFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9);
        PdfPTable contentTable = new PdfPTable(4);
        for (String[] row : tableRows) {
            for (int i = 0; i < row.length; i++) {
                PdfPCell cell = new PdfPCell(new Phrase(row[i], tableContentFont));
                cell.setPaddingBottom(5);
                contentTable.addCell(cell);
            }
        }
        document.add(contentTable);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.aidger.utils.pdf.ProtocolConverter.java

License:Open Source License

/**
 * Writes the Table of activities./*from  www  .java 2s.c om*/
 */
private void writeTable() {
    try {
        Font tableTitleFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 9);
        String[] courseTitles = { _("Affected assistant"), _("Affected course"), _("Type"), _("Date"),
                _("Content"), _("Initiator"), _("Processor"), _("Remark") };
        PdfPTable contentTable = new PdfPTable(1);
        PdfPTable titleTable = new PdfPTable(8);
        /*
         * Create the titles of the table entries.
         */
        for (int i = 0; i < courseTitles.length; i++) {
            PdfPCell cell = new PdfPCell(new Phrase(courseTitles[i], tableTitleFont));
            if (i != 0) {
                cell.setBorder(6);
            } else {
                cell.setBorder(2);
            }
            titleTable.addCell(cell);
        }
        PdfPCell cell = new PdfPCell(titleTable);
        cell.setPaddingTop(10.0f);
        cell.setBorder(0);
        contentTable.addCell(cell);
        document.add(contentTable);
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.aidger.utils.pdf.ProtocolConverter.java

License:Open Source License

/**
 * Adds one activity to the activity table.
 * //from   w ww.j  av a2s  . c om
 * @param activity
 *            The activity to add.
 * @return The PdfPTable of the row.
 * @throws DocumentException
 * @throws IOException
 */
private PdfPTable addRow(Object[] activity) throws DocumentException, IOException {
    Font tableContentFont = new Font(
            BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9);
    PdfPTable contentTable = new PdfPTable(8);
    for (int i = 0; i < 8; i++) {
        PdfPCell cell = new PdfPCell(new Phrase(activity[i].toString(), tableContentFont));
        if (i != 0) {
            cell.setBorder(4 + Rectangle.TOP);
        } else {
            cell.setBorder(0 + Rectangle.TOP);
        }
        cell.setPaddingBottom(5);
        contentTable.addCell(cell);
    }
    return contentTable;
}

From source file:de.beimax.talenttree.AbstractPageGenerator.java

License:Open Source License

/**
 * Parse a string to PDF/itext phrase to be rendered later
 * @param key language key//  w  ww. j  av a 2  s .c o m
 * @param fontSize size of font
 * @param narrowFonts use narrow fonts?
 * @return
 * @throws Exception
 */
protected Phrase parseTextProperty(String key, float fontSize, boolean narrowFonts) throws Exception {
    // define fonts
    Font fontRegular, fontBold;
    if (narrowFonts) {
        fontRegular = new Font(generator.getFontCondensedRegular(), fontSize);
        fontBold = new Font(generator.getFontCondensedBold(), fontSize);
    } else {
        fontRegular = new Font(generator.getFontRegular(), fontSize);
        fontBold = new Font(generator.getFontBold(), fontSize);
    }
    Font fontSymbol = new Font(generator.getFontSymbol(), fontSize);

    Phrase phrase = new Phrase();
    phrase.setLeading(fontSize * 1.2f);

    // get localized element
    String localized = getLocalizedString(key);
    for (String part : localized.split("\\|")) {
        if (part.length() == 0)
            continue; // make sure to not fire index out of range
        char first = part.charAt(0);
        char last = part.charAt(part.length() - 1);
        switch (first) {
        case '*': // bold
            part = part.substring(1); // remove first char
            if (last == ' ')
                part = part.substring(0, part.length() - 1);
            phrase.add(new Chunk(part, fontBold));
            if (last == ' ')
                phrase.add(new Chunk(" ", fontRegular));
            break;
        case '#': // symbol font
            part = part.substring(1); // remove first char
            if (last == ' ')
                part = part.substring(0, part.length() - 1);
            phrase.add(new Chunk(part, fontSymbol));
            if (last == ' ')
                phrase.add(new Chunk(" ", fontRegular));
            break;
        default: // all other cases
            phrase.add(new Chunk(part, fontRegular));
        }
    }

    return phrase;
}

From source file:de.beimax.talenttree.PageGeneratorCareer.java

License:Open Source License

/**
 * Add skill data//from   www  .  j av  a  2s  .  co  m
 * @param prefix translated prefix (printed bold) without :
 * @param dataKey data key in YAML file, skills/bonus_skills
 * @throws Exception
 */
protected void addSkillData(String prefix, String dataKey) throws Exception {
    Font fontRegular = new Font(generator.getFontRegular(), 10.5f);
    Font fontBold = new Font(generator.getFontBold(), 10.5f);

    // add career skills
    Phrase phrase = new Phrase();
    phrase.add(new Chunk(prefix + ": ", fontBold));
    ArrayList<String> skills = new ArrayList<String>();
    //noinspection unchecked
    for (String key : (Iterable<String>) data.get(dataKey))
        skills.add(getLocalizedString(key));
    // sort localized
    Collections.sort(skills, Collator.getInstance());
    // build skill list
    StringBuilder sb = new StringBuilder();
    for (String skill : skills) {
        if (sb.length() != 0)
            sb.append(", ");
        sb.append(skill);
    }
    phrase.add(new Chunk(sb.toString(), fontRegular));
    Paragraph p = new Paragraph(phrase);
    p.setAlignment(Element.ALIGN_JUSTIFIED);
    p.setIndentationRight(getUsablePageWidth() - PDFGenerator.headerTextMaxWidth);
    p.setLeading(13.2f);
    document.add(p);
}

From source file:de.beimax.talenttree.PageGeneratorSignature.java

License:Open Source License

/**
 * Create basic header/*  w w  w.  j  a  v  a  2s. c  o m*/
 * @throws Exception
 */
protected void addHeader() throws Exception {
    Font fontHeader = new Font(generator.getFontBold(), 14);
    Font fontSubHeader = new Font(generator.getFontBold(), 18);
    document.add(new Paragraph(getMappedLocalizedString("header"), fontHeader));
    document.add(new Paragraph(getMappedLocalizedString("subheader"), fontSubHeader));
}