"justified" 属性 的 textField 和 staticText 在 jaspersoft 报告中不起作用
"justified" property of textField and staticText is not working in jaspersoft report
我想在 textField 和 staticText 中添加设置文本,因为它将在 jasper 报告中等分 space。
文本应该像下图一样分布。
将 textAlignment 设置为 "Justified",但它不起作用。
有人可以建议我解决这个问题吗?
我必须在 jasper 报告中执行此操作并生成 PDF 文件格式的报告。
<staticText>
<reportElement x="52" y="34" width="135" height="20" uuid="44eed122-c07e-42d0-b696-a6ad54b759a4"/>
<textElement textAlignment="Justified" verticalAlignment="Middle" rotation="None">
<font fontName="Serif" size="12"/>
</textElement>
<text><![CDATA[Welcome]]></text>
</staticText>
文本应像 PDF 报告中的波纹管文本一样分发。
Justification - 单词之间以及字形或字母之间的空格被拉伸或压缩,以便对齐 连续文本行 的左右两端。使用对齐时,习惯上通过简单地左对齐或右对齐来单独处理段落的最后一行,具体取决于语言方向。
所以您需要 行文本 才能看到 textAlignment="Left"
和 textAlignment="Justified"
值之间的区别。我想 alignment textAlignment="Justified"
可以正常工作,但它将文本视为 "the last line of a paragraph"。如果您将长文本放在 staticText 中,您将不会遇到任何麻烦 (v6.9.0.)。见下图。
解决方法可能是这样的:
- 创建 tabSet 变量
<variable name="tabSet" class="java.lang.String">
<variableExpression><![CDATA["					"]]></variableExpression>
<initialValueExpression><![CDATA["					"]]></initialValueExpression></variableExpression>
</variable>
- 将变量添加到您需要证明的任何表达式,包括 last\first 行
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
- 设置对齐方式和标记
<textElement textAlignment="Justified" markup="html"/>
完整示例如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3 -->
<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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="00216f45-7b94-4847-94ea-7ea4f1508a6e">
<scriptlet name="DynTable" class="net.sf.jasperreports.engine.JRDefaultScriptlet">
<scriptletDescription><![CDATA[]]></scriptletDescription>
</scriptlet>
<variable name="tabSet" class="java.lang.String">
<variableExpression><![CDATA["					"]]></variableExpression>
<initialValueExpression><![CDATA["					"]]></initialValueExpression>
</variable>
<detail>
<band height="560" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="20" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Justified" verticalAlignment="Middle" markup="styled"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="550" height="20" uuid="1132e9a7-8b30-4167-94ce-a013480dca9d"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Left"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Left" verticalAlignment="Justified"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="80" width="550" height="20" uuid="bc341f2a-916e-4391-90dc-8b68684d2c6c"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="100" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Justified" verticalAlignment="Justified" markup="none"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="160" width="550" height="20" uuid="8472fd7d-b77c-46bf-9a11-b5f4cd1fff78"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Left"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="180" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Left" verticalAlignment="Top"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="240" width="550" height="20" uuid="8da01066-6dc6-4551-8530-2ac179fab340"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Workaround"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="260" width="550" height="20" uuid="931c0377-e69d-41e9-8c0e-eec6b53d14d1"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="280" width="550" height="20" uuid="aa466b7b-c67b-4cf7-bb52-09d52fceedf6"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="300" width="550" height="20" uuid="e6cb9bd0-80b6-4138-9e58-803caf5b9c54"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="1" y="320" width="550" height="20" uuid="113a944e-b09b-419e-abf9-06b76959731d"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="340" width="550" height="20" uuid="920883bb-cd3a-4a26-99e4-ad0a5415033f"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
我想在 textField 和 staticText 中添加设置文本,因为它将在 jasper 报告中等分 space。
文本应该像下图一样分布。
将 textAlignment 设置为 "Justified",但它不起作用。
有人可以建议我解决这个问题吗?
我必须在 jasper 报告中执行此操作并生成 PDF 文件格式的报告。
<staticText>
<reportElement x="52" y="34" width="135" height="20" uuid="44eed122-c07e-42d0-b696-a6ad54b759a4"/>
<textElement textAlignment="Justified" verticalAlignment="Middle" rotation="None">
<font fontName="Serif" size="12"/>
</textElement>
<text><![CDATA[Welcome]]></text>
</staticText>
文本应像 PDF 报告中的波纹管文本一样分发。
Justification - 单词之间以及字形或字母之间的空格被拉伸或压缩,以便对齐 连续文本行 的左右两端。使用对齐时,习惯上通过简单地左对齐或右对齐来单独处理段落的最后一行,具体取决于语言方向。
所以您需要 行文本 才能看到 textAlignment="Left"
和 textAlignment="Justified"
值之间的区别。我想 alignment textAlignment="Justified"
可以正常工作,但它将文本视为 "the last line of a paragraph"。如果您将长文本放在 staticText 中,您将不会遇到任何麻烦 (v6.9.0.)。见下图。
解决方法可能是这样的:
- 创建 tabSet 变量
<variable name="tabSet" class="java.lang.String">
<variableExpression><![CDATA["					"]]></variableExpression>
<initialValueExpression><![CDATA["					"]]></initialValueExpression></variableExpression>
</variable>
- 将变量添加到您需要证明的任何表达式,包括 last\first 行
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
- 设置对齐方式和标记
<textElement textAlignment="Justified" markup="html"/>
完整示例如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3 -->
<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="report3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="00216f45-7b94-4847-94ea-7ea4f1508a6e">
<scriptlet name="DynTable" class="net.sf.jasperreports.engine.JRDefaultScriptlet">
<scriptletDescription><![CDATA[]]></scriptletDescription>
</scriptlet>
<variable name="tabSet" class="java.lang.String">
<variableExpression><![CDATA["					"]]></variableExpression>
<initialValueExpression><![CDATA["					"]]></initialValueExpression>
</variable>
<detail>
<band height="560" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="20" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Justified" verticalAlignment="Middle" markup="styled"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="550" height="20" uuid="1132e9a7-8b30-4167-94ce-a013480dca9d"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Left"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="550" height="20" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Left" verticalAlignment="Justified"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="80" width="550" height="20" uuid="bc341f2a-916e-4391-90dc-8b68684d2c6c"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Justified"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="100" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Justified" verticalAlignment="Justified" markup="none"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="160" width="550" height="20" uuid="8472fd7d-b77c-46bf-9a11-b5f4cd1fff78"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Left"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="180" width="550" height="60" uuid="803f5f42-1d88-4da6-973e-bb70e6e99388"/>
<textElement textAlignment="Left" verticalAlignment="Top"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="240" width="550" height="20" uuid="8da01066-6dc6-4551-8530-2ac179fab340"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Workaround"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="260" width="550" height="20" uuid="931c0377-e69d-41e9-8c0e-eec6b53d14d1"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="280" width="550" height="20" uuid="aa466b7b-c67b-4cf7-bb52-09d52fceedf6"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="300" width="550" height="20" uuid="e6cb9bd0-80b6-4138-9e58-803caf5b9c54"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="1" y="320" width="550" height="20" uuid="113a944e-b09b-419e-abf9-06b76959731d"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit"+$V{tabSet}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="340" width="550" height="20" uuid="920883bb-cd3a-4a26-99e4-ad0a5415033f"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Justified" markup="html"/>
<textFieldExpression><![CDATA["Lorem ipsum dolor sit amet"+$V{tabSet}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>