Split text evenly into 2 columns

Hi all,
i have a long text (general sales conditions) and i'm trying to figure out how to split it into 2 column with the same height.
The text isn't static, so it can change whenever it need to be changed (e.g. customer specific text) and for this reason i can't split it manually.
Using 2 columns page format i managed to let Jasper fill one column at a time, but my customer doesn't want 2 column with different heights.
Can someone help me?
 
P.S. I'm using Jaspersoft Studio 6.0.3.
 
Thank you in advance,
Giuliano
gttgln's picture
41
Joined: Apr 14 2015 - 3:22am
Last seen: 7 years 11 months ago

4 Answers:

You can break your text into two equal part at a word boundary and display them in two seperate coulmns in the detail band and allow text overflow stretch relative to the tallest object. I will make a sample report and send you the custom wiki posting link.

tchen's picture
121130
Joined: Feb 27 2008 - 7:33am
Last seen: 2 days 7 hours ago

Try this report:using a postgreSQL data source

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report4Giuliano" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1fe3275c-4ced-4197-979c-9f5ffd79bb93">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JRSrepo"/>
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="Parameter1" class="java.lang.String">
        <defaultValueExpression><![CDATA["10 Things Not To Do On Tax Day - 1. Fib on your taxes and think you’ll pay later. - 2. Call your tax professional for anything other than an extension. - 3. Spend your refund when it’s not in pocket. - 4. Head out for the post office at 4:55pm. - 5. Call the IRS. - 6. Forget to sign your return. - 7. Assume you’ll figure it out later. - 8. Not pay at all. - 9. Fail to take advantage of all of the cool stuff available. - 10. Panic. (http://www.forbes.com/sites/kellyphillipserb/2015/04/15/9-things-not-to-do-on-tax-day/)"]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[select 1]]>
    </queryString>
    <field name="?column?" class="java.lang.Integer"/>
    <variable name="split_point" class="java.lang.Integer">
        <variableExpression><![CDATA[new Integer(($P{Parameter1}.length()/2)+$P{Parameter1}.substring($P{Parameter1}.length()/2).indexOf(" "))]]></variableExpression>
    </variable>
    <variable name="split_point2" class="java.lang.Integer">
        <variableExpression><![CDATA[new Integer($P{Parameter1}.substring(0,$P{Parameter1}.length()/2).lastIndexOf(" "))]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="1" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band splitType="Stretch">
            <property name="local_mesure_unitheight" value="pixel"/>
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
        </band>
    </columnHeader>
    <detail>
        <band height="45" splitType="Stretch">
            <property name="local_mesure_unitheight" value="pixel"/>
            <property name="com.jaspersoft.studio.unit.height" value="px"/>
            <textField isStretchWithOverflow="true">
                <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="0" y="0" width="285" height="30" backcolor="#F7C8F0" uuid="876f86fd-6283-4c6e-bd4e-556363a92476">
                    <property name="local_mesure_unitwidth" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.width" value="px"/>
                </reportElement>
                <textFieldExpression><![CDATA[$P{Parameter1}]]></textFieldExpression>
            </textField>
        </band>
        <band height="50">
            <textField isStretchWithOverflow="true">
                <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="0" y="0" width="285" height="30" backcolor="#93F595" uuid="ef3e1934-fb73-46aa-81ea-b9875009f7c6">
                    <property name="local_mesure_unitwidth" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.width" value="px"/>
                </reportElement>
                <textFieldExpression><![CDATA[$P{Parameter1}.substring(0,$V{split_point}.intValue())]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="287" y="0" width="285" height="30" backcolor="#E6F593" uuid="08c692a3-adab-4511-9c2b-ddf4ba98c400">
                    <property name="local_mesure_unitx" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.x" value="px"/>
                </reportElement>
                <textFieldExpression><![CDATA[$P{Parameter1}.substring($V{split_point}.intValue()+1)]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band splitType="Stretch"/>
    </summary>
</jasperReport>

tchen's picture
121130
Joined: Feb 27 2008 - 7:33am
Last seen: 2 days 7 hours ago

Thank you, but one of the problems is that the text is very, very long... like this: http://www.ensto.com/ensto/workingprinciples/generalconditions

So the entire text falls into many pages and this isn't enough.

However you gave me an idea... if i manage to get the maximum characters that goes into a single page i can create different reports each with different parts of the text using your template...

gttgln's picture
41
Joined: Apr 14 2015 - 3:22am
Last seen: 7 years 11 months ago

Your requirement is to have two column report template lying content from the left to right just like a newspaper column layout. The challenge is how JR can dynamically set detail band height based on the amount of spaces needed to layout the (remaining) text and space left on the current page in two even part. JR does not have this feature currently to meet this requirement.

As you may imagine, the difficulty is not only to count number of characters left on the current page, but also determine how many characters the remaining part of the current page can compensate. In addition, font actually being used for the text field display can only be determined at the report run time from JVM, thus the actual font pixel size can affect the final report context layout. Compounding the problem, report template measuring unit (such as A4) might need Metric conversion that will have inherited “arrears” deficiency affecting page break point if not handled correctly. The same issue can also be observed with different printers due to pixel to DPI conversion.    

tchen's picture
121130
Joined: Feb 27 2008 - 7:33am
Last seen: 2 days 7 hours ago
Feedback
randomness