如何在项目符号列表上添加缩进?

Rob*_*rto 7 indentation jasper-reports

我想在我的文本字段中添加一些缩进。我已经添加了一个项目符号样式(将<li>标签添加到文本中),但似乎 JasperSoft Studio 不会自动缩进文本。

即使设置“样式化”标记并<ul>在段落顶部添加一个标签,如下所示:

"<ul><li> Example text 1... </li><li> Example text 2... </li></ul>"
Run Code Online (Sandbox Code Playgroud)

JasperSoft 仍然无法管理<ul>标签(不幸的是,查看文档,还有其他 HTML 标签..)所以结果不是我想要的。

在这一点上,我尝试在不同的论坛上进行搜索,我发现我可以创建手动报告样式并将其应用于我的文本字段(遵循本指南:使用 JasperReports 在生成的 PDF 中缩进),但这对我不起作用。

我也尝试过手动配置,觉得创建样式对Jaspersoft来说不太舒服,于是在文本字段设置了这样的配置:

边框配置 首行缩进

因此,将10 px值设置为left padding属性,所有文本都应该向右移动一个小位移。将第一行缩进属性设置为-10 px,段落的第一行应根据页面边距自动到达0 px位置。这应该是我所有的缩进,JasperSoft 似乎是因为这个而理解这一点的:

JasperSoft 文本缩进

打印页面我得到的结果是完全不同的。

这里

有谁知道我忘记了什么?

Pet*_*erg 5

This would be a quick way to make a bullet list without using attribute tag html, that you have correctly defined as not well supported by jasper-reports.

Use the unicode symbol \u2022 to represent the bullet, with the following example text (\n is line break)

"\u2022 Some text on line 1 that gets longer to wrap\n\u2022 This is text on line 2"
Run Code Online (Sandbox Code Playgroud)

Then you can set leftPadding="10" and firstLineIndent="-10" as described in Indentation in generated PDF using JasperReports

Example 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>
Run Code Online (Sandbox Code Playgroud)

Output

结果

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?

Edit adding solution preferred by me which avoids firstLineIndent="-10" hack

The solution is to convert the string into a JRDatasource in this example

 new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList($P{testText}.split("\n")))
Run Code Online (Sandbox Code Playgroud)

and then used the jr:list, with <field name="_THIS" class="java.lang.String"/>

Full 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>
Run Code Online (Sandbox Code Playgroud)

The output is same as above, but we are not hacking with negative values which could create problems on certain exports.