【问题标题】:Jasper iReport weird space between Static Text and Text FieldJasper iReport 静态文本和文本字段之间的奇怪空间
【发布时间】:2018-03-14 21:45:27
【问题描述】:

我有一个带有静态文本的 Jasper/iReport 和一个文本字段,如下所示:

如您所见,两个字段之间几乎没有多余的空间。但是当我渲染它时,它会像这样显示:

知道为什么吗?

Jrxml 示例

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fcf485a8-4a9b-49b5-ba23-15b22808d171">
    <property name="ireport.zoom" value="3.0"/>
    <property name="ireport.x" value="682"/>
    <property name="ireport.y" value="0"/>
    <field name="testfield" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="107" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="49" width="224" height="15" uuid="d706eb33-a1da-4ec2-b774-f27d6ea50b72"/>
                <textElement verticalAlignment="Middle" markup="none">
                    <font fontName="Arial" size="8" isBold="true"/>
                </textElement>
                <text><![CDATA[Please Note: In order to qualify for the Earlybird Discounts]]></text>
            </staticText>
            <textField>
                <reportElement x="224" y="49" width="59" height="15" uuid="a559bcca-c8b7-4a12-a45a-ee7a6677cccf"/>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial" size="8"/>
                </textElement>
                <textFieldExpression><![CDATA[($F{testfield} != null) ? $F{testfield} : "This is text field"]]></textFieldExpression>
            </textField>
        </band>
    </summary>
</jasperReport>

我注意到当我在 iReport 中预览时它显示正常,但是当您在 Adob​​e Reader 中打开时,它有额外的空间。

【问题讨论】:

  • 我首先想到的是在两个元素上添加边框,看看发生了什么
  • 取决于对齐方式、字体大小等。您应该发布小的 jrxml 来重现问题
  • jrxml 示例添加

标签: jasper-reports


【解决方案1】:

您可以将两个文本放在一个文本字段中,例如: "之前或之后收到" + $P{invoiceDTO}

如果这不可行,请在外观中设置“拉伸类型:无拉伸”。

【讨论】: