Jump to content
We've recently updated our Privacy Statement, available here ×

Disabling hyperlink in PDF


sgolestane

Recommended Posts

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

There are two ways to achieve this:

1) Duplicate the elements that have hyperlinks and make one copy with and the other without hyperlinks, one on top of the other. Make sure you mark these elements with different keys (key attribute): "hyper" and "nohyper", for example. Then, when you export them to HTML and PDF, make use of a key-based element filter to filter out hyper or nohyper elements from the generated output.

See the ElementKeyExporterFilter class and the JRExporterParameter.FILTER exporter parameter for more details.

2) Use custom hyperlink support in JR. You invent a new type of hyperlink, let's say "MyHyperlink". This type of hyperlink of yours has some parameters that you define yourself (at a minimun, this hyperlink could have only one parameter, which is the entire target URL itself). Then, you create custom hyperlink handlers for both the HTML and the PDF exporter, to deal with this type of hyperlink of yours. In HTML, you will produce normal hyperlinks, while in PDF, your handler will ignore those hyperlinks and not create them.

For more details about custom hyperlinks, see the Javadocs starting here:

http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRHyperlinkProducer.html

I hope this helps.

Teodor

Link to comment
Share on other sites

Thanks Teodor,

This how I addressed this requirement. As we don't want to have any hypelink in PDF exports, i extended JRPdfExporter and overloaded setHyperlinkInfo with a method with and empty body.

 

Code:
public class JRPdfExporterWithoutHyperlinks extends JRPdfExporter{    @Override    protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link)    {        //do nothing, we don't want Hyperlinks in pdf    }}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...