How to Add Special Annotations for PDF using Java

Special annotations for PDF documents only

We think it’s no secret that the PDF format is the most popular format among text documents. Many people prefer to use it because they know that the style and formatting of the document is maintained regardless of the computer or application with which the PDF is viewed. Given its popularity, our Java API has been improved. We have created annotations unique to the PDF format, the so-called Components. As you know, our Java API supports a large number of annotations that can be applied to different documents - Word documents, Excel sheets, Visio diagrams, PDF etc. But Component support PDF only!

This article will talk about the components that are already implemented in the Annotation Java API and how you can use them.

Button component

Button component allows to create button component like shown at the picture below:

There is an ability to specify the next properties for ButtonComponent type:

  • Box - defines annotation position at document page;
  • PenColor - defines frame color;

Follow these steps to add Button component to document:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate ButtonComponent object with desired properties (position, page number, etc);
  • Call Add method and pass ButtonComponent object;
  • Call Save method with resultant document path or stream.

The following code demonstrates how to add ButtonComponent to the document:

Checkbox component

Checkbox component allows to create checkbox component like shown at the picture below:

There is an ability to specify the next properties for CheckBoxComponent type:

  • Box - defines annotation position at document page;
  • PenColor - defines frame color;

Follow these steps to add Checkbox component to document:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate CheckboxComponent object with desired properties (position, page number, etc);
  • Call Add method and pass CheckboxComponent object;
  • Call Save method with resultant document path or stream.

The following code demonstrates how to add CheckboxComponent to the document:

Dropdown component allows to create combo box with specified options like shown at the picture below:

There is an ability to specify the next properties for DropdownComponent type:

  • Box - defines annotation position at document page;
  • PenColor - defines frame color;
  • PenStyle - defines frame line style (solid, dash, dot etc.);
  • PenWidth - defines frame line width in pixels.

Follow these steps to add Dropdown component to document:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate DropdownComponent object with desired properties (position, page number, etc);
  • Call Add method and pass DropdownComponent object;
  • Call Save method with resultant document path or stream.

The following code demonstrates how to add DropdownComponent to the document:

Conclusion

In this article we have told you about components that are unique to pdf. We showed you how to add a button, a checkbox and a drop-down list. Now, you should be confident to build your own document annotator using our Java application API.

More resources

Advanced Usage Topics

To learn more about document annotating features, please refer to the advanced usage section.

Free Online App

Along with full-featured Java library we provide simple but powerful free Apps. You are welcome to annotate your PDF, DOC or DOCX, XLS or XLSX, PPT or PPTX, PNG and other documents with free to use online GroupDocs Annotation App.