List of usage examples for com.lowagie.text Font NORMAL
int NORMAL
To view the source code for com.lowagie.text Font NORMAL.
Click Source Link
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Cell columnHeaderCell(String label, boolean leaf, int hAlign) throws BadElementException { Paragraph para = new Paragraph(label); para.setFont(new Font(Font.HELVETICA, 10, Font.NORMAL, Color.WHITE)); Cell cell = new Cell(); cell.addElement(para);/* w w w .ja v a 2 s. co m*/ cell.setHorizontalAlignment(hAlign); cell.setHeader(true); cell.setVerticalAlignment(Cell.ALIGN_BOTTOM); cell.setBackgroundColor(new Color(55, 96, 145)); cell.setBorderWidth(0); return cell; }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
/** * Renders a Cell for/*from w w w . ja v a 2 s. com*/ * * @param label * @param header * @param depth * @param leaf * @param horizantalAlignment * @return * @throws BadElementException */ public static Cell bodyCell(String label, boolean header, int depth, boolean leaf, int horizantalAlignment) throws BadElementException { Cell cell = new Cell(); cell.setHorizontalAlignment(horizantalAlignment); if (label != null) { Paragraph para = new Paragraph(label); Font font = new Font(Font.HELVETICA, 10, Font.NORMAL, Color.BLACK); if (depth == 0 && !leaf) { font.setColor(Color.WHITE); } para.setFont(font); para.setIndentationLeft(5.4f + (header ? 12 * depth : 0)); cell.addElement(para); } cell.setBorderWidthLeft(0f); cell.setBorderWidthRight(0); cell.setBorderWidthTop(0); if (!leaf && depth == 0) { cell.setBackgroundColor(new Color(149, 179, 215)); // #95B3D7 cell.setBorderWidthBottom(0.5f); cell.setBorderColorBottom(new Color(219, 229, 241)); // #DBE5F1 } else if (!leaf && depth == 1) { cell.setBackgroundColor(new Color(219, 229, 241)); cell.setBorderWidthBottom(0.5f); cell.setBorderColorBottom(new Color(79, 129, 189)); } else { cell.setBorderWidthBottom(0.5f); cell.setBorderColorBottom(new Color(219, 229, 241)); cell.setBorderWidthTop(0.5f); cell.setBorderColorTop(new Color(219, 229, 241)); } return cell; }
From source file:org.silverpeas.components.almanach.control.AlmanachPdfGenerator.java
License:Open Source License
static public void buildPdf(String name, AlmanachSessionController almanach, String mode) throws AlmanachRuntimeException { try {/*from ww w . j a v a 2 s.c om*/ String fileName = FileRepositoryManager.getTemporaryPath(almanach.getSpaceId(), almanach.getComponentId()) + name; Document document = new Document(PageSize.A4, 50, 50, 50, 50); // we add some meta information to the document document.addAuthor(almanach.getSettings().getString("author", "")); document.addSubject(almanach.getSettings().getString("subject", "")); document.addCreationDate(); PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); try { Calendar currentDay = Calendar.getInstance(); currentDay.setTime(almanach.getCurrentDay()); String sHeader = almanach.getString("events"); if (mode.equals(PDF_MONTH_ALLDAYS) || mode.equals(PDF_MONTH_EVENTSONLY)) { sHeader += " " + almanach.getString("GML.mois" + currentDay.get(Calendar.MONTH)); } sHeader += " " + currentDay.get(Calendar.YEAR); HeaderFooter header = new HeaderFooter(new Phrase(sHeader), false); HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true); footer.setAlignment(Element.ALIGN_CENTER); document.setHeader(header); document.setFooter(footer); createFirstPage(almanach, document); document.newPage(); Font titleFont = new Font(Font.HELVETICA, 24, Font.NORMAL, new Color(255, 255, 255)); Paragraph cTitle = new Paragraph(almanach.getString("Almanach") + " " + almanach.getString("GML.mois" + currentDay.get(Calendar.MONTH)) + " " + currentDay.get(Calendar.YEAR), titleFont); Chapter chapter = new Chapter(cTitle, 1); // Collection<EventDetail> events = // almanach.getListRecurrentEvent(mode.equals(PDF_YEAR_EVENTSONLY)); AlmanachCalendarView almanachView; if (PDF_YEAR_EVENTSONLY.equals(mode)) { almanachView = almanach.getYearlyAlmanachCalendarView(); } else { almanachView = almanach.getMonthlyAlmanachCalendarView(); } List<DisplayableEventOccurrence> occurrences = almanachView.getEvents(); generateAlmanach(chapter, almanach, occurrences, mode); document.add(chapter); } catch (Exception ex) { throw new AlmanachRuntimeException("PdfGenerator.generate", AlmanachRuntimeException.WARNING, "AlmanachRuntimeException.EX_PROBLEM_TO_GENERATE_PDF", ex); } document.close(); } catch (Exception e) { throw new AlmanachRuntimeException("PdfGenerator.generate", AlmanachRuntimeException.WARNING, "AlmanachRuntimeException.EX_PROBLEM_TO_GENERATE_PDF", e); } }
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); }/* www .j av a2s . c o 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.silverpeas.components.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) { try {/*from w ww . j a v a2s . c o m*/ String activity = ""; if (step.getResolvedState() != null) { State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState()); activity = resolvedState.getLabel(getRole(), getLanguage()); } String sAction; try { if ("#question#".equals(step.getAction())) { sAction = getString("processManager.question"); } else if ("#response#".equals(step.getAction())) { sAction = getString("processManager.response"); } else if ("#reAssign#".equals(step.getAction())) { sAction = getString("processManager.reAffectation"); } else { Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction()); sAction = action.getLabel(getRole(), getLanguage()); } } catch (WorkflowException we) { sAction = "##"; } String actor = step.getUser().getFullName(); String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage()); String header = ""; if (StringUtil.isDefined(activity)) { header += activity + " - "; } header += sAction + " (" + actor + " - " + date + ")"; Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL); PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader)); pCell.setFixedHeight(28); pCell.setBackgroundColor(new Color(239, 239, 239)); pCell.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPTable pTable = new PdfPTable(1); pTable.setWidthPercentage(100); pTable.addCell(pCell); document.add(pTable); } catch (Exception e) { SilverLogger.getLogger(this).error(e.getMessage(), e); } }
From source file:org.silverpeas.components.kmelia.workflowextensions.SendInKmelia.java
License:Open Source License
private void generatePDFStepContent(HistoryStep step, com.lowagie.text.Document document) { try {//from w w w . j ava 2 s . co m Form form; if ("#question#".equals(step.getAction()) || "#response#".equals(step.getAction())) { // TODO form = null; } else { form = getProcessInstance().getProcessModel().getPresentationForm(step.getAction(), getRole(), getLanguage()); } XmlForm xmlForm = (XmlForm) form; if (xmlForm != null && step.getActionRecord() != null) { DataRecord data = step.getActionRecord(); // Force simpletext displayers because itext cannot display HTML Form fields (select, // radio...) float[] colsWidth = { 25, 75 }; PdfPTable tableContent = new PdfPTable(colsWidth); tableContent.setWidthPercentage(100); String fieldValue = ""; Font fontLabel = new Font(Font.HELVETICA, 10, Font.BOLD); Font fontValue = new Font(Font.HELVETICA, 10, Font.NORMAL); List<FieldTemplate> fieldTemplates = xmlForm.getFieldTemplates(); for (FieldTemplate fieldTemplate1 : fieldTemplates) { try { GenericFieldTemplate fieldTemplate = (GenericFieldTemplate) fieldTemplate1; String fieldLabel = fieldTemplate.getLabel("fr"); Field field = data.getField(fieldTemplate.getFieldName()); String componentId = step.getProcessInstance().getProcessModel().getModelId(); // wysiwyg field if ("wysiwyg".equals(fieldTemplate.getDisplayerName())) { String file = WysiwygFCKFieldDisplayer.getFile(componentId, getProcessInstance().getInstanceId(), fieldTemplate.getFieldName(), getLanguage()); // Extract the text content of the html code Source source = new Source(new FileInputStream(file)); fieldValue = source.getTextExtractor().toString(); } // Field file type else if (FileField.TYPE.equals(fieldTemplate.getDisplayerName()) && StringUtil.isDefined(field.getValue())) { SimpleDocument doc = AttachmentServiceProvider.getAttachmentService() .searchDocumentById(new SimpleDocumentPK(field.getValue(), componentId), null); if (doc != null) { fieldValue = doc.getFilename(); } } // Field date type else if ("date".equals(fieldTemplate.getTypeName())) { fieldValue = DateUtil.getOutputDate(field.getValue(), "fr"); } // Others fields type else { fieldTemplate.setDisplayerName("simpletext"); fieldValue = field.getValue(getLanguage()); } PdfPCell cell = new PdfPCell(new Phrase(fieldLabel, fontLabel)); cell.setBorderWidth(0); cell.setPaddingBottom(5); tableContent.addCell(cell); cell = new PdfPCell(new Phrase(fieldValue, fontValue)); cell.setBorderWidth(0); cell.setPaddingBottom(5); tableContent.addCell(cell); } catch (Exception e) { SilverLogger.getLogger(this).error(e.getMessage(), e); } } document.add(tableContent); } } catch (Exception e) { SilverLogger.getLogger(this).error(e.getMessage(), e); } }
From source file:org.sonar.report.pdf.Header.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { try {//from ww w .jav a 2 s .c om Image logoImage = Image.getInstance(logo); Rectangle page = document.getPageSize(); PdfPTable head = new PdfPTable(4); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.addCell(logoImage); Phrase projectName = new Phrase(project.getName(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); Phrase phrase = new Phrase("Sonar PDF Report", FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY)); head.getDefaultCell().setColspan(2); head.addCell(phrase); head.getDefaultCell().setColspan(1); head.addCell(projectName); head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - 20, writer.getDirectContent()); head.setSpacingAfter(10); } catch (BadElementException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.sonarqube.report.extendedpdf.ExtendedHeader.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { String pageTemplate = "/templates/page.pdf"; try {// w ww.java 2s .co m PdfContentByte cb = writer.getDirectContentUnder(); PdfReader reader = new PdfReader(this.getClass().getResourceAsStream(pageTemplate)); PdfImportedPage page = writer.getImportedPage(reader, 1); cb.addTemplate(page, 0, 0); Font font = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY); Rectangle pageSize = document.getPageSize(); PdfPTable head = new PdfPTable(1); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.getDefaultCell().setBorder(0); Phrase projectName = new Phrase(project.getName(), font); head.addCell(projectName); head.setTotalWidth(pageSize.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), pageSize.getHeight() - 15, writer.getDirectContent()); head.setSpacingAfter(10); PdfPTable foot = new PdfPTable(1); foot.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); foot.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); foot.getDefaultCell().setBorder(0); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm"); Phrase projectAnalysisDate = new Phrase(df.format(project.getMeasures().getDate()), font); foot.addCell(projectAnalysisDate); foot.setTotalWidth(pageSize.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin(), 20, writer.getDirectContent()); foot.setSpacingBefore(10); } catch (IOException e) { Logger.error("Cannot find the required template: " + pageTemplate); e.printStackTrace(); } }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
protected void printFrontPage(Document frontPageDocument, PdfWriter frontPageWriter) throws org.dom4j.DocumentException, ReportException { String frontPageTemplate = "/templates/frontpage.pdf"; try {/* w w w.ja v a 2s . c o m*/ PdfContentByte cb = frontPageWriter.getDirectContent(); PdfReader reader = new PdfReader(this.getClass().getResourceAsStream(frontPageTemplate)); PdfImportedPage page = frontPageWriter.getImportedPage(reader, 1); frontPageDocument.newPage(); cb.addTemplate(page, 0, 0); Project project = getProject(); Rectangle pageSize = frontPageDocument.getPageSize(); PdfPTable projectInfo = new PdfPTable(1); projectInfo.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); projectInfo.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); projectInfo.getDefaultCell().setBorder(Rectangle.BOTTOM); projectInfo.getDefaultCell().setPaddingBottom(10); projectInfo.getDefaultCell().setBorderColor(Color.GRAY); Font font = FontFactory.getFont(FontFactory.COURIER, 18, Font.NORMAL, Color.LIGHT_GRAY); Phrase projectName = new Phrase("Project: " + project.getName(), font); projectInfo.addCell(projectName); Phrase projectVersion = new Phrase("Version: " + project.getMeasures().getVersion(), font); projectInfo.addCell(projectVersion); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm"); Phrase projectAnalysisDate = new Phrase("Analysis Date: " + df.format(project.getMeasures().getDate()), font); projectInfo.addCell(projectAnalysisDate); projectInfo.setTotalWidth( pageSize.getWidth() - frontPageDocument.leftMargin() * 2 - frontPageDocument.rightMargin() * 2); projectInfo.writeSelectedRows(0, -1, frontPageDocument.leftMargin(), pageSize.getHeight() - 575, frontPageWriter.getDirectContent()); projectInfo.setSpacingAfter(10); } catch (IOException e) { Logger.error("Cannot find the required template: " + frontPageTemplate); e.printStackTrace(); } }
From source file:org.tn5250jlpr.SCS2PDF.java
License:Open Source License
public void openOutputFile(String path) { try {/*from ww w . j a va2s .c o m*/ System.out.println("Opening file"); if (document == null) { document = new Document(); bos = PdfWriter.getInstance(document, new FileOutputStream(path + ".pdf")); // document.setPageSize(new Rectangle(0.0f, // 0.0f, // getPointFromInches(13), // getPointFromInches(11))); BaseFont bf = BaseFont.createFont("Courier", "Cp1252", false); font = new Font(bf, 11, Font.NORMAL); } } catch (IOException _ex) { System.out.println("Cannot open"); } catch (Exception _ex) { System.out.println("Cannot open"); } }