2

I have a BIRT report with an image in the master page.

My BIRT design file:

I embedded a png inside the report and it generated the following XML after the body tag:

  <list-property name="images">
      <structure>
          <property name="name">filename.png</property>
          <property name="type">image/png</property>
          <property name="data">
            BASE64 of the image
          </property>
      </structure>
   </list-property>

Then, I have included it into the master page, adding this element:

    <image id="828">
       <property name="source">embed</property>
       <property name="imageName">filename.png</property>
    </image>

Behaviours of my BIRT design file:

Then, If I run the preview from the BIRT designer it works great with both HTML and PDF output. If I render it using IPDFRenderOption (from my software) it generates the correct pdf fine. But if I use HTMLRenderOption, then the image is not embeded into the HTML report, but it is rendered with something like:

 <img src="file:/.../apache-tomcat-7.0.35/design11.png">

What I expect:

While I expected something like:

 <img src="data:image/png;base64,BASE64 STUFF THAT I PUT IN THE LIST-PROPERTIES ">

So, how can I let BIRT, when executed with HTMLRenderOption, to embed my image into the HTML file instead of creating a link to it?

Antonio Ragagnin
  • 2,278
  • 4
  • 24
  • 39
  • I doubt this is supported, but it would be a nice feature. In the early days when BIRT started, MSIE was the #1 browser and it didn't support – hvb Jun 20 '14 at 07:19
  • So how am I supposse to deploy a web service that produces BIRT html reports with images? Since BIRT put the local path with `file://`? – Antonio Ragagnin Jun 20 '14 at 07:32
  • @hvb, If interested, check my workaround/solution to this problem. In contrast to other solutions in the internet, it does not involves scripts. – Antonio Ragagnin Jun 20 '14 at 08:35

1 Answers1

1

I solved this by adding two different images to the masterpage of the report:

Setting of the image in the PDF output:

Since the PDF is well rendered, I leaved the image as I wrote in the question, and I set off the visibility of this image in the HTML output

Setting of the image in the HTML output:

Then, in the master page, I added a new image. This time I haven't set it as embedded. Instead I set it as referenced by an URI. As URI I set the base64 URI that I need in my HTML output. Basically, I added to the XML of the report the following image:

<image id="1972">
    <list-property name="visibility">
        <structure>
            <property name="format">pdf</property>
            <expression name="valueExpr" type="javascript">true</expression>
        </structure>
    </list-property>
        <property name="source">url</property>
        <expression name="uri" type="constant">data:image/png;base64, BASE 64 OF MY PNG IMAGE</expression>
 </image>

I then set the image to be visibile only for the HTML output.

In this way BIRT renders an img tag with the URL i put in the XML, whatever it is. And thus, it puts the data:image/png;base64, BASE 64 OF MY PNG IMAGE as url. And thus it embeds the image in the HTML output.

Adding images from the database in your table:

BIRT supports the images inside blob fiels, and can manage in adding them to your report. To see how, see there: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.birt.doc%2Fbirt%2Flayout.5.7.html

If it does not works, you can manage inserting a dynamic value on your url, still without editing the scripts (but of course using a bit of Javascript to decide which column contains the data of teh image).

Here below the XML code of an image that reads the base64 value from a column:

  <image id="1974">
        <property name="source">url</property>
        <expression name="uri" type="javascript">"data:image/png;base64,"+row["BASE_64_PNG_COLUMN"]     </expression>
  </image>
Antonio Ragagnin
  • 2,278
  • 4
  • 24
  • 39
  • Nice! You edited the XML directly? Would this work for dynamic images (From blobs in the DB) AS well, EG by using the DE API? – hvb Jun 21 '14 at 12:01
  • @hvb There are are standard ways to add blob-images to your report (see what I added to my answer). However, here above you can see how to do it dinamically. without complex javascript and without `onFactory` or similar calls. – Antonio Ragagnin Jun 23 '14 at 09:56
  • I see. This works as long as the BLOB already contains the image data base64-encoded. Otherwise, it shouldn't be too hard to create a PL/SQL function (for an Oracle DB) vor whatever to do this encoding. Nice! – hvb Jun 24 '14 at 19:38
  • Using the "data:image/png;..." approach does not work for me with BIRT 4.4.2. Firefox displays the image when pasting the full URI. But when generating PDF report (or other type) only "The resource of this report item is not reachable." instead of the image is displayed. Any ideas? – Uli May 19 '15 at 14:20
  • @Uli, my approach was a workaround of a render problem in the HTML rendering. The PDF render should works fine if you use the `BIRT` `` tag. – Antonio Ragagnin May 20 '15 at 12:14
  • Not really. I have posted a new question (http://stackoverflow.com/questions/30346658/birt-does-not-show-base64-encoded-image) cause I think its not solvable here. Thanks for your great idea with the base64 URIs!! – Uli May 20 '15 at 12:18