Hi,
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”);
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,
Save Editcancel
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,
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,