Using external CSS programmatically

David91
edited February 11, 2022 in Analytics #1
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">Hi,</p>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">I want to use an external css when executing the BIRT report via a Java application. I've come along with a few articles (e.g. <a data-ipb='nomediaparse' href='http://developer.actuate.com/community/forum/index.php?/files/file/510-birt-dynamically-choose-css-file/'>http://developer.actuate.com/community/forum/index.php?/files/file/510-birt-dynamically-choose-css-file/</a>) which sets the css at runtime over</p>
<pre class="_prettyXprint">
design.getDesignHandle().addCss("someCss.css");</pre>
<p style="font-size:15px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;">but it seems that it's deprecated. I'm using BIRT 4.4.2. Any suggestions how I could set a css file at runtime?</p>

Comments

  • I don't believe this is deprecated. Have you tried adding the code to the initialize of the report like in the devshare? What is happening when you do it as you've described above?
    Warning No formatter is installed for the format ipb
  • David91
    edited May 13, 2015 #3
    <p>I've a default css which I'm using in the report and now I want to use an external css with has the same structure and elements but only different font styles. Now I've done it with</p>
    <p> </p>
    <div>
    <pre class="_prettyXprint">
    ReportDesignHandle report = (ReportDesignHandle)design.getDesignHandle();
    CssStyleSheetHandle css = report.openCssStyleSheet("PathToCSS/someCss.css");
    report.addCss(css);
    design.setDesignHandle(report);</pre>
    </div>
    <div> </div>
    <div>but it has no effects and shows the "default" css from the report.</div>
  • <p>My mistake. I used "Import CSS File" instead of "Use CSS File" in the report designer. Now, with the code above, it's working fine.</p>
    <p> </p>
    <p>Thanks.</p>
  • Great! Glad to hear it's working! :)<br><br>Let us know whenever you have questions.
    Warning No formatter is installed for the format ipb
  • <p>I can not get this to work.  I need to import a external style sheet, I have looked all over the net and this thread is the only thing that I can find that seems to be what I am looking for.  What is the <span>design in "</span><span>(</span><span>ReportDesignHandle</span><span>)</span><span>design</span><span>.</span><span>getDesignHandle</span><span>();" and "</span><span>design</span><span>.</span><span>setDesignHandle</span><span>(</span><span>report</span><span>);"</span></p>
    <p> </p>
    <p><span>I mean obviously it is a designHandle.  but how do I set this?</span></p>
  • <p>I'm not sure I am clear on what you are asking.</p>
    <p>
    Are you trying to add the external CSS through a java program that uses the report engine or are you trying to do this within the report design itself?</p>
    Warning No formatter is installed for the format ipb
  • <p>Yes I am writing a java program with the report <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">engine and I need to be able to load</span> <span style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">external CSS.</span></p>
  • <p>Im also using BIRT 4.2.2 like David above.</p>
  • <p>Without access to the full code I cannot be exactly sure the object type however, my guess would be that it is actually an IReportRunnable object created similar to the following:</p>
    <pre class="_prettyXprint _lang-">
    IReportRunnable design = engine.openReportDesign("Reports/TopNPercent.rptdesign");
    </pre>
    Warning No formatter is installed for the format ipb
  • <p>Im getting an error: The method openReportDesign(String) is undefined for the type IDesignEngine</p>
    <p> </p>
    <p>mean anything to you? I will keep at it.</p>
  • <p>Are you trying to add the CSS file at run time when executing the report with the report engine or are you trying to modify and then save the report design using the design engine?</p>
    <p> </p>
    <p>The method I indicated is for adding at runtime when using the report engine. Which means you need to define the engine object as an IReportEngine.</p>
    <pre class="_prettyXprint _lang-js">
    IReportEngine engine = factory.createReportEngine( config );
    </pre>
    <p>Take a look at the report engine API (REAPI) documentation for more details: <a data-ipb='nomediaparse' href='https://www.eclipse.org/birt/documentation/integrating/reapi.php'>https://www.eclipse.org/birt/documentation/integrating/reapi.php</a></p&gt;
    Warning No formatter is installed for the format ipb
  • For the design engine, create a session handle, then, you should be able to open the design from the session handle with session.openDesign("filename").
    Warning No formatter is installed for the format ipb
  • android272
    edited June 4, 2015 #14
    <p>I need to add the CSS at run time and then save it.</p>
    <p> </p>
    <p>Here is where I define my <span style="color:rgb(102,0,102);">IReportEngine </span>engine.</p>
    <pre class="_prettyXprint">
    </pre>
    <div>// Configure the Engine and start the Platform</div>
    <div>DesignConfig config = new DesignConfig();</div>
    <div> </div>
    <div>config.setProperty("BIRT_HOME",</div>
    <div>"D:/Downloads/birt-runtime-4_2_2/ReportEngine");</div>
    <div>IDesignEngine engine = null;</div>
    <div>try {</div>
    <div>Platform.startup(config);</div>
    <div>IDesignEngineFactory factory = (IDesignEngineFactory) Platform</div>
    <div>.createFactoryObject(IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY);</div>
    <div> </div>
    <div>engine = factory.createDesignEngine(config);</div>
    <div>} catch (Exception ex) {</div>
    <div>ex.printStackTrace();</div>
    <div>}</div>
  • android272
    edited June 4, 2015 #15
    <p>Turns out I already had a designHandle that I forgot about earlier in my code.</p>
    <pre class="_prettyXprint _lang-">
    designHandle = session.openDesign("path/to/reports/report.rptdesign"); </pre>
    <p>then I modified the code from this post to look like this,</p>
    <pre class="_prettyXprint _lang-">
    ReportDesignHandle report = designHandle.getDesignHandle();

    CssStyleSheetHandle css = report.openCssStyleSheet("Path/to/CSS/report.css");

    report.addCss(css);</pre>
    <p>question though. I am getting a warning that says that getDesignHandle is deprecated and the java doc says it is deprecated. So I was wondering if it was? I saw above mwilliams said that he did not think that it was deprecated  I just want to make sure it is not.</p>
  • <p>This looks to be a bit tricky as the get getDesignHandle() method is showing as deprecated in some classes and not in others in the documentation. It does looks like the getDesignHandle() method has been deprecated in the org.eclipse.birt.report.model.api.DesignElementHandle class and has been replaced with getModuleHandle().</p>
    <p> </p>
    <p>As it looks to me like that is the class you are using, I would change up your code to be using getModuleHandle() instead so you aren't using a deprecated method.</p>
    Warning No formatter is installed for the format ipb
  • <p>That worked. I needed to cast it to (ReportDesignHandle)</p>
    <pre class="_prettyXprint _lang-">
    ReportDesignHandle report = (ReportDesignHandle) designHandle.getModuleHandle();
    </pre>
    <p>Now all I need to do is figure out my CSS. but I will start a new thread for that.</p>
  • Hi,

    I want to use client specific woff file in my report, can anyone help here how to add it into my report design?

    Thanks in advance.