Including dynamic images in a PDF with BIRT

Go To StackoverFlow.com

2

I am trying to use BIRT 2.5.0 to generate a pdf file. BIRT is called from pHp (this is done thanks to JavaBridge and a Tomcat server).

And I am simply trying to create a checkbox, checked under certain conditions. I looked a bit on the internet and found 2 different ways to do it.

The first way is to play with the Visibility if the field "idclassebillet" (on which I am making the test) has a value of 1. I did it this way :

<image id="9010">
    <list-property name="visibility">
        <structure>
            <property name="format">all</property>
            <expression name="valueExpr" type="javascript">row["classEq1"]</expression>
        </structure>
    </list-property>
    <list-property name="boundDataColumns">
        <structure>
            <property name="name">classEq1</property>
            <text-property name="displayName">classEq1</text-property>
            <expression name="expression" type="javascript">dataSetRow["idclassebillet"] == 1</expression>
            <property name="dataType">boolean</property>
        </structure>
    </list-property>
    <property name="source">embed</property>
    <property name="imageName">checkbox_unchecked.png</property>
</image>

But this doesn't work.

So the second solution that I found was to play with a simple URL. This solution is much more convenient, but doesn't work neither. This would looks like that.

<image id="9018">
    <property name="source">url</property>
    <list-property name="boundDataColumns">
        <structure>
            <property name="name">classEq1</property>
                <text-property name="displayName">classEq1</text-property>
                <expression name="expression" type="javascript">dataSetRow["idclassebillet"]</expression>
            <property name="dataType">integer</property>
        </structure>
    </list-property>
    <expression name="uri" type="javascript">
        if(row["classEq1"] == 1)
            "http://my.server.com/checkbox_checked.png"+row["classEq1"];
        else
            "http://my.server.com/checkbox_unchecked.png"+row["classEq1"];
    </expression>
</image>

In both cases, I declare the field "dataSetRow["idfield"]" like that :

<data-sets>
    <oda-data-set extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" name="infoBordereau" id="178">
        <structure name="cachedMetaData">
            <list-property name="resultSet">
            ...
                <structure>
                    <property name="position">9</property>
                    <property name="name">idclassebillet</property>
                    <property name="dataType">integer</property>
                </structure>
            ...
        </structure>
        <property name="dataSource">GestionBillet</property>
        <list-property name="resultSet">
            ...
            <structure>
                <property name="position">8</property>
                <property name="name">idclassebillet</property>
                <property name="nativeName">idclassebillet</property>
                <property name="dataType">integer</property>
            </structure>
            ...
        </list-property>
    ....
    </oda-data-set>
</data-sets>

I checked that I can access to the content of "idclassebillet". If I simply print it this way, it works fine :

<data id="90060001">
    <property name="whiteSpace">nowrap</property>
    <property name="dataSet">infoBordereau</property>
    <list-property name="boundDataColumns">
        <structure>
            <property name="name">classEq1</property>
            <text-property name="displayName">classEq1</text-property>
            <expression name="expression" type="javascript">dataSetRow["idclassebillet"]</expression>
            <property name="dataType">integer</property>
        </structure>
    </list-property>
    <property name="resultSetColumn">classEq1</property>
</data>

And whatever the solution I choose to get my "dynamic" images, I always get the same image, whatever the value of "dataSetRow["idclassebillet"]" is. I have no problem accessing and printing the image. The problem is more to "test" the value of the "idclassebillet" field (ie. how can I access this field ?).

I hope that you understand what I am trying to do. If you have a better solution (and if possible an example of working code), don't hesitate to share ^^ :)

Many thanks,

Raphaël POITTEVIN

NB : At first, I wanted my images to be embedded in the document (this what I use in the first solution), but as this didn't worked, I used an images hosted on http://my.server.com ...

2012-04-04 07:34
by PiroXXI


1

If your objective is to display an unchecked/checked checkbox, have you considered using the Wingdings font with characters 0xA8 and 0xFD or 0xFE?

2012-04-04 08:46
by NoName
Hi Mark, thank you for your answer. This is quite a good idea. I added the line <property name="fontFamily">Wingdings</property> to my part... and my code looks a bit like that :

if(dataSetRow["idclassebillet"] == 1)

String.fromCharCode('0xFD');

else

String.fromCharCode('0xFE');

But this only prints the 'ý' character...

Any idea? (nb : link I also tried others char like U+2610, but it didn't print anything. - PiroXXI 2012-04-04 09:32

@PiroXXI: Those three characters are ¨ , ý and þ respectively in "normal" fonts (Arial, Times, etc) but should display as a blank checkbox, a crossed checkbox and a ticked checkbox respectively in Wingdings. It sounds as though the font isn't being displayed correctly; have you tried previewing it on your own machine - NoName 2012-04-04 10:35
It works quite well on my own machine (a windows), but I can't get it to work fine on the linux server. :/ (I installed the font, but it's like BIRT don't find it ) . adding and removing the <property name="fontFamily">Wingdings</property>" has an effect as the font is different after. But it doesn't looks like the Windings font I have on my windows.. - PiroXXI 2012-04-05 08:14
From this post on the BIRT World blog: http://birtworld.blogspot.co.uk/2010/05/adventures-with-fonts.html , it looks as though the issue is with your fontsConfigXXX.xml files located in plugins/org.eclipse.birt.report.engine.fonts_XXX - further details at the link - NoName 2012-04-05 09:06
Ads