How do you include a hyperlink (URL) in a PDF that links to an external site?
Using a simple string like "http://www.stackoverflow.com", a link is automatically generated. But, how can I use a URL like <a href="http://www.stackoverflow.com">Click here</a>
?
If I use this HTML string, Jaspers create a link but also shows the code.
Using JasperReports 4.0.4 and iReport 4.5.1.
To set anchor, bookmark, or hyperlink properties, go to the Hyperlink tab in the Properties view. Use Anchor and Bookmark to create an anchor inside the current document; it is only available for elements that support hyperlinks (textfield, image, and chart).
jasper. properties is looked up by jasper reports in the classpath, so it can be directly in the WEB-INF/classes folder, or in the root folder of any of the jars in WEB-INF/lib.
The best way to use a font in JasperReports Library is to use a font extension. Jaspersoft fonts can be configured in Studio and Server and displayed in the PDF view. Fonts can be referred from an URL and from the file system using the Preferences dialog window from the Jaspersoft Studio.
To make a textField a hyperlink to an external URL, you need to add the attribute hyperlinkType="Reference"
to the element, and add a <hyperlinkReferenceExpression>
tag within it. The reference expression is where you put the URL.
For example:
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement x="5" y="5" width="200" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA["Click Here!"]]></textFieldExpression>
<hyperlinkReferenceExpression><![CDATA["http://www.google.com"]]></hyperlinkReferenceExpression>
</textField>
The hyperlinkTarget
attribute behaves in the same way as the target
attribute in HTML.
Note that only textFields, images, and charts can be hyperlinked in this way.
For some reasons, the example given didn't work. I used wayback machine and found the following snippet that worked:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With