Jump to content

tooltips in jasperreports created pdf


zatalian

Recommended Posts

Hi,

I have a report created with jasperreports with lots of tooltips and hyperlinks. I can see them in jasperviewer.

I was wondering if it is possible to view those tooltips in acroread when i export the report to a pdf file.

 



Post Edited by zatalian at 09/30/2009 18:13
Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

The PDF exporter does not currently honor element tooltips because there is no native support for tooltips in PDF.  It might be possible with annotations, that's something that we could look into.

Therefore currently there is no way to have tooltips in PDFs generated by JR.  Log a bug/feature request for this if you think we should investigate whether there's a solution for this.

Regards,

Lucian

Link to comment
Share on other sites

I almost solved it by extending the standard JRPdfExporter :

 

public class StudentPdfExporter extends JRPdfExporter
{
    @Override protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link)
    {
        switch (link.getHyperlinkType())
        {
            case JRHyperlink.HYPERLINK_TYPE_REFERENCE :
            {
                if ((link.getHyperlinkTooltip() != null) && (link.getHyperlinkReference() == null))
                {
                    PdfFormField pushButton = PdfFormField.createPushButton(pdfWriter);
                    pushButton.setFieldName(link.getHyperlinkTooltip());
                    Rectangle rect = new Rectangle(0, 0, 0, 0);
                    pushButton.setWidget(rect, PdfAnnotation.HIGHLIGHT_NONE);
                    pushButton.put(PdfName.TU, new PdfString(link.getHyperlinkTooltip(), PdfObject.TEXT_UNICODE));
                    chunk.setAnnotation(pushButton);
                }
                else super.setHyperlinkInfo(chunk, link);
                break;
            }

            default :
            {
                super.setHyperlinkInfo(chunk, link);
                break;
            }
        }
    }
}

 

If i use a "self reference" hyperlink with a reference and tooltip, things work as expected by using the old JRPdfExporter.

When i use a "self reference" hyperlink with a blank reference, I create a PdfFormField annotation like suggested above. This creates a nice tooltip, but only for the first line of detail. All other lines don't show the tooltip anymore...

Look at the attached pdf to see what i mean. The studentnumbers in the pdf are normal "self reference" hyperlinks which work. Under the numbers 39 to 43 you should find tooltips for every student, but the tooltips only work for the first student....

 

Any idea on how to solve this one?

Link to comment
Share on other sites

I solved it!!

The pushButton's need to have a unique name. Using the tooltip as name was not good.

I'm using the hash of the chunk to create a unique name now and tadaa... it's working.

I'm even using HYPERLINK_TYPE_NONE, so i don't have to mess with the reference type.

 

public class StudentPdfExporter extends JRPdfExporter
{
    @Override protected void setHyperlinkInfo(Chunk chunk, JRPrintHyperlink link)
    {
        switch (link.getHyperlinkType())
        {
            case JRHyperlink.HYPERLINK_TYPE_NONE :
            {
                if (link.getHyperlinkTooltip() != null)
                {
                    PdfFormField pushButton = PdfFormField.createPushButton(pdfWriter);
                    pushButton.setFieldName(String.format("tooltip%s", chunk.hashCode()));
                    Rectangle rect = new Rectangle(0, 0, 0, 0);
                    pushButton.setWidget(rect, PdfAnnotation.HIGHLIGHT_NONE);
                    pushButton.put(PdfName.TU, new PdfString(link.getHyperlinkTooltip(), PdfObject.TEXT_UNICODE));
                    chunk.setAnnotation(pushButton);
                }
                break;
            }

            default :
            {
                super.setHyperlinkInfo(chunk, link);
                break;
            }
        }
    }
}

 

Thanks for the hint that pointed me i the right direction!

 

Link to comment
Share on other sites

  • 9 months later...

Hi

I am facing the same problem trying to get the tooltips to my pdf document . I have used the above code but facing some issue on the line "chunk.setAnnotation(pushButton)" .It is getting stuck here and not moving to the second line of detail

if i comment the above line , everything goes fine but pdf created is without a hyperlink.

Is there any way to do get the tootips on to xls document? or is there any way of hiding or masking the url that appears when you hover the mouse pointer.

thanks in advance...

Regards

Siva Praneeth

 

Link to comment
Share on other sites

Hi,

 

Not sure what you mean by "is getting stuck here and not moving to the second line of detail".

If you have an exception, post the stack trace here.

 

As for Excel exports. We are not sure we are able to set them using the third party APIs we use for generating XLS files.

Log a request for enhancemnt for that and we'll look into it:

http://jasperforge.org/projects/jasperreports/tracker

 

Thank you,

Teodor

 

 

Link to comment
Share on other sites

Hi Teodor ,

 

Thanks for the quick reply. I donot get any exception there on the line and the report is not exported to pdf. Is there anyway we can stop showing the URL when you hover your mouse over it? This also solves my issue.

 

I have requested for an enhancement in the trackers

 

Thank you

Siva.

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

There must be some exception there, which should explain why the PDF is not generated. You should use a debugger to go thought the code and see if the exceptions are caught and hidden somehow by an empty try/catch statement.

 

As for hidding the default tooltips in XLS, I don't have a solution either. If we did not yet find a way to set them, it means we don't have a way to hide them either.

Depending on which XLS exporter you are using (JRXlsExporter class or JExcelApiExporter), maybe you can give us a hand and look thourhg our open source code and the POI/JExcelApi documentation and find a solution to the problem. Then you would be in a position to contribute that back to the JasperReports community.

 

Thank you,
Teodor

 

Link to comment
Share on other sites

  • 2 months later...

Hi guys,

Where does the pdfWriter variable come from above?

PdfFormField pushButton = PdfFormField.createPushButton(pdfWriter);

Looks like just what I'm after, but can't figure out how to satisfy that parameter.

Would love some help.  I really need to get tooltips exported into my PDF's, as the report makes heavy use of them for documenting outcomes.

Thanks,

Craig

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...