We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF Tool Tip Nullpointer Exception

Hello team!


I wanted to check if PDF Java supports a tool tip that can be added as a feature to the pdf document?

I was looking at this sample code you had:

// Open a document
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(“input.pdf”);

// Get a field
com.aspose.pdf.TextBoxField textBoxField = (com.aspose.pdf.TextBoxField)pdfDocument.getForm().get(“textbox1”);

// Set the tooltip for textfield
textBoxField.setAlternateName(“Text box tool tip”);

// Save modified document
pdfDocument.save(“output.pdf”);

However the code throws a null pointer exception on textBoxField.setAlternateName(“Text box tool tip”);
Any reason for this? I am using the aspose-pdf-9.5.0-jdk16.jar





Hi Troy,



Thanks for your inquiry. I am afraid I am unable to replicate the issue while tested the scenario with as sample PDF and Aspose.Pdf for Java 9.5.0. Please share your sample PDF document here, we will test the scenario and will guide you accordingly.

// Open a document <o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(myDir+"Input.pdf");

// Get a field

com.aspose.pdf.TextBoxField textBoxField = (com.aspose.pdf.TextBoxField)pdfDocument.getForm().get("Text1");

textBoxField.setAlternateName("TextBox Tool Tip");

// Save the updated document

pdfDocument.save(myDir+"output_tooltip.pdf");


We are sorry for the inconvenience caused.

Best Regards,

Tilal,


Thank you for sharing your output pdf file. Would you mind sharing your input pdf as well. I was unaware that the original input pdf file needs to have an already existing text box? In any case, please find my pdf I was testing with.

What does the tool tip exactly do? It seems that, when I hover over the first text box, I get the text “TextBox Tool Tip” similar to an html tag with <input type=“text”; title=“TextBox Tool Tip”/>

There doesnt seem to be any relavant functionality? I was under a different impression. I wanted something more of : When user hovers/clicks a word a tool tip box pops up allowing users different options such as high lighting, underlining, strikeout etc.

Can this be achievable? Can we have a “onClick/hover” function to call javascript, that launches a tool box with these different options?

Hi Troy,


Thanks for your feedback. Please find attached input PDF document for your reference. Yes tool tip just shows a text message. However we are looking into your other requirement and will let you know about our findings soon.

Best Regards,

Thank you Tilal for your input pdf file.


When I was talking about tool tip, I was thinking more in lines of :

http://jsfiddle.net/fDavN/6636/


When the user clicks part of a text or pdf document a “tooltip” or popup box should appear

tekstream:
I was unaware that the original input pdf file needs to have an already existing text box? In any case, please find my pdf I was testing with.
Hi Troy,

The input PDF file should have TextField because you are trying to set the AlternateName against some specific form field inside PDF form.

Hi,


Aspose.Pdf for .NET supports the feature to add Annotations to PDF file but as per your requirement, you may consider adding JavaScript to PDF file. However when adding JavaScript, you need to specify the rectangular region where JavaScript will be added. For more information, please visit Create JavaScript Link in Existing PDF File (Facades)