How to add padding to a bullet list?

I want to add some indentation to the text box. I already added the bullet style (adding the <li> to the text), but it seems that JasperSoft Studio does not automatically insert text into the text.

Even if you set the β€œstylized” markup and add the <ul> at the top of the paragraph as follows:

 "<ul><li> Example text 1... </li><li> Example text 2... </li></ul>" 

JasperSoft is still unable to control the <ul> (looking at the documentation, unfortunately, also at other HTML tags), so the result is not the one I wanted.

At this point, I tried to search in different forums, and I found that I could create a report style manually and apply it to the text field (following this guide: Indentation in the generated PDF file using JasperReports ), but niether it worked for me.

I also tried to set the manual configuration, believing that creating a style cannot be convenient for Jaspersoft and set this configuration in the text box:

Border configurationFirst line indentation

So, setting the value of the residual property to 10 px , the whole text should get a slight offset to the right. Setting the indentation property of the first line to -10 px , the first line of the paragraph should automatically go to the position 0 px , based on the edge of the page. This should be all my indentation, and it seems that JasperSoft understands this because of this:

JasperSoft text indentation

Printing a page, the result of which I get, is completely different.

Here

Does anyone know what I forgot?

+3
source share
1 answer

This would be a quick way to make a bullet list without using the tag html attribute, which you correctly identified as poorly supported by jasper reports.

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

 "\u2022 Some text on line 1 that gets longer to wrap\n\u2022 This is text on line 2" 

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

Jrxml example

 <?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> 

Output

result

Perhaps, however, if it were me, I would convert the text to a JRDataSource and use the jr:list component. For an example of how to create a data source from a String, see This. How to convert a selected String string to a table layout? , and if you are interested in how you can manipulate text to insert Unicode, see How to replace a character with an Unicode image?

Change the preferred add-on solution that avoids firstLineIndent="-10" hack

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

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

and then used 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> 

The result is the same as above, but we do not crack negative values ​​that can cause problems with a certain export.

+2
source

Source: https://habr.com/ru/post/977190/


All Articles