Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)

JasperReports - Rotation Sample (version 4.0.1)


Shows how rotated text could be used in report templates.

Download All Sample Source Files
Browse Sample Source Files on SVN


Main Features in This Sample

Rotated Text


top

Rotated TextDocumented 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:
  • to the left
  • to the right
  • upside-down
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 textAlignment, verticalAlignment and rotation attributes values.

Examples of combining horizontal alignment, vertical alignment and rotation in a <textElement /> 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:
  • textAlignment="Left"
  • verticalAlignment="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.
  • textAlignment="Center"
  • verticalAlignment="Bottom"
  • rotation="Left"
The resulting paragraph will be horizontally aligned right, vertically aligned middle, and the text will flow from bottom to top.
  • textAlignment="Right"
  • verticalAlignment="Middle"
  • rotation="Left"
The resulting paragraph will be horizontally aligned center, vertically aligned top, and the text will flow from bottom to top.
  • textAlignment="Left"
  • verticalAlignment="Middle"
  • rotation="UpsideDown"
The resulting paragraph will be horizontally aligned right, vertically aligned middle, and the text will flow from right to left.
  • textAlignment="Right"
  • verticalAlignment="Top"
  • rotation="UpsideDown"
The resulting paragraph will be horizontally aligned left, vertically aligned bottom, and the text will flow from right to left.
  • textAlignment="Right"
  • verticalAlignment="Middle"
  • rotation="Right"
The resulting paragraph will be horizontally aligned center, vertically aligned bottom, and the text will flow from top to bottom.
  • textAlignment="Center"
  • verticalAlignment="Bottom"
  • rotation="Right"
The resulting paragraph will be horizontally aligned left, vertically aligned middle, and the text will flow from top to bottom.
  • textAlignment="Left"
  • verticalAlignment="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:

  <staticText>
    <reportElement mode="Opaque" x="100" y="0" width="90" height="350" backcolor="#c0c0c0"/>
    <textElement textAlignment="Center" verticalAlignment="Bottom" rotation="Left">
      <font size="14"/>
    </textElement>
    <text><![CDATA[rotation="Left" textAlignment="Center" verticalAlignment="Bottom"]]></text>
  </staticText>


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/rotation 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/rotation/build/reports directory.
Then the report will open in the JasperReports internal viewer.



© 2001-2010 Jaspersoft Corporation www.jaspersoft.com