List of usage examples for com.lowagie.text Font Font
public Font(BaseFont bf, float size, int style, Color color)
From source file:org.oscarehr.web.reports.ocan.SummaryOfActionsAndCommentsReportGenerator.java
License:Open Source License
private void createDomainHeader(PdfPTable table, String name) { Font f = new Font(Font.HELVETICA, 14, Font.BOLD, Color.BLACK); PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(0);// w w w . j a v a 2 s . c o m table.addCell(emptyCell); PdfPCell headerCell = new PdfPCell(); headerCell.setColspan(2); headerCell.setPhrase(new Phrase(name, f)); headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(headerCell); }
From source file:org.oscarehr.web.reports.ocan.SummaryOfActionsAndCommentsReportGenerator.java
License:Open Source License
private PdfPTable createNeedHeader(String name) throws DocumentException { Font whiteFont = new Font(Font.HELVETICA, 14, Font.BOLD, Color.WHITE); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100);/*from ww w. j ava 2 s . c o m*/ table.setWidths(new float[] { 0.10f, 0.20f, 0.70f }); PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(0); table.addCell(emptyCell); PdfPCell headerCell = new PdfPCell(); headerCell.setColspan(2); headerCell.setPhrase(new Phrase(name, whiteFont)); headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(headerCell); return table; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java
License:Open Source License
private Phrase createPhrase(final RenderableComplexText node) { Phrase p = new Phrase(); RichTextSpec text = node.getRichText(); for (RichTextSpec.StyledChunk c : text.getStyleChunks()) { TypedMapWrapper<Attribute, Object> attributes = new TypedMapWrapper<Attribute, Object>( c.getAttributes());//from ww w .jav a2 s . c o m final Number size = attributes.get(TextAttribute.SIZE, 10f, Number.class); final PdfTextSpec pdfTextSpec = computeFont(c); final int style = computeStyle(attributes, pdfTextSpec); final Color paint = (Color) c.getStyleSheet().getStyleProperty(ElementStyleKeys.PAINT); // add chunks BaseFont baseFont = pdfTextSpec.getFontMetrics().getBaseFont(); Font font = new Font(baseFont, size.floatValue(), style, paint); if (c.getOriginatingTextNode() instanceof RenderableReplacedContentBox) { RenderableReplacedContentBox content = (RenderableReplacedContentBox) c.getOriginatingTextNode(); com.lowagie.text.Image image = imageHandler.createImage(content); if (image != null) { Chunk chunk = new Chunk(image, 0, 0); // chunk.setFont(font); p.add(chunk); } } else { String textToPrint = c.getText(); Chunk chunk = new Chunk(textToPrint, font); p.add(chunk); } } return p; }
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Write the findings to the protocol.//from w ww . j a v a2 s. c o m * * @param protocol * the protocol * @param attachExtRefs * true if the external references should be part of the protocol * * @throws ExportException * If an error occurs while writing the findings to the protocol */ protected void writeFindings(Protocol protocol, boolean attachExtRefs) throws ExportException { try { /* * Define fonts */ Font plainFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9, Font.NORMAL, Color.WHITE); Font boldFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10, Font.NORMAL, Color.WHITE); Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); /* * Write findings */ PdfPTable tableBase = new PdfPTable(1); tableBase.setWidthPercentage(100); tableBase.setSplitRows(false); tableBase.getDefaultCell().setBorderWidth(0); tableBase.getDefaultCell().setPadding(0); for (Finding f : protocol.getFindings()) { tableBase.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 1)); PdfPCell cellFinding = new PdfPCell(); cellFinding.setBorderColor(Color.GRAY); cellFinding.setBorderWidth(0.5f); PdfPTable tableTitle = new PdfPTable(3); tableTitle.setWidthPercentage(100); /* * Print title of the finding */ Phrase phraseTitle = new Phrase(translate("Finding") + " " + f.getId(), boldFontTitle); PdfPCell cellTitle = new PdfPCell(phraseTitle); cellTitle.setBackgroundColor(bgColorTitle); cellTitle.setBorderWidth(0); cellTitle.setPadding(padding); cellTitle.setPaddingBottom(padding * 1.5f); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); tableTitle.addCell(cellTitle); /* * Print severity of the finding */ Phrase phraseSeverity = new Phrase(findMgmt.getLocalizedSeverity(f), plainFontTitle); PdfPCell cellSeverity = new PdfPCell(phraseSeverity); cellSeverity.setBackgroundColor(bgColorTitle); cellSeverity.setBorderWidth(0); cellSeverity.setPadding(padding); cellSeverity.setPaddingTop(padding * 1.1f); cellSeverity.setHorizontalAlignment(Element.ALIGN_CENTER); tableTitle.addCell(cellSeverity); /* * Print the meeting date and time of the finding */ String meetingDate = sdfDate.format(protocol.getDate().getTime()); PdfPCell cellMeeting = new PdfPCell(new Phrase(meetingDate, plainFontTitle)); cellMeeting.setBackgroundColor(bgColorTitle); cellMeeting.setBorderWidth(0); cellMeeting.setPadding(padding); cellMeeting.setPaddingTop(padding * 1.1f); cellMeeting.setHorizontalAlignment(Element.ALIGN_RIGHT); tableTitle.addCell(cellMeeting); /* * Description */ Phrase phraseDesc = new Phrase(f.getDescription(), plainFont); phraseDesc.setLeading(leading); PdfPCell cellDesc = new PdfPCell(); cellDesc.addElement(phraseDesc); cellDesc.setBorderWidth(0); cellDesc.setPadding(padding); cellDesc.setColspan(3); tableTitle.addCell(cellDesc); cellFinding.addElement(tableTitle); /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading * 0.93f); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); /* * Table of references */ if (f.getReferences().size() > 0 || (f.getExternalReferences().size() > 0 && attachExtRefs == true)) { PdfPTable tableRefs = new PdfPTable(new float[] { 0.04f, 0.96f }); tableRefs.setWidthPercentage(100); PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("References:"), boldItalicFont)); cellRefTitle.setBorderWidth(0); cellRefTitle.setPadding(padding); cellRefTitle.setPaddingTop(padding * 3); cellRefTitle.setPaddingBottom(0); cellRefTitle.setColspan(2); tableRefs.addCell(cellRefTitle); /* * Textual references */ for (String ref : f.getReferences()) { Phrase phraseRef = new Phrase(ref, plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); tableRefs.addCell(cellListPoint); tableRefs.addCell(cellRef); } /* * External file references */ if (attachExtRefs == true) { for (File ref : findMgmt.getExtReferences(f)) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), plainFont)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); tableRefs.addCell(cellListPoint); cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); tableRefs.addCell(cellRef); } } cellFinding.addElement(tableRefs); } /* * Table of aspects */ if (f.getAspects().size() > 0) { PdfPTable tableAspects = new PdfPTable(new float[] { 0.04f, 0.96f }); tableAspects.setWidthPercentage(100); PdfPCell cellAspTitle = new PdfPCell(new Phrase(translate("Aspects:"), boldItalicFont)); cellAspTitle.setBorderWidth(0); cellAspTitle.setPadding(padding); cellAspTitle.setPaddingTop(padding * 3); cellAspTitle.setPaddingBottom(0); cellAspTitle.setColspan(2); tableAspects.addCell(cellAspTitle); for (String asp : f.getAspects()) { Phrase phraseAsp = new Phrase(asp, plainFont); phraseAsp.setLeading(leading); PdfPCell cellAsp = new PdfPCell(); cellAsp.addElement(phraseAsp); cellAsp.setBorderWidth(0); cellAsp.setPadding(padding); tableAspects.addCell(cellListPoint); tableAspects.addCell(cellAsp); } cellFinding.addElement(tableAspects); } /* * Vertical strut at the end of the table */ PdfPTable tableStrut = new PdfPTable(1); tableStrut.setWidthPercentage(100); tableStrut.addCell(createVerticalStrut(padding, 1)); cellFinding.addElement(tableStrut); tableBase.addCell(cellFinding); } pdfDoc.add(tableBase); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put findings into the PDF document.")); } }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph reportTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, 26, Font.NORMAL, new Color(23, 54, 93))); para.setSpacingAfter(15);//from w ww.j av a 2 s . c om return para; }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph filterDescription(String text) { Paragraph para = new Paragraph(text); para.setFont(new Font(Font.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 0))); return para;//from w w w .j av a 2 s . c o m }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph elementTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, 13, Font.BOLD, new Color(79, 129, 189))); para.setSpacingBefore(10);//from w ww .j a v a2 s . c o m return para; }
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);/*from w ww . java 2 s. c o 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 ww . j a v a2s . c om*/ * * @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 {/* www.j a va2 s. c o m*/ 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); } }