Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - Styled Text Sample (version 4.0.1) | |
|
|
|
Main Features in This Sample | |
| Styled Text |
|
|
Secondary Features | |
Creating Styled Text Using a Markup Language |
|
|
||||
top | |||||
|
|||||
Styled Text | Documented by Sanda Zaharia | ||||
|
|||||
| Description / Goal |
| How to format text using a styled text tags as markup language. | ||
| Since |
| 2.0.5 | ||
|
|||||
|
Styled Text
The text content in text elements can be formatted using some particular style attributes such as foreground color, background color, font name, font size, font weight, etc. Document styles also contain text formatting attributes ( forecolor ,
backcolor , etc) and can be used to customize the text appearance inside the report element. All these style
attributes affect the entire text content in the report element.
But there are situations when one needs to apply a style only to some parts of the text paragraph. Users may want to highlight only few words within the text, with no affecting the rest of the paragraph. The solution formerly used was to set the isStyledText attribute of the text element. It is now a deprecated
solution and is replaced by the use of the markup="styled" setting.
If isStyledText="true" is set the engine gets notified that the text element contains a structured XML fragment
with JasperReports proprietary processing rules.
Styled Text Markup Tags The JasperReports proprietary markup language is called styled text and is an XML based format in which the style of any portion of text inside a text element can be changed by embedding that portion inside a <style> tag or other simple HTML tag from the following list:
<style> tag has various attributes for altering the color, font, or other style
properties of the text. From the standard HTML <font> tag, only the fontFace, color,
and size attributes are recognized by the JasperReports engine. Each individual
style property is inherited from the overall text element or from the parent <style> tag
when nested <style> tags are used.
The Styled Text Sample This sample contains various styled text paragraphs, illustrating the use of the styled text tags enumerated above. The first paragraph is obtained by processing the following fragment: This is a <style isBold="true" isItalic="true" isUnderline="true">static text</style> element containing styled text. <style backcolor="yellow" isBold="true" isItalic="true">Styled text</style> elements are introduced by setting the <style forecolor="blue" isItalic="true">markup</style> attribute available for the <style isBold="true" forecolor="magenta">textElement</style> tag to <style forecolor="red" isItalic="true">styled</style> and by formatting the text content using nested <style isBold="true" forecolor="green">style</style> tags and simple HTML tags.The next one is obtained by processing the following fragment: This text field element contains styled text displaying the text-only version of the <style size=\"12\" isBold=\"true\" forecolor=\"black\">^<style forecolor=\"#808080\">Jasper</style> <style forecolor=\"#990000\">Reports</style></style> logo and some <font size=\"10\"><sup>superscript</sup></font> text and <font size=\"10\"><sub>subscript</sub></font> text.Then the text in the left column is obtained by processing the following fragment: Here is the list with the attributes supported by the <style isBold="true">style</style> tag used to format the text content inside a styled text element: fontName <style size="32">size</style> <style isBold="true">isBold</style> <style isItalic="true">isItalic</style> <style isUnderline="true">isUnderline</style> <style isStrikeThrough="true">isStrikeThrough</style> pdfFontName pdfEncoding isPdfEmbedded <style forecolor="red">forecolor</style> <style backcolor="blue" forecolor="white" isBold="true">backcolor</style>The text in the column to the right is obtained by processing the following fragment: Here is the list with the supported HTML tags : <font size="12"><font size="12"></font> <font color="red"><font color="red"></font> <font face="DejaVu Serif"><font face="DejaVu Serif"></font> <b>bold <b></b> <i>italic <i></i> <u>underlined <u></u> an empty line follows (<br/>): <br/> <sup><sup></sup> and <sub><sub></sub> <br/> A bulleted list: <li>item 1 <li></li>The next paragraph is obtained by processing the following fragment: ampersand & less < greater > quote " apostrophe ' ampersand & less < greater > quote " apostrophe 'And the last fragment is obtained by processing the following: <style size=\"16\">1</style>\n<style size=\"24\">2</style>\n<style size=\"32\">3</style>\n <style size=\"24\">2</style>\n<style size=\"16\">1</style>\nFor more information about the recommended text formatting solution, please take a look at the Markup Sample. Running 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/styledtext 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/styledtext/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
||||
|
|
© 2001-2010 Jaspersoft Corporation www.jaspersoft.com |