Adding Comments to PDFs on iOS

Nutrient iOS SDK provides a user interface (UI) for viewing, adding, and deleting comments in PDF documents. The component, Instant Comments, is available only if you use Nutrient Instant.

Comments enable collaborative workflows where multiple users can discuss specific sections of a PDF document without leaving the viewer. Nutrient Instant enables users to receive updates in real time.

Licensing

Comments require a separate component in your Nutrient license. Without this included in your license, you won’t be able to add the functionality of viewing, searching, or adding comments in your application. Contact our Sales team to add comments to your license.

If you’re a new customer, you can try comments without a license key. If you’re an existing customer, ask our Sales team for a trial license if you’re interested.

Terminology

Before starting, here are a few key terms related to comments:

  • Root annotation — The annotation to which all the comments in a single thread are linked.

  • Comment thread — A group of comments associated with the same root annotation.

  • Comment — A single comment added by a user.

Root annotation types

All comments are linked to their respective root annotations. The comments with the same root annotation are part of a single comment thread. There can be two types of root annotations:

  • TextMarkupAnnotation — You can start a new comment thread by selecting some text and tapping the (comment icon) comment menu item. In this case, the text markup annotation created will act as a root annotation.

  • InstantCommentMarkerAnnotation — A comment marker annotation is a new annotation that can be added anywhere in a PDF document and used to start comment threads.

Getting started

The Nutrient Instant Comments tool is disabled by default. If your Document Engine license includes it, add the .instantCommentMarker annotation type to the editableAnnotationTypes of the PDFConfiguration instance you’re using:

let instantController = InstantViewController(document: pdfDocument, configuration: InstantViewController.defaultConfiguration.configurationUpdated {
    // Add `.instantCommentMarker` to the `editableAnnotationTypes` to enable editing of Instant Comments.
    $0.editableAnnotationTypes?.insert(.instantCommentMarker)
})
PSPDFInstantViewController *instantVC = [[PSPDFInstantViewController alloc] initWithDocument:document configuration:[PSPDFInstantViewController.defaultConfiguration configurationUpdatedWithBuilder:^(PSPDFConfigurationBuilder *builder) {
    // Add `PSPDFAnnotationStringInstantCommentMarker` to the `editableAnnotationTypes` to enable editing of Instant Comments.
    NSMutableSet *editableAnnotationTypes = [builder.editableAnnotationTypes mutableCopy];
    [editableAnnotationTypes addObject:PSPDFAnnotationStringInstantCommentMarker];
    builder.editableAnnotationTypes = editableAnnotationTypes;
}]];

Additionally, we don’t show the comment tool (comment icon) in the annotation toolbar by default. This is because we want you to think about the workflow you want for your users and then decide whether or not you want to add it in the annotation toolbar. For example, if you want to enable the creation of comments from the annotation toolbar and disable note annotations, you can add a custom button item to the annotation toolbar and remove the note button item. For more information, refer to the customizing the annotation toolbar guide and custom annotation toolbar subclass from our ConstructionExample.swift.

Adding a comment

You can add comments in two ways, depending on the type of root annotation.

Annotation creation menu

This method involves the creation of InstantCommentMarkerAnnotation before the creation of comments. To add a comment marker annotation, long press at the location on the page where you want to place the comment to invoke the page’s long-press menu. Once the long-press menu appears, tap the (comment icon) comment option to add the comment marker annotation.

comment-long-press-menu

Using text markup annotations

To add a comment linked to a text in the document, select the text, and tap the (comment icon) comment option from the menu. This opens a comment editor where you can add your first comment and start the new thread.

comment-markup-menu

At the moment, we don’t support the addition of comments or comment marker annotations using programmatic APIs. This is something that might change in the future.

Deleting a comment

You can delete an individual comment by invoking the menu for the comment and tapping the Delete Comment option. If all the comments of a thread are deleted, the corresponding root annotation is automatically deleted.

Document Engine currently doesn’t expose any APIs for deleting a comment.

Information

Comment editing isn’t supported in the current version.

Disabling new comment thread creation

By default, creating new comment threads is disabled in Nutrient Instant. The .instantCommentMarker annotation type isn’t included in the default value of editableAnnotationTypes. Hence, no additional steps are required to disable the creation of new comment threads.