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

Free Support Forum - aspose.com

How to add Tooltip to a cell using ASPOSE API

Hi,


I have an FTL template file which we use to generate a PDF. i am trying to add a tooltip text to this template file using ASPOSE API.

Can someone please help how this can be done?

Here is a sample of my file -

<pre style=“margin-top: 0px; margin-bottom: 1em; padding: 5px; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; font-size: 13px; line-height: inherit; font-family: Consolas, Menlo, Monaco, “Lucida Console”, “Liberation Mono”, “DejaVu Sans Mono”, “Bitstream Vera Sans Mono”, “Courier New”, monospace, sans-serif; vertical-align: baseline; width: auto; max-height: 600px; overflow: auto; background-color: rgb(239, 240, 241); word-wrap: normal; color: rgb(36, 39, 41);”><code style=“margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, “Lucida Console”, “Liberation Mono”, “DejaVu Sans Mono”, “Bitstream Vera Sans Mono”, “Courier New”, monospace, sans-serif; vertical-align: baseline; white-space: inherit;”>


Hi How are you…!

Hi There,


Thanks for contacting support.

You can add annotation inside PDF and toggle its visibility by setting JavaScript Actions, so that it will look like a tooltip. Please check following code snippet to achieve the requirement. I have also attached an output generated by below code, for your reference.

Document
doc = new Document(dataDir + “Tooltip.pdf”);<o:p></o:p>

TextFragmentAbsorber tfa = new TextFragmentAbsorber("Hello World!");

doc.getPages().get_Item(1).accept(tfa);

Page page = doc.getPages().get_Item(1);

String name = "TXTANNOT";

String title = "Tooltip";

String comment = "Hi How Are You?";

TextAnnotation text = new TextAnnotation(page, tfa.getTextFragments().get_Item(1).getRectangle());

text.setName(name);

text.setTitle(title);

text.setContents(comment);

// These flags must be raised to suppress showing of annotation icon

text.setFlags(AnnotationFlags.NoView | AnnotationFlags.ReadOnly);

page.getAnnotations().add(text);

com.aspose.pdf.Rectangle popupRect = new com.aspose.pdf.Rectangle(90, 610, 235, 710);

// Add popup annotation

PopupAnnotation popup = new PopupAnnotation(page, popupRect);

page.getAnnotations().add(popup);

text.setPopup(popup);

popup.setParent(text);

// Add button

Field field = new ButtonField(page, tfa.getTextFragments().get_Item(1).getRectangle());

doc.getForm().add(field);

String fieldName = field.getPartialName();

String openScript = "var t = this.getAnnot(this.pageNum, '" + name + "'); t.popupOpen = true; var w = this.getField('" + fieldName + "'); w.setFocus();";

String closeScript = "var t = this.getAnnot(this.pageNum, '" + name + "'); t.popupOpen = false;";

PdfAction openaction = new JavascriptAction(openScript);

PdfAction closeaction = new JavascriptAction(closeScript);

// Set ButtonField actions

field.getActions().setOnEnter(openaction);

field.getActions().setOnExit(closeaction);

doc.save(dataDir + "ToolTip_out.pdf");



In case of any further assistance, please feel free to contact us.


Best Regards,

Is it possible to do in xml? I tried this way . Is there any other property where it lets you set read only?
<Attachment AttachmentType=“Note”
NoteContent=“This is a test for note popup window positioning.”
NoteHeading=“Test” IsNoteOpen=“true”
NoteWindowPositioningType=“Absolute”
NoteWindowLeft=“100” NoteWindowTop=“100”
NoteWindowWidth=“160” NoteWindowHeight=“100”>

Is there any xml tag for it?
TextAnnotation

Hello There,


Thanks for writing back.

We have logged an investigation ticket as PDFJAVA-36801 in our issue tracking system for your requirement. For now, you can add annotations by using above code snippet, after generating the PDF document from XML. As soon as we have some feedback from product team, we will definitely inform you. Please be patient and spare us little time.

We are sorry for the inconvenience.


Best Regards,

Hi,
I tried doing this, but the problem is we are using aspose.pdf.kit to generate our pdf. So is it possible to do this using Aspose.pdf.Kit api, because the api for TextFragmentAbsorber is part of Aspose.pdf for .net API.
Can you give some example of code snipped with that api?

Thank you for your help

Hi There,


Thanks for writing back.

I am afraid that you are using a quite old version of Aspose.Pdf for Java API, whereas we always recommend to use latest version of the API which is Aspose.Pdf for Java 17.4. Please note that Aspose.Pdf.Kit for java has been discontinued and its all features are incorporated in Aspose.Pdf for Java.

Please download latest version of the API and in case you still face any issue, please feel free to let us know.


Best Regards,