| JasperReports Ultimate Guide - Samples - Schema - Configuration - Functions - FAQ - API (Javadoc)
|
|
|
|
|
| JasperReports - Paragraph Sample (version master-SNAPSHOT) | |
|
|
|
|
|
|
| Main Features in This Sample | |
|
| Paragraphs |
|
|
|
||||
| top | |||||
|
|
|||||
![]() | Paragraphs | Documented by Sanda Zaharia | |||
|
|
|||||
|
| Description / Goal |
| How to format texts using paragraph properties. | ||
|
| Since |
| 4.0.2 | ||
|
|
|||||
|
|
Working with Paragraphs
When we place text content in a report element, we may need to make it look like a distinct paragraph. The information needed in this case can be retrieved either from the element's style (where we have attributes for text alignment), or from the <paragraph/> tag that is available within <style/> and/or <textElement/>.
Example:
<textField>
<reportElement .../>
<textElement textAlignment="Right">
<paragraph lineSpacing="Fixed" lineSpacingSize="20.0">
<tabStop position="20" alignment="Center"/>
<tabStop position="40" alignment="Center"/>
</paragraph>
</textElement>
<textFieldExpression>...</textFieldExpression>
</textField>
Paragraph Alignment
A paragraph can be aligned both horizontally and vertically. For the horizontal alignment we can choose one of the following options:
<style name="MyParagraphStyle" hTextAlign="Center" vTextAlign="Middle" ... />
...
<textField>
<reportElement style="MyParagraphStyle".../>
<textElement/>
<textFieldExpression>...</textFieldExpression>
</textField>
or:
<textField>
<reportElement .../>
<textElement textAlignment="Center" verticalAlignment="Middle" ... />
<textFieldExpression>...</textFieldExpression>
</textField>
or:
<textField>
<reportElement ...>
<property name="net.sf.jasperreports.style.hTextAlign" value="Center"/>
<property name="net.sf.jasperreports.style.vTextAlign" value="Middle"/>
</reportElement>
<textElement/>
<textFieldExpression>...</textFieldExpression>
</textField>
Line Spacing
For a given paragraph one can apply various settings for line spacing, as attributes of the <paragraph/> tag associated with the text element:
<textField textAdjust="StretchHeight">
<reportElement .../>
<textElement ...>
<paragraph lineSpacing="Fixed" lineSpacingSize="20.0" spacingBefore="6" spacingAfter="12">
</textElement>
<textFieldExpression>...</textFieldExpression>
</textField>
Paragraph Indentation
JasperReports also supports paragraph indentation, which can be customized using the following attributes of the <paragraph/> tag:
<style name="indentStyle" isDefault="true" fontName="DejaVu Sans"> <paragraph firstLineIndent="20" leftIndent="35" rightIndent="20"/> </style>Tab Stops In a given text element we can configure custom tab stops as well, by placing a sequence of <tabStop/> elements
inside a <paragraph/> tag. A custom tab stop is completely characterized by its position and alignment:
tabStopWidth attribute of the <paragraph/>.
Examples: <paragraph lineSpacing="Fixed" lineSpacingSize="20.0" tabStopWidth="20"/> or <paragraph lineSpacing="Fixed" lineSpacingSize="20.0"> <tabStop position="20"/> <tabStop position="40" alignment="Center"/> <tabStop position="80" alignment="Right"/> </paragraph>Default Values for Paragraph Settings In case we need the same paragraph settings to be applied for all reports that share the same context, we can use the following properties that can be set on the report context:
default.jasperreports.properties file:
net.sf.jasperreports.default.line.spacing.size=1 net.sf.jasperreports.default.first.line.indent=0 net.sf.jasperreports.default.left.indent=0 net.sf.jasperreports.default.right.indent=0 net.sf.jasperreports.default.spacing.before=0 net.sf.jasperreports.default.spacing.after=0 net.sf.jasperreports.default.tab.stop.width=40Running the Sample Running the sample requires the Apache Ant library. Make sure that ant is already installed on your system (version 1.5 or later).
In a command prompt/terminal window set the current folder to demo/samples/paragraphs within the JasperReports source project and run the > ant test view command.
It will generate all supported document types containing the sample report in the demo/samples/paragraphs/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
||||
|
|
|||||
|
|
| © 2001- Cloud Software Group, Inc. www.jaspersoft.com |