How to use external font families in BIRT Reports?

Prakash V
Prakash V Member
edited February 11, 2022 in Analytics #1
<p>Hi,</p>
<p>    I'm using BIRT version 4.5.0. I want to use some specific font families (more specifically 'Open Sans') in reports. In the mentioned version of BIRT is supported few font families only and also I'm not able to add external font families by API and also by design. Is any APIs or JAR files available to handle external font families? Also kindly expecting the procedure (code) to handle that font families. Thanks in advance..</p>

Comments

  • Clement Wong
    Clement Wong E Community Moderator
    edited July 21, 2017 #2
    <p>It's not true that BIRT doesn't support additional font families.</p>
    <p> </p>
    <p>To include web fonts... When designing, you should download the .OTF, install and use that so that you can select the Font in the drop down.  Otherwise, you'll need to manually update the XML Source to point to the web font you want to use.</p>
    <p> </p>
    <p>Then, for deploying, you can modify FramesetFragment.jsp (found under ...\birtwebcontent\birt\pages\layout) to include the Open Sans CSS:</p>
    <pre class="_prettyXprint _lang-nocode">
    ...
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8">
    <LINK REL="stylesheet" HREF="birt/styles/style.css" TYPE="text/css">
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
    <%
    if( attributeBean.isRtl() )
    {
    %>
    <LINK REL="stylesheet" HREF="birt/styles/dialogbase_rtl.css" MEDIA="screen" TYPE="text/css"/>
    <%
    ...
    </pre>
    <p>For commercial BIRT, you can also modify a common .CSS such as webfonts.css to include the web font definition, or add the link to the CSS in a common JSP file.  Another method is outlined here in this blog using head.js @ <a data-ipb='nomediaparse' href='https://blogs.opentext.com/extend-birt-with-font-symbols-code/'>https://blogs.opentext.com/extend-birt-with-font-symbols-code/</a></p&gt;
    <p> </p>
    <p> </p>
    <p>The attached design was testing in open source BIRT 4.5.0, deployed to Tomcat 8.  Here's a screenshot of the output of the report:</p>
    <p>
    Warning No formatter is installed for the format ipb
  • <p>BIRT support External font families by using following API</p>
    <pre class="_prettyXprint _linenums:0">
    ReportDesignHandle designHandle = session.createDesign();

    IncludedCssStyleSheet sheet =  StructureFactory.createIncludedCssStyleSheet();
    sheet.setExternalCssURI("https://fonts.googleapis.com/css?family=Open+Sans");
    sheet.setUseExternalCss(true);
    designHandle.addCss(sheet);    

    StyleHandle newStyle = designHandle.getElementFactory().newStyle("group-header");
    newStyle.setProperty(StyleHandle.FONT_FAMILY_PROP, "Open Sans");
    newStyle.setProperty(StyleHandle.COLOR_PROP, "#676767");
    designHandle.getStyles().add(newStyle);
    </pre>
    <p>It's working fine for me</p>
  • Hello Everyone,

    I'm trying to add custom fonts in WOFF file in my BIRT Report. Please guide me