Anchors in JasperReport

Posted on by By admin, in Business Intelligence, Jaspersoft, Open Source Business Intelligence | 0

Anchors in JasperReport

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

What is anchor?
Anchor provides easy access to different sections of the  report through link. One can implement this functionality in jasper using anchor expression in hyperlink. Anchor should always return ‘java.lang.String’ values.
While creating jasperreports we can use anchors in text field or image element component in the irpeort. Most important thing about these anchors is that they are also present in the pdf export of the report.

There are different types of anchor expression in ireport:

1. Local anchor: using this type of anchor expression one can tag the specific content in the report .

Example:
Creating a Local Anchor Example

 <textField>
<reportElement x="4" y="4" width="450" height="20"/>
<textElement>
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression class="java.lang.String">"TITLE section"</textFieldExpression>
<anchorNameExpression>"title"</anchorNameExpression>
</textField>

The <anchorNameExpression> tag was used here in order to associate a local anchor, named title, with this text field.

Creating a Local Anchor Hyperlink Example

<textField hyperlinkType="LocalAnchor">
<reportElement x="4" y="40" width="400" height="20" forecolor="#FF0000"/>
<textFieldExpression class="java.lang.String">">> Click here to go to the title section."</textFieldExpression>
<hyperlinkAnchorExpression>"title"</hyperlinkAnchorExpression>
</textField>

The hyperlink created using the <hyperlinkAnchorExpression> tag points to the local anchor created above.

2. Local page: using this type of anchor expression one can tag the specific page in the report .

Creating a Local Page Hyperlink Example

<textField hyperlinkType="LocalPage">
<reportElement x="5" y="65" width="300" height="15" forecolor="#008000"/>
<textFieldExpression class="java.lang.String">"  >> Click here to go to the second page."</textFieldExpression>
<hyperlinkPageExpression>Integer.valueOf(2)</hyperlinkPageExpression>
</textField>

The hyperlink created using the <hyperlinkPageExpression> tag points to the second page of the current document.

3. Reference URL in the anchor: Using this anchor we can also put the URL in the report.

Creating a Reference Hyperlink Example

<textField hyperlinkType="Reference">
<reportElement x="5" y="95" width="300" height="15"/>
<textFieldExpression class="java.lang.String">"  >> Click here to go to www.google.com"</textFieldExpression>
<hyperlinkReferenceExpression>"http://www.google.com"</hyperlinkReferenceExpression>
</textField>

The hyperlink created using the <hyperlinkReferenceExpression> tag points to the www.google.com site.

4. Remote anchor hyperlink: The hyperlink created using the <hyperlinkReferenceExpression>and <hyperlinkAnchorExpression> tags points to an anchor named ‘title’ found in the HyperlinkReport.pdf document, saved in the current directory.

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Creating a Remote Anchor Hyperlink Example

<textField hyperlinkType="RemoteAnchor">
<reportElement x="5" y="125" width="350" height="15"/>
<textFieldExpression class="java.lang.String">"  >> Click here to go to another PDF file."</textFieldExpression>
<hyperlinkReferenceExpression>"./HyperlinkReport.pdf"</hyperlinkReferenceExpression>
<hyperlinkAnchorExpression>"title"</hyperlinkAnchorExpression>
</textField>

5.  Remote page hyperlink:
The hyperlink created using the <hyperlinkReferenceExpression> and <hyperlinkPageExpression> tags points to the second page of the HyperlinkReport.pdf document, saved in the current directory.

Creating a Remote Page Hyperlink Example

<textField hyperlinkType="RemoteAnchor">
<reportElement x="5" y="125" width="350" height="15"/>
<textFieldExpression class="java.lang.String">"  >> Click here to go to another PDF file."</textFieldExpression>
<hyperlinkReferenceExpression>"./HyperlinkReport.pdf"</hyperlinkReferenceExpression>
<hyperlinkPageExpression>Integer.valueOf(2)</hyperlinkPageExpression>
</textField>
logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

Thanks,
Nisha Sahu

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments