Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create TOC in Jaspersoft studio with dotted lines

I am trying to create my table of contents in jasper studio 6.4.3. It has to be a dotted TOC, which means I need to fill the space between label text field and page number text filed with dots. The solution that I have at the time has two problems.

First: There are half dots to see, depending the length of the texts in fields

Second: I can not get the dots and page number field aligned to the label after stretch. The solution for the dots is, having a static text field behind both text fields and set the text fields background to with, in order to cover the dots behind the texts.

enter image description here

<band height="31" splitType="Stretch">
        <property name="local_mesure_unitheight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
        <printWhenExpression><![CDATA[$F{level} == 1]]></printWhenExpression>
        <staticText>
            <reportElement style="InhaltsverzeichnisPunkte" mode="Transparent" x="0" y="1" width="440" height="18" uuid="b08b479c-10a8-4d87-8507-4f32fd50004f"/>
            <text><![CDATA[. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .]]></text>
        </staticText>
        <textField isStretchWithOverflow="true">
            <reportElement style="InhaltsverzeichnisPunkte" x="396" y="1" width="45" height="18" uuid="bc43bd36-7466-457c-95e6-384410c05cbe"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression><![CDATA["<style backcolor='white'>"+($V{PAGE_NUMBER} + $F{pageIndex} + 3)+"</style>"]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true" hyperlinkType="LocalAnchor">
            <reportElement style="Formatvorlage Standard (kleiner) + 10 Pt." mode="Transparent" x="0" y="3" width="396" height="15" uuid="b19a02f7-3d3f-4086-86ed-5dc6859e5fd1"/>
            <textElement textAlignment="Left" markup="styled"/>
            <textFieldExpression><![CDATA["<style backcolor='white'>"+$F{label}+"</style>"]]></textFieldExpression>
            <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
        </textField>
    </band>

As you can see in the picture, the page number 6 need and the dots should be appear aligned to the second line in the text field, and the dot after character g is cut.

like image 651
Iman Avatar asked Oct 29 '25 03:10

Iman


1 Answers

You can almost achieve what you want with:

  • verticalAlignment set to Bottom for all your text elements
  • stretchType set to ContainerBottom for the 'dotted' staticText and the 'page index' textField elements

like so:

<band height="39" splitType="Stretch">
<staticText>
    <reportElement stretchType="ContainerBottom" mode="Transparent" x="0" y="1" width="440" height="18" uuid="b08b479c-10a8-4d87-8507-4f32fd50004f"/>
    <textElement verticalAlignment="Bottom"/>
    <text><![CDATA[. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .]]></text>
</staticText>
<textField isStretchWithOverflow="true">
    <reportElement stretchType="ContainerBottom" x="396" y="1" width="45" height="18" uuid="bc43bd36-7466-457c-95e6-384410c05cbe"/>
    <textElement textAlignment="Right" verticalAlignment="Bottom" markup="styled"/>
    <textFieldExpression><![CDATA["<style backcolor='white'>"+($V{PAGE_NUMBER} + $F{pageIndex} + 3)+"</style>"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" hyperlinkType="LocalAnchor">
    <reportElement mode="Transparent" x="0" y="3" width="396" height="16" uuid="b19a02f7-3d3f-4086-86ed-5dc6859e5fd1">
        <property name="com.jaspersoft.studio.unit.height" value="px"/>
    </reportElement>
    <textElement textAlignment="Left" verticalAlignment="Bottom" markup="styled"/>
    <textFieldExpression><![CDATA["<style backcolor='white'>"+$F{label}+"</style>"]]></textFieldExpression>
    <hyperlinkAnchorExpression><![CDATA[$F{label}]]></hyperlinkAnchorExpression>
</textField>

The output: enter image description here

Note:

  • You may still experience 'cut' dots because the text elements overlap. I cannot think of a different approach for this.
  • I have adjusted your code by removing the styles and tweaking the elements' height to align properly.
like image 136
Narcis Avatar answered Oct 31 '25 06:10

Narcis