Add Tooltip in PDF in Java

This short guide explains how to add a tooltip in PDF in Java. It shares a complete sample code to create a PDF and add control for demonstrating PDF hover text in Java. You will get details to set the IDE and a list of steps to perform this task in a structured way.

Steps to Add Tooltip in PDF in Java

  1. Set the IDE to use Aspose.PDF for Java to add a tooltip
  2. Create or load an existing PDF file and create a page in it if required
  3. Define a rectangular area where the tooltip will be displayed on the page
  4. Create a TextBoxField and set its properties, including AlternateName as the tooltip text
  5. Customize the style of the form field by setting its border parameters and appearance
  6. Add the TextBoxField control with a tooltip to the PDF form
  7. Save the resultant output PDF file

The above steps describe the process to work with the Adobe Acrobat tooltip in Java. Create a new PDF file, add a page to it, create a rectangular area for displaying the tooltip, create a TextBoxField object, and set its properties. Use the setAlternateName() method to set the tooltip text, set the control’s border properties and appearance, and finally add this control to the PDF.

Code to Add PDF Mouseover Popup Text in Java

This code demonstrates the process for adding PDF tooltip. You may use any other form control for exercising the tooltip by using the alternate name property. Annotations in the PDF also support popup text as tooltip by using different properties such as contents, title, or subject.

This article has taught us how to work with tooltips in a PDF. To remove the highlights in a PDF, refer to the article Remove highlight from PDF using Java.