How can I use bold attribute in a part of a textField?

I have the following code:

<textField isBlankWhenNull="true">
    <reportElement uuid="05cb6077-8a6a-478f-aaa4-1a021a8ed7d3" isPrintRepeatedValues="false" x="0" y="70" width="535" height="50" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
    <textElement textAlignment="Justified" verticalAlignment="Middle" markup="html">
        <font size="10"/>
    </textElement>
    <textFieldExpression><![CDATA["Documento assinado eletronicamente por  <style isBold='true' pdfFontName='Helvetica-Bold'>" + $F{dsUsuarioDeferimento} +  "</style> ,  em " + $F{dtDeferimento} +  " , com fundamento no art. 6º, § , 1º, do <a href='http://www.planalto.gov.br/ccivil_03/_Ato2015-2018/2015/Decreto/D8539.htm'><u><span style='color:#0000EE'>Decreto nº 8.539, de 8 de outubro de 2015.</span></u></a>"]]>
    </textFieldExpression>
</textField>

I need to put $F{dsUsuarioDeferimento} in bold style. But nothing I've tried works. Any help?

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

15 Answers:

Why do you mix up Styled markup language with Html syntax?

With pure html tags <b> and markup  = html it's working fine so far:

"Documento assinado eletronicamente por  <b>" + $F{dsUsuarioDeferimento} +  "</b> ,  em " + $F{dtDeferimento} +  " , com fundamento no art. 6º, § , 1º, do <a href='http://www.planalto.gov.br/ccivil_03/_Ato2015-2018/2015/Decreto/D8539.htm'><u><span style='color:#0000EE'>Decreto nº 8.539, de 8 de outubro de 2015.</span></u></a>"

hth + regards

C-Box

C-Box's picture
20551
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago

I don't know why, but isn't working, i tried <b> </b>. In an empty jxrml works, but mine dont

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

Have you really switched the MARKUP attribute to HTML? Do you use the built-in Preview or the PDF-Export?

Just post your whole jrxml  otherwise.

regards

C-Box

C-Box's picture
20551
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago

This is my full textfield now:

 

<textField isBlankWhenNull="true">
    <reportElement uuid="05cb6077-8a6a-478f-aaa4-1a021a8ed7d3" isPrintRepeatedValues="false" x="0" y="70" width="535" height="50" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
    <textElement textAlignment="Justified" verticalAlignment="Middle" markup="html">
        <font size="10"/>
    </textElement>
    <textFieldExpression><![CDATA["Documento assinado eletronicamente por  <b>" + $F{dsUsuarioDeferimento} +  "</b> ,  em " + $F{dtDeferimento} +  " , com fundamento no art. 6º, § , 1º, do <a href='http://www.planalto.gov.br/ccivil_03/_Ato2015-2018/2015/Decreto/D8539.htm'><u><span style='color:#0000EE'>Decreto nº 8.539, de 8 de outubro de 2015.</span></u></a>"]]></textFieldExpression>
 </textField>

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

And my full jxrml:

<?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="CertificadoRegistroProdutoProdutosVeterinariosComposicao" pageWidth="535" pageHeight="802" columnWidth="535" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isTitleNewPage="true" uuid="04f710a4-be9e-4128-8025-455b2232a69e">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String">
        <defaultValueExpression><![CDATA["C:\\mapa_sipe\\workspace_producao\\sipe_trunk_producao\\sipe-ejb\\ejbModule\\br\\gov\\mapa\\sipe\\integracao\\relatorios\\produto\\"]]></defaultValueExpression>
    </parameter>
    <field name="dsComposicaoProduto" class="java.lang.String"/>
    <field name="dtConcessao" class="java.lang.String"/>
    <field name="dtRenovacao" class="java.lang.String"/>
    <field name="dtVencimentoRegistro" class="java.lang.String"/>
    <field name="composicaoComprimido" class="java.lang.Boolean"/>
    <field name="listaComprimidos" class="java.util.Collection"/>
    <field name="listaIngredienteProduto" class="java.util.Collection"/>
    <field name="nmMunicipioUFAssinatura" class="java.lang.String"/>
    <field name="dtRegistroAnterior" class="java.lang.String"/>
    <field name="dtDeferimento" class="java.lang.String"/>
    <field name="dsUsuarioDeferimento" class="java.lang.String"/>
    <title>
        <band height="5"/>
    </title>
    <detail>
        <band height="35" splitType="Stretch">
            <staticText>
                <reportElement uuid="87937c10-31d7-4ee1-8df6-3a03a4289180" x="0" y="0" width="221" height="16"/>
                <textElement verticalAlignment="Middle" markup="none">
                    <font size="11" isBold="true" isStrikeThrough="false" pdfFontName="Helvetica-Bold"/>
                </textElement>
                <text><![CDATA[FÓRMULA COMPLETA  DO PRODUTO]]></text>
            </staticText>
            <subreport isUsingCache="false" runToBottom="false">
                <reportElement uuid="6c86f9a9-1250-4357-8d58-3c9c88b3133f" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="0" y="16" width="535" height="19" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true">
                    <printWhenExpression><![CDATA[new Boolean($F{composicaoComprimido}.booleanValue())]]></printWhenExpression>
                </reportElement>
                <subreportParameter name="SUBREPORT_DIR">
                    <subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listaComprimidos})]]></dataSourceExpression>
                <subreportExpression><![CDATA[this.getClass().getClassLoader().getResourceAsStream($P{SUBREPORT_DIR} + "/CertificadoRegistroProdutoProdutosVeterinariosComposicaoComprimidos.jasper")]]></subreportExpression>
            </subreport>
        </band>
        <band height="43" splitType="Stretch">
            <textField>
                <reportElement uuid="2de034c4-f1d2-4b1e-8583-2a551c1665f6" positionType="Float" isPrintRepeatedValues="false" x="0" y="0" width="535" height="16" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true">
                    <printWhenExpression><![CDATA[new java.lang.Boolean($F{dsComposicaoProduto} != null)]]></printWhenExpression>
                </reportElement>
                <textElement verticalAlignment="Top" markup="none">
                    <font size="11"/>
                </textElement>
                <textFieldExpression><![CDATA["Cada "+$F{dsComposicaoProduto}+" do produto contém:"]]></textFieldExpression>
            </textField>
            <subreport isUsingCache="false" runToBottom="false">
                <reportElement uuid="ca0f248c-107b-466b-98a2-3a4b78d4805a" positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="0" y="16" width="535" height="27" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true">
                    <printWhenExpression><![CDATA[new java.lang.Boolean($F{dsComposicaoProduto} != null)]]></printWhenExpression>
                </reportElement>
                <subreportParameter name="dsComposicaoProduto">
                    <subreportParameterExpression><![CDATA[$F{dsComposicaoProduto}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listaIngredienteProduto})]]></dataSourceExpression>
                <subreportExpression><![CDATA[this.getClass().getClassLoader().getResourceAsStream($P{SUBREPORT_DIR} + "/CertificadoRegistroProdutoProdutosVeterinariosComposicao.jasper")]]></subreportExpression>
            </subreport>
        </band>
        <band height="130">
            <textField isBlankWhenNull="true">
                <reportElement uuid="854ebc23-ca5c-48a6-a682-01127ad82e26" positionType="Float" x="97" y="7" width="151" height="14" isRemoveLineWhenBlank="true"/>
                <box leftPadding="2"/>
                <textElement verticalAlignment="Middle">
                    <font size="11"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{dtConcessao}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement uuid="0d6b11e4-d6b9-4ed5-9975-7f47e4bddfee" positionType="Float" x="55" y="23" width="480" height="14" isRemoveLineWhenBlank="true"/>
                <box leftPadding="2"/>
                <textElement verticalAlignment="Middle">
                    <font size="11"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{dtRenovacao}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement uuid="ca9b0530-637d-4f0d-a64f-50af23e0eaea" positionType="Float" x="0" y="23" width="85" height="14" isRemoveLineWhenBlank="true">
                    <printWhenExpression><![CDATA[Boolean.valueOf($F{dtRenovacao} != null || !$F{dtRenovacao}.isEmpty())]]></printWhenExpression>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font size="11"/>
                </textElement>
                <text><![CDATA[Renovado:]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="052021f0-34da-4809-8e78-7a50b3a27034" positionType="Float" x="0" y="7" width="121" height="14"/>
                <textElement verticalAlignment="Middle">
                    <font size="11"/>
                </textElement>
                <text><![CDATA[Data de concessão:]]></text>
            </staticText>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement uuid="42bc40e6-87b9-40ab-bf33-4339dac42409" positionType="Float" stretchType="RelativeToBandHeight" isPrintRepeatedValues="false" x="0" y="43" width="535" height="14" isPrintWhenDetailOverflows="true"/>
                <textElement textAlignment="Center" verticalAlignment="Bottom">
                    <font size="11"/>
                </textElement>
                <textFieldExpression><![CDATA["Esta licença é valida até: "+ $F{dtVencimentoRegistro}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement uuid="25992ad2-2ca0-483b-b24c-daef0ecad6b0" positionType="Float" x="458" y="7" width="77" height="14" isRemoveLineWhenBlank="true">
                    <printWhenExpression><![CDATA[new Boolean($F{dtRegistroAnterior} != "")]]></printWhenExpression>
                </reportElement>
                <box leftPadding="2"/>
                <textElement verticalAlignment="Middle">
                    <font size="11"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{dtRegistroAnterior}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement uuid="e0ff2299-210f-4b7f-9ea5-a3eb8a830eff" positionType="Float" x="363" y="7" width="140" height="14">
                    <printWhenExpression><![CDATA[new Boolean($F{dtRegistroAnterior} != "")]]></printWhenExpression>
                </reportElement>
                <textElement verticalAlignment="Middle">
                    <font size="11"/>
                </textElement>
                <text><![CDATA[Data do 1º registro:]]></text>
            </staticText>
            <textField isBlankWhenNull="true">
                <reportElement uuid="05cb6077-8a6a-478f-aaa4-1a021a8ed7d3" isPrintRepeatedValues="false" x="0" y="70" width="535" height="50" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>
                <textElement textAlignment="Justified" verticalAlignment="Middle" markup="html">
                    <font size="10"/>
                </textElement>
                <textFieldExpression><![CDATA["Documento assinado eletronicamente por  <b>" + $F{dsUsuarioDeferimento} +  "</b> ,  em " + $F{dtDeferimento} +  " , com fundamento no art. 6º, § , 1º, do <a href='http://www.planalto.gov.br/ccivil_03/_Ato2015-2018/2015/Decreto/D8539.htm'><u><span style='color:#0000EE'>Decreto nº 8.539, de 8 de outubro de 2015.</span></u></a>"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

... works like a charm (just putted your textfield snipped into an empty design):

<?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="report12" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="09565e94-7305-4c20-bd80-8383c088a43a">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <field name="dtDeferimento" class="java.lang.String"/>
    <field name="dsUsuarioDeferimento" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement isPrintRepeatedValues="false" x="0" y="70" width="535" height="50" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="40729a1f-839b-40ca-8fe4-d053cfcbca5b"/>
                <textElement textAlignment="Justified" verticalAlignment="Middle" markup="html">
                    <font size="10"/>
                </textElement>
                <textFieldExpression><![CDATA["Documento assinado eletronicamente por  <b>" + $F{dsUsuarioDeferimento} +  "</b> ,  em " + $F{dtDeferimento} +  " , com fundamento no art. 6º, § , 1º, do <a href='http://www.planalto.gov.br/ccivil_03/_Ato2015-2018/2015/Decreto/D8539.htm'><u><span style='color:#0000EE'>Decreto nº 8.539, de 8 de outubro de 2015.</span></u></a>"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

see preview:

so no glue what's going wrong?!?!

C-Box

C-Box's picture
20551
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago

I dont have any idea, empty one works, preview works, but when i generate the jasper, don't work

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

Maybe is the iReport version, idk, i have a lot of jrxml files with the same problem

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

... and also just copied your full JRXML into my iReport and run it against EMPTY DATASOURCE:

works... so I just can imagine, that the field content of your Field "dsUsuarioDeferimento" contains some illegal characters, that escapes the html-syntax!?!??!

Could you post the field content also?

regards from Dresden/Germany

C-Box

C-Box's picture
20551
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago

So if it's okay in iReport and not in your java-app.... then you should check the involved fonts. Check if all used fonts are available to the JVM and use a FontExtension for custom font's . Jasper itself has also a built-in font-extendsion when I remember right. (jasperreports-fonts-5.5.1.jar that should be within the classpath of your app)

Probably your app don't know how to render the bold part of your textelement because of a missing bold-font??!

regards

C-Box

C-Box's picture
20551
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago

I tried with "Teste" rather than  "dsUsuarioDeferimento" and didnt work.  I'm gonna check the involved fonts now

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

When I use <font size="10" pdfFontName="Helvetica-Bold"/> works, but the whole text, not only <b> part. Maybe it's a glue

stenio.vilar's picture
Joined: Mar 27 2019 - 2:21pm
Last seen: 2 years 7 months ago

It may be a limitation with iReport. More the reason to switch to Jaspersoft Studio. I remember 5.5.x versions and earlier 6.x having some problems that were fixed in 6.2.x.

Sorry, but I can't replicate the problem with Jaspersoft Studio.

hozawa's picture
176559
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 11 months ago

I'd avoid switching to JasperSoftStudio if you don't need any new features of JR > 6.x  --> it's a PAIN working with it, as it's terrible slow even on a Core7 with SSD and 16GB RAM.... (tested on serveral machines here at work and also at home) so if you are used in RAPID designing your JRXMLs the Netbeans based iReport is still the best choice -> of course not with the latest version of JasperReports.

I don't know why the new Eclipse based Studio isn't optimized and don't understand where the performance is lost. I guess it's kind of bug whith rendering the jr-design object model.

So as we intensively used the html formatting text features I can confirm, that there is NO problem within JR 5.5.1 with inline bold segments in a textfield... even when exporting to PDF! Many customers of us use this feature in there outgoing pdfs. Of course we use another Font (Arial) and we created a FontExtension for that.

Also the sample report (see other post) is running fine in iReport 5.5.1 -> in preview and also in pdf-export. So the JR5.5.1-engine works well!

@stenio that's why: track down the FontExtension problem in your application.  For testing you could also change the font to the built-in DeJavu fonts.

When I remember right, these are included in the default JasperReportsFontExtensions (that sould be as welll in your classpath of course!)

hth + regards 

C-Box

C-Box's picture
20551
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 1 week ago

Yeah the font here might be the problem. Make sure you're using an actually available font like DjvuSans or DjvuSerif that has bold and italic versions as well. You currently use SansSerif which is a wildcard font and it's rendering in runtime can be unreliable.

Friendly User's picture
Joined: Oct 8 2009 - 5:59am
Last seen: 2 months 3 weeks ago
Feedback
randomness