Add dropdown component

On this page

Dropdown component creates a combo box as shown in the picture below:

You can specify the following properties of the DropdownComponent class:

  • Box defines the annotation position
  • PenColor defines the frame color
  • PenStyle defines the frame line style (solid, dash, dot etc.)
  • PenWidth defines the frame line width in pixels.

To add a dropdown component, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the DropdownComponent class. Specify the appropriate properties (position, page number, etc).
  3. Call the Add method. Specify the DropdownComponent class.
  4. Call the Save method. Specify the output document path or stream.

The following code snippet shows how to add DropdownComponent to the document:

try(final Annotator annotator = new Annotator(Constants.INPUT_PDF)) {
	DropdownComponent dropdownComponent = new DropdownComponent();
	dropdownComponent.setOptions(new ArrayList<>(Arrays.asList("Item1", "Item2", "Item3")));
	dropdownComponent.setSelectedOption(null);
	dropdownComponent.setPlaceholder("Choose option");
	dropdownComponent.setBox(new Rectangle(100, 100, 100, 100));
	dropdownComponent.setCreatedOn(new Date());
	dropdownComponent.setMessage("This is dropdown component");
	dropdownComponent.setPageNumber(0);
	dropdownComponent.setPenColor(65535);
	dropdownComponent.setPenStyle(PenStyle.DOT);
	dropdownComponent.setPenWidth((byte) 3);

	List<Reply> replies = new ArrayList<>();
	Reply reply1 = new Reply();
	reply1.setComment("First comment");
	reply1.setRepliedOn(new Date());

	Reply reply2 = new Reply();
	reply2.setComment("Second comment");
	reply2.setRepliedOn(new Date());

	replies.add(reply1);
	replies.add(reply2);

	dropdownComponent.setReplies(replies);
	annotator.add(dropdownComponent);
	annotator.save("result_dropdown_component.pdf");
}

On this page