List of usage examples for com.lowagie.text Font Font
public Font(BaseFont bf, float size, int style, Color color)
From source file:org.silverpeas.components.almanach.control.AlmanachPdfGenerator.java
License:Open Source License
private static void generateAlmanach(Chapter chapter, AlmanachSessionController almanach, List<DisplayableEventOccurrence> occurrences, String mode) { boolean monthScope = AlmanachPdfGenerator.PDF_MONTH_EVENTSONLY.equals(mode) || AlmanachPdfGenerator.PDF_MONTH_ALLDAYS.equals(mode); boolean yearScope = AlmanachPdfGenerator.PDF_YEAR_EVENTSONLY.equals(mode); int currentDay = -1; Calendar calendar = Calendar.getInstance(); calendar.setTime(almanach.getCurrentDay()); calendar.set(Calendar.DAY_OF_MONTH, 1); int currentMonth = calendar.get(Calendar.MONTH); int currentYear = calendar.get(Calendar.YEAR); if (yearScope) { // start from begin of current year calendar.set(Calendar.MONTH, 0); }/*from ww w .j a v a2s. co m*/ // for each day of the current month while ((monthScope && currentMonth == calendar.get(Calendar.MONTH)) || (yearScope && currentYear == calendar.get(Calendar.YEAR))) { Section section = null; if (AlmanachPdfGenerator.PDF_MONTH_ALLDAYS.equals(mode)) { section = chapter.addSection(generateParagraph(calendar, almanach), 0); } Font titleTextFont = new Font(Font.BOLD, 12, Font.SYMBOL, new Color(0, 0, 0)); // get the events of the current day for (DisplayableEventOccurrence occurrence : occurrences) { EventDetail event = occurrence.getEventDetail(); String theDay = DateUtil.date2SQLDate(calendar.getTime()); String startDay = DateUtil.date2SQLDate(occurrence.getStartDate().asDate()); String startHour = event.getStartHour(); String endHour = event.getEndHour(); if (startDay.compareTo(theDay) > 0) { continue; } String endDay = startDay; if (event.getEndDate() != null) { endDay = DateUtil.date2SQLDate(occurrence.getEndDate().asDate()); } if (endDay.compareTo(theDay) < 0) { continue; } if (calendar.get(Calendar.DAY_OF_MONTH) != currentDay) { if (AlmanachPdfGenerator.PDF_MONTH_EVENTSONLY.equals(mode) || AlmanachPdfGenerator.PDF_YEAR_EVENTSONLY.equals(mode)) { section = chapter.addSection(generateParagraph(calendar, almanach), 0); } currentDay = calendar.get(Calendar.DAY_OF_MONTH); } Font textFont; if (event.getPriority() == 0) { textFont = new Font(Font.HELVETICA, 10, Font.NORMAL, new Color(0, 0, 0)); } else { textFont = new Font(Font.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0)); } String eventTitle = event.getTitle(); if (startDay.compareTo(theDay) == 0 && startHour != null && startHour.length() != 0) { eventTitle += " (" + startHour; if (endDay.compareTo(theDay) == 0 && endHour != null && endHour.length() != 0) { eventTitle += "-" + endHour; } eventTitle += ")"; } section.add(new Paragraph(eventTitle, titleTextFont)); if (StringUtil.isDefined(event.getPlace())) { section.add(new Paragraph(event.getPlace(), titleTextFont)); } if (StringUtil.isDefined(event.getDescription(almanach.getLanguage()))) { section.add(new Paragraph(event.getDescription(almanach.getLanguage()), textFont)); } section.add(new Paragraph("\n")); } // end for calendar.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:org.sonar.report.pdf.DefaultPDFReporter.java
License:Open Source License
private void printDashboard(Project project, Section section) throws DocumentException { PdfPTable dashboard = new PdfPTable(3); dashboard.getDefaultCell().setBorderColor(Color.WHITE); Font titleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK); Font dataFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.GRAY); Font dataFont2 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD, new Color(100, 150, 190)); PdfPTable linesOfCode = new PdfPTable(1); linesOfCode.getDefaultCell().setBorderColor(Color.WHITE); linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), titleFont)); linesOfCode.addCell(new Phrase(project.getMeasure("ncss").getFormatValue(), dataFont)); linesOfCode.addCell(/*from w w w . ja v a2 s.co m*/ new Phrase(project.getMeasure("packages_count").getFormatValue() + " packages", dataFont2)); linesOfCode .addCell(new Phrase(project.getMeasure("classes_count").getFormatValue() + " classes", dataFont2)); linesOfCode.addCell( new Phrase(project.getMeasure("functions_count").getFormatValue() + " methods", dataFont2)); linesOfCode.addCell(new Phrase( project.getMeasure("duplicated_lines_ratio").getFormatValue() + " duplicated lines", dataFont2)); PdfPTable comments = new PdfPTable(1); comments.getDefaultCell().setBorderColor(Color.WHITE); comments.addCell(new Phrase(getTextProperty("general.comments"), titleFont)); comments.addCell(new Phrase(project.getMeasure("comment_ratio").getFormatValue(), dataFont)); comments.addCell( new Phrase(project.getMeasure("comment_lines").getFormatValue() + " comment lines", dataFont2)); PdfPTable codeCoverage = new PdfPTable(1); codeCoverage.getDefaultCell().setBorderColor(Color.WHITE); codeCoverage.addCell(new Phrase(getTextProperty("general.test_count"), titleFont)); codeCoverage.addCell(new Phrase(project.getMeasure("test_count").getFormatValue(), dataFont)); codeCoverage.addCell( new Phrase(project.getMeasure("test_success_percentage").getFormatValue() + " success", dataFont2)); codeCoverage .addCell(new Phrase(project.getMeasure("code_coverage").getFormatValue() + " coverage", dataFont2)); PdfPTable complexity = new PdfPTable(1); complexity.getDefaultCell().setBorderColor(Color.WHITE); complexity.addCell(new Phrase(getTextProperty("general.complexity"), titleFont)); complexity.addCell(new Phrase(project.getMeasure("ccn_function").getFormatValue(), dataFont)); complexity.addCell(new Phrase(project.getMeasure("ccn_class").getFormatValue() + " /class", dataFont2)); complexity.addCell(new Phrase(project.getMeasure("ccn").getFormatValue() + " decision points", dataFont2)); PdfPTable rulesCompliance = new PdfPTable(1); rulesCompliance.getDefaultCell().setBorderColor(Color.WHITE); rulesCompliance.addCell(new Phrase(getTextProperty("general.rules_compliance"), titleFont)); rulesCompliance.addCell(new Phrase(project.getMeasure("rules_compliance").getFormatValue(), dataFont)); PdfPTable violations = new PdfPTable(1); violations.getDefaultCell().setBorderColor(Color.WHITE); violations.addCell(new Phrase(getTextProperty("general.violations"), titleFont)); violations.addCell(new Phrase(project.getMeasure("rules_violations").getFormatValue(), dataFont)); dashboard.addCell(linesOfCode); dashboard.addCell(comments); dashboard.addCell(codeCoverage); dashboard.addCell(complexity); dashboard.addCell(rulesCompliance); dashboard.addCell(violations); dashboard.setSpacingBefore(8); section.add(dashboard); Image ccnDistGraph = getCCNDistribution(project); if (ccnDistGraph != null) { section.add(ccnDistGraph); Paragraph imageFoot = new Paragraph(getTextProperty("metrics.ccn_classes_count_distribution"), Style.FOOT_FONT); imageFoot.setAlignment(Paragraph.ALIGN_CENTER); section.add(imageFoot); } }
From source file:test.poi.ConvertDocxResumeToPDF.java
License:LGPL
private static void create() { long startTime = System.currentTimeMillis(); try {// w w w . j a v a2 s. co m // 1) Load docx with POI XWPFDocument XWPFDocument document = new XWPFDocument( ConvertDocxResumeToPDF.class.getClassLoader().getResourceAsStream("DocxResume.docx")); // 2) Convert POI XWPFDocument 2 PDF with iText File outFile = new File("d:/DocxResume.pdf"); outFile.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(outFile); PdfOptions options = PdfOptions.create(); // options.fontProvider(new IFontProvider() { @Override public Font getFont(String familyName, String encoding, float size, int style, Color color) { try { BaseFont bfChinese = BaseFont.createFont("c:/Windows/Fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font fontChinese = new Font(bfChinese, size, style, color); if (familyName != null) fontChinese.setFamily(familyName); return fontChinese; } catch (Throwable e) { e.printStackTrace(); return ITextFontRegistry.getRegistry().getFont(familyName, encoding, size, style, color); } } }); PdfConverter.getInstance().convert(document, out, options); } catch (Throwable e) { e.printStackTrace(); } System.out.println("Generate DocxResume.pdf with " + (System.currentTimeMillis() - startTime) + " ms."); }