How to hide textField for specified exporter. For example for not HTML

Use an Element Key Filter.

The quote from JR Ultimate Guide:

This built-in filter implementations excludes from export elements that match a given element key.
Element keys are set at report design time and are propagated into generated reports.
Each element in a filled report has the same key as the element from the report template that generated it.
To trigger an element key filter, the report designer needs to define one or more report properties that start with <exporter_property_prefix>.exclude.key. Each such property matches a single element key which is to be excluded by the filter. The element key is given by the property value, or if no value is set for the property, by the property suffix.
The following example shows how to specify element keys which are to be excluded from specific export outputs:

<jasperReport ...>
    <!-- exclude elements with keys Image1 and Text4 from HTML export-->
    <property name="net.sf.jasperreports.export.html.exclude.key.Image1"/>
    <property name="net.sf.jasperreports.export.html.exclude.key.Text4"/>
    <!-- exclude elements with keys Image5 from PDF export -->
    <property name="net.sf.jasperreports.export.pdf.exclude.key.the.image" value=”Image5”/>
    ...
</jasperReport>

In your case you should add key for text field with hyperlink (for example, textFieldWithHL) and then add one property for each format (pdf, docx, xls, csv, xml, txt, odt) you want to exclude from printing this hyperlink:

<property name="net.sf.jasperreports.export.pdf.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.docx.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.xls.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.csv.exclude.key.textFieldWithHL"/>
<property name="net.sf.jasperreports.export.xml.exclude.key.textFieldWithHL"/>

The expressions from your post:

net.sf.jasperreports.export.{format}.exclude.origin.{suffix}.{arbitrary_name}
net.sf.jasperreports.export.{format}.exclude.origin.keep.first.{suffix}.{arbitrary_name}

allow to exclude the whole bands (also group bands). This filters work with JROrigin objects.


For example, consider a report with a logo that must be included as SVG for PDF output or PNG for HTML output. The JRXML file contains:

    <image scaleImage="RetainShape" onErrorType="Blank">
        <reportElement key="IMAGE_LOGO_PNG" x="1" y="0" width="100" height="60" uuid="a896cade-f6fc-4d8f-b762-29b950309257"/>
        <imageExpression><![CDATA[Transcoder.asPNG($V{V_LOGO_FILE} + ".svg")]]></imageExpression>
    </image>
    <image scaleImage="RetainShape" onErrorType="Blank">
        <reportElement key="IMAGE_LOGO_SVG" x="1" y="0" width="100" height="60" uuid="a896cade-f6fc-4d8f-b762-29b950309257"/>
        <imageExpression><![CDATA[Transcoder.asSVG($V{V_LOGO_FILE} + ".svg")]]></imageExpression>
    </image>

To exclude the SVG from HTML and the PNG from PDF, add the following properties immediately after the <jasperReport...> root element in the JRXML file:

<property name="net.sf.jasperreports.export.html.exclude.key.IMAGE_LOGO_SVG"/>
<property name="net.sf.jasperreports.export.pdf.exclude.key.IMAGE_LOGO_PNG"/>

Leave a Comment