Create an external URL hyperlink with JasperReports

前端 未结 2 1442
天命终不由人
天命终不由人 2020-12-03 05:30

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 ge

相关标签:
2条回答
  • 2020-12-03 05:53

    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>
    
    0 讨论(0)
  • 2020-12-03 05:54

    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.

    0 讨论(0)
提交回复
热议问题