如何在项目符号列表上添加缩进?
How to add indentation on bullet list?
我想在我的文本字段中添加一些缩进。我已经添加了项目符号样式(将 <li>
标记添加到文本中),但 JasperSoft Studio 似乎不会自动缩进文本。
即使设置 "styled" 标记并在段落顶部添加 <ul>
标记,如下所示:
"<ul><li> Example text 1... </li><li> Example text 2... </li></ul>"
JasperSoft 仍然无法管理 <ul>
标签(不幸的是,查看文档,还有其他 HTML 标签..)所以结果不是我想要的。
此时我尝试在不同的论坛上进行搜索,我发现我可以创建一个手动 报告样式 并将其应用于我的文本字段(遵循本指南:Indentation in generated PDF using JasperReports) 但这对我没用。
我也尝试过手动配置,认为创建样式对 Jaspersoft 来说不太舒服,并为文本字段设置了这样的配置:
所以,设置为 left padding 属性 10 px 值,所有文本都应该有一个小位移正确的。设置第一行缩进 属性 at -10 px 段落的第一行应该自动到达 0 px 位置,基于页边距。
这应该是我所有的缩进,JasperSoft 似乎是因为这个才理解这一点的:
打印页面得到的结果完全不同。
有谁知道我忘记了什么?
这是一种无需使用属性标记 html 即可快速制作项目符号列表的方法,您已将其正确定义为 jasper-reports 不支持该标记。
使用unicode符号\u2022
表示项目符号,下面的例子文字(\n
是换行符)
"\u2022 Some text on line 1 that gets longer to wrap\n\u2022 This is text on line 2"
然后您可以按照Indentation in generated PDF using JasperReports
中的描述设置leftPadding="10"
和firstLineIndent="-10"
示例 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="Indentation" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f0ac92f3-35e5-417e-aecd-5c47be379bf8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="44" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="110" height="40" uuid="3563a40d-d80e-4e09-9d84-d4f1779c1895"/>
<box topPadding="0" leftPadding="10" bottomPadding="0" rightPadding="0"/>
<textElement markup="none">
<paragraph lineSpacing="Single" firstLineIndent="-10" leftIndent="0" spacingBefore="0"/>
</textElement>
<textFieldExpression><![CDATA["\u2022 Some text on line 1 that gets longer to wrap\n\u2022 This is text on line 2"]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
输出
Probably however if it was me I would have converted the text to a
JRDataSource
and used the jr:list
component. For an example on how to create a datasource from a String see this How to convert a , separated String to a table layout?
and if you instead are wondering how you can manipulate your text to insert the unicode see How can I replace a character with an unicode image?
编辑添加我喜欢的解决方案,避免 firstLineIndent="-10"
hack
解决方案是在本例中将字符串转换为JRDatasource
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList($P{testText}.split("\n")))
然后用了jr:list
,用了<field name="_THIS" class="java.lang.String"/>
完整 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="Indentation" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f0ac92f3-35e5-417e-aecd-5c47be379bf8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="ListDataset" uuid="a6053d26-ad58-4808-ac51-76e62529d7de">
<queryString>
<![CDATA[]]>
</queryString>
<field name="_THIS" class="java.lang.String"/>
</subDataset>
<parameter name="testText" class="java.lang.String">
<defaultValueExpression><![CDATA["Some text on line 1 that gets longer to wrap\nThis is text on line 2"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="34" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="170" height="20" uuid="a9d62b3a-cdad-4c44-a3e6-8e7688986380"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="ListDataset" uuid="a21cd89b-dd5a-4135-90e0-a84ef83bd9dc">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList($P{testText}.split("\n")))]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="20" width="170">
<ellipse>
<reportElement x="13" y="4" width="4" height="4" backcolor="#000000" uuid="c2a202b7-ca0f-4ce4-a2d8-35b314f8e1ee">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
</ellipse>
<textField isStretchWithOverflow="true">
<reportElement x="30" y="0" width="80" height="20" uuid="31b05be1-9d89-4928-aec8-095e15e66711"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</title>
</jasperReport>
输出与上面相同,但我们没有使用可能对某些导出造成问题的负值进行黑客攻击。
如果不需要文本重排,非常简单的方法:
- 将"Markup"设置为
none
- 使用
\u2022
获得子弹。
- 手动将文本分行
- 在没有项目符号的每一行前面加上
\u00a0\u00a0\u00a0
(不间断space)。这很好地伪造了缩进。
缺点:
- 您必须手动换行
- 不支持合理的段落间距。只能有整行空行。
我想在我的文本字段中添加一些缩进。我已经添加了项目符号样式(将 <li>
标记添加到文本中),但 JasperSoft Studio 似乎不会自动缩进文本。
即使设置 "styled" 标记并在段落顶部添加 <ul>
标记,如下所示:
"<ul><li> Example text 1... </li><li> Example text 2... </li></ul>"
JasperSoft 仍然无法管理 <ul>
标签(不幸的是,查看文档,还有其他 HTML 标签..)所以结果不是我想要的。
此时我尝试在不同的论坛上进行搜索,我发现我可以创建一个手动 报告样式 并将其应用于我的文本字段(遵循本指南:Indentation in generated PDF using JasperReports) 但这对我没用。
我也尝试过手动配置,认为创建样式对 Jaspersoft 来说不太舒服,并为文本字段设置了这样的配置:
所以,设置为 left padding 属性 10 px 值,所有文本都应该有一个小位移正确的。设置第一行缩进 属性 at -10 px 段落的第一行应该自动到达 0 px 位置,基于页边距。 这应该是我所有的缩进,JasperSoft 似乎是因为这个才理解这一点的:
打印页面得到的结果完全不同。
有谁知道我忘记了什么?
这是一种无需使用属性标记 html 即可快速制作项目符号列表的方法,您已将其正确定义为 jasper-reports 不支持该标记。
使用unicode符号\u2022
表示项目符号,下面的例子文字(\n
是换行符)
"\u2022 Some text on line 1 that gets longer to wrap\n\u2022 This is text on line 2"
然后您可以按照Indentation in generated PDF using JasperReports
中的描述设置leftPadding="10"
和firstLineIndent="-10"
示例 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="Indentation" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f0ac92f3-35e5-417e-aecd-5c47be379bf8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="44" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="110" height="40" uuid="3563a40d-d80e-4e09-9d84-d4f1779c1895"/>
<box topPadding="0" leftPadding="10" bottomPadding="0" rightPadding="0"/>
<textElement markup="none">
<paragraph lineSpacing="Single" firstLineIndent="-10" leftIndent="0" spacingBefore="0"/>
</textElement>
<textFieldExpression><![CDATA["\u2022 Some text on line 1 that gets longer to wrap\n\u2022 This is text on line 2"]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
输出
Probably however if it was me I would have converted the text to a
JRDataSource
and used thejr:list
component. For an example on how to create a datasource from a String see this How to convert a , separated String to a table layout? and if you instead are wondering how you can manipulate your text to insert the unicode see How can I replace a character with an unicode image?
编辑添加我喜欢的解决方案,避免 firstLineIndent="-10"
hack
解决方案是在本例中将字符串转换为JRDatasource
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList($P{testText}.split("\n")))
然后用了jr:list
,用了<field name="_THIS" class="java.lang.String"/>
完整 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="Indentation" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f0ac92f3-35e5-417e-aecd-5c47be379bf8">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="ListDataset" uuid="a6053d26-ad58-4808-ac51-76e62529d7de">
<queryString>
<![CDATA[]]>
</queryString>
<field name="_THIS" class="java.lang.String"/>
</subDataset>
<parameter name="testText" class="java.lang.String">
<defaultValueExpression><![CDATA["Some text on line 1 that gets longer to wrap\nThis is text on line 2"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="34" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="170" height="20" uuid="a9d62b3a-cdad-4c44-a3e6-8e7688986380"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="ListDataset" uuid="a21cd89b-dd5a-4135-90e0-a84ef83bd9dc">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList($P{testText}.split("\n")))]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="20" width="170">
<ellipse>
<reportElement x="13" y="4" width="4" height="4" backcolor="#000000" uuid="c2a202b7-ca0f-4ce4-a2d8-35b314f8e1ee">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
</ellipse>
<textField isStretchWithOverflow="true">
<reportElement x="30" y="0" width="80" height="20" uuid="31b05be1-9d89-4928-aec8-095e15e66711"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</title>
</jasperReport>
输出与上面相同,但我们没有使用可能对某些导出造成问题的负值进行黑客攻击。
如果不需要文本重排,非常简单的方法:
- 将"Markup"设置为
none
- 使用
\u2022
获得子弹。 - 手动将文本分行
- 在没有项目符号的每一行前面加上
\u00a0\u00a0\u00a0
(不间断space)。这很好地伪造了缩进。
缺点:
- 您必须手动换行
- 不支持合理的段落间距。只能有整行空行。