JasperReports logo version 7.0.0 Home - Samples - Configuration - Functions - FAQ - API (Javadoc)

JasperReports - Rotation Sample

Shows how rotated text could be used in report templates.

Main Features in This Sample

Rotated Text

Rotated Text

Documented by Sanda Zaharia

Description / Goal
How to rotate text elements.

Since: 0.5.2

Rotating paragraphs

There are three possibilities to rotate a text paragraph:

Any rotation above changes both the text's flow direction and the paragraph's relative position within its textbox container. In these conditions horizontal and vertical alignments should be reevaluated.

For example, let's consider a paragraph with Left horizontal alignment and Top vertical alignment. If this paragraph is rotated to the left, then it will be positioned into the left bottom area of its textbox container. The vertical alignment will change from Top to Bottom, and the text will flow from bottom to top.

Performing various combinations between horizontal alignment, vertical alignment and text's flow direction, leads to a large set of paragraph positions relative to its textbox container.

In JasperReports calculations related to text rotation are done at export time, based on the text element's hTextAlign, vTextAlign and rotation attributes values.

Examples of combining horizontal alignment, vertical alignment and rotation in a text element

Values allowed for the horizontal alignment are: Left, Center, Right and Justified. By default, horizontal alignment is set to Left.
Values allowed for the vertical alignment are: Top, Middle and Bottom. By default, vertical alignment is set to Top.
Values allowed for the text rotation are: None, Left, Right and UpsideDown. By default, text rotation is set to None.

Below are some possible combinations between them:

hTextAlign="Left"
vTextAlign="Top"
rotation="Left"

This is the case already described in the Rotating paragraphs section above. The resulting paragraph will be horizontally aligned left, vertically aligned bottom, and the text will flow from bottom to top.

hTextAlign="Center"
vTextAlign="Bottom"
rotation="Left"

The resulting paragraph will be horizontally aligned right, vertically aligned middle, and the text will flow from bottom to top.

hTextAlign="Right"
vTextAlign="Middle"
rotation="Left"

The resulting paragraph will be horizontally aligned center, vertically aligned top, and the text will flow from bottom to top.

hTextAlign="Left"
vTextAlign="Middle"
rotation="UpsideDown"

The resulting paragraph will be horizontally aligned right, vertically aligned middle, and the text will flow from right to left.

hTextAlign="Right"
vTextAlign="Top"
rotation="UpsideDown"

The resulting paragraph will be horizontally aligned left, vertically aligned bottom, and the text will flow from right to left.

hTextAlign="Right"
vTextAlign="Middle"
rotation="Right"

The resulting paragraph will be horizontally aligned center, vertically aligned bottom, and the text will flow from top to bottom.

hTextAlign="Center"
vTextAlign="Bottom"
rotation="Right"

The resulting paragraph will be horizontally aligned left, vertically aligned middle, and the text will flow from top to bottom.

hTextAlign="Left"
vTextAlign="Top"
rotation="Right"

The resulting paragraph will be horizontally aligned right, vertically aligned top, and the text will flow from top to bottom.

Below is a code snippet showing how to set text alignment and rotation in a static text. In this case the paragraph is horizontally centered, vertically aligned to bottom and rotated to the left:

<element kind="staticText" mode="Opaque" x="100" width="90" height="350" backcolor="#C0C0C0" hTextAlign="Center" vTextAlign="Bottom" rotation="Left">
  <text><![CDATA[rotation="Left"
    hTextAlign="Center"
    vTextAlign="Bottom"]] ></text>
</element>

Running the Sample

Running the sample requires the Apache Maven library. Make sure that maven is already installed on your system (version 3.6 or later). In a command prompt/terminal window set the current folder to demo/samples/rotation within the JasperReports source project and run the following command:

> mvn clean compile exec:exec@all

It will generate all supported document types containing the sample report in the demo/samples/rotation/target/reports directory.




© 2001- Cloud Software Group, Inc. www.jaspersoft.com