List of usage examples for com.itextpdf.text Phrase Phrase
public Phrase(final float leading, final String string)
Phrase
with a certain leading and a certain String
. From source file:de.aidger.utils.pdf.BalanceReportConverter.java
License:Open Source License
/** * Writes a semester table and adds the groups of that semester to it. * //w w w .java 2 s. c o m * @param semester * The name of the semester to be added. */ @SuppressWarnings("unchecked") private void createSemester(String semester) { balanceReportGroups = new ArrayList<ArrayList>(); try { Font semesterTitleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 13); Font semesterNameFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 13); PdfPTable finalSemesterTable = new PdfPTable(1); PdfPTable semesterTitleTable = new PdfPTable(new float[] { 0.2f, 0.8f }); PdfPCell semesterCell = new PdfPCell(new Phrase(_("Semester"), semesterTitleFont)); semesterCell.setBorder(0); semesterTitleTable.addCell(semesterCell); semesterCell = new PdfPCell(new Phrase(semester, semesterNameFont)); semesterCell.setBorder(0); semesterTitleTable.addCell(semesterCell); semesterCell = new PdfPCell(semesterTitleTable); semesterCell.setBorder(0); semesterCell.setPaddingTop(7.0f); finalSemesterTable.addCell(semesterCell); PdfPTable contentTable = new PdfPTable(1); /* * As long as there are groups for this Balance report, create new * group tables. */ List<Course> courses = null; if (semester != null) { courses = (new Course()).getCoursesBySemester(semester); } else { courses = new ArrayList<Course>(); List<Course> unsortedCourses = new Course().getAll(); for (Course course : unsortedCourses) { if (course.getSemester() == null) { courses.add(new Course(course)); } } } List<Course> filteredCourses = balanceHelper.filterCourses(courses, filters); for (Course course : filteredCourses) { PdfPTable groupTable = null; if (balanceReportGroups.isEmpty()) { groupTable = createGroup(course); } else { boolean foundGroup = false; for (int i = 0; i <= balanceReportGroups.size() - 1; i++) { if (((ArrayList) balanceReportGroups.get(i)).get(1).equals(course.getGroup())) { foundGroup = true; break; } } if (!foundGroup) { groupTable = createGroup(course); } } } for (int i = 0; i <= balanceReportGroups.size() - 1; i++) { PdfPCell cell = new PdfPCell((PdfPTable) ((ArrayList) balanceReportGroups.get(i)).get(0)); cell.setBorder(0); cell.setPaddingBottom(8.0f); contentTable.addCell(cell); } PdfPCell contentCell = new PdfPCell(contentTable); contentCell.setPaddingLeft(10.0f); contentCell.setBorder(1); finalSemesterTable.addCell(contentCell); finalSemesterTable.setKeepTogether(true); document.add(finalSemesterTable); } catch (Exception e) { Logger.error(e.getMessage()); } }
From source file:de.aidger.utils.pdf.BalanceReportConverter.java
License:Open Source License
/** * Creates a row with the data of one course and returns it. * /*from ww w .j av a2s . c o m*/ * @param course * The course of which the data shall be written to a row. * @return The row as a PdfPCell */ private PdfPCell addRow(BalanceCourse balanceCourse, float[] columnwidths, ArrayList<Integer> costUnits) { PdfPTable groupContentTable = new PdfPTable(columnwidths); ArrayList<Object> rowObjectVector = new ArrayList<Object>(); Font tableContentFont; try { tableContentFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9); for (int i = 0; i < 6; i++) { rowObjectVector.add((balanceCourse).getCourseObject()[i]); } sums.set(4, (Double) sums.get(4) + (Double) rowObjectVector.get(4)); sums.set(5, (Double) sums.get(5) + (Double) rowObjectVector.get(5)); int i = 0; for (Integer costUnit : costUnits) { boolean foundCostUnit = false; for (BudgetCost budgetCost : balanceCourse.getBudgetCosts()) { int budgetCostId = budgetCost.getId(); /* * Set the budget cost of the cost unit to the one * specified. */ if (budgetCostId == costUnit) { rowObjectVector.add(budgetCost.getValue()); foundCostUnit = true; } } if (!foundCostUnit) { rowObjectVector.add(0.0); } if (sums.size() < rowObjectVector.size()) { sums.add(rowObjectVector.get(rowObjectVector.size() - 1)); } else { sums.set(rowObjectVector.size() - 1, (Double) sums.get(rowObjectVector.size() - 1) + (Double) rowObjectVector.get(rowObjectVector.size() - 1)); } } for (Object courseObject : rowObjectVector.toArray()) { PdfPCell cell = null; if (courseObject.getClass().equals(Double.class)) { /* * Round to the configured precision. */ int decimalPlace = Integer.parseInt(Runtime.getInstance().getOption("rounding", "2")); double rounded = new BigDecimal((Double) courseObject) .setScale(decimalPlace, BigDecimal.ROUND_HALF_EVEN).doubleValue(); cell = new PdfPCell( new Phrase(new BigDecimal(rounded).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(), tableContentFont)); } else { cell = new PdfPCell(new Phrase(courseObject.toString(), tableContentFont)); } if (i != 0) { cell.setBorder(4 + Rectangle.BOTTOM); } else { cell.setBorder(0 + Rectangle.BOTTOM); i++; } cell.setPaddingBottom(5); groupContentTable.addCell(cell); } PdfPCell cell = new PdfPCell(groupContentTable); cell.setBorder(0); return cell; } 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.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./*from w ww. j av a 2 s . com*/ * * @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 w ww . j a v a2 s.c om * * @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 w w . j a v a 2 s . co 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 . j av a 2 s . c om*/ */ 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. *//* w w w. jav a 2 s .c o m*/ 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 w w w . j a v a 2 s .c o m */ 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 w w .j a v a2 s . co m*/ * @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.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java
License:Open Source License
public void addTable(List<String> headers, float[] headerWidth, List<List<Map.Entry<String, BaseColor>>> cells) throws Exception { PdfPTable table = new PdfPTable(headers.size()); if (headerWidth != null) { table.setWidths(headerWidth);//from ww w. j av a 2 s . co m } for (String header : headers) { PdfPCell cell = new PdfPCell( new Phrase(header, new Font(Font.FontFamily.HELVETICA, 18, Font.BOLDITALIC))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); } for (List<Map.Entry<String, BaseColor>> row : cells) { for (Map.Entry<String, BaseColor> cellItem : row) { PdfPCell cell = new PdfPCell( new Phrase(cellItem.getKey(), new Font(Font.FontFamily.HELVETICA, 14, Font.NORMAL))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(cellItem.getValue()); table.addCell(cell); } } this.document.add(table); }