Automated Annotation Creation

Table of Contents

Automated Annotation Creation

ICEpdf Viewer RI allows users to create link annotations using a visual editor. The editor allows for quick edits and simple annotation additions but becomes tedious when working with large document sets. ICEpdf's Core API provides a mechanism which enables WordText objects returned from a document search to be converted to Link Annotations.

The Annotation Example contains two approaches for converting search results into Link Annotations. The following code snippet show how search results are iterated over to create Link annotations.

for (WordText wordText : foundWords) {
    // create a new link annotation
    LinkAnnotation linkAnnotation = (LinkAnnotation)
            AnnotationFactory.buildAnnotation(
                    document.getPageTree().getLibrary(),
                    AnnotationFactory.LINK_ANNOTATION,
                    wordText.getBounds().getBounds(),
                    annotationState);
    // create a new URI action
    org.icepdf.core.pobjects.actions.Action action =
            createURIAction(document.getPageTree().getLibrary(),
                    "http://www.icepdf.org");
    // add the action to the annotation
    linkAnnotation.addAction(action);
    // add it to the page.
    page.addAnnotation(linkAnnotation);
}

The source-code for the example is located at install_dir/icepdf/examples/annotation/NewAnnotationPostPageLoad.java.

The source-code for the example is located at install_dir/icepdf/examples/annotation/NewAnnotationPrePageLoad.java.

Creating A Single Annotation Over Multiple Terms

Search results can also be in the form of List<LineText> which is handy when trying to create single annotation over multiple WordText objects. The method searchController.searchHighlightPage(int, int):List<LineText> returns a line of text with an optional padding of words that are on either side of the search terms in context of the document content. When the padding is set to a value of zero the LineText list contains child WordText objects that represent the search terms. When a call to lineText.getBounds() is called the bounding box represent the union of all terms.

The following code snippet shows how annotation can be create around mutliple search terms.

// get the search results for this page
foundTerm = searchController.searchHighlightPage(pageIndex, 0);
if (foundTerm != null) {
    // get the current page lock and start adding the annotations
    AbstractPageViewComponent pageViewComponent =
            pageComponents.get(pageIndex);
    for (LineText lineText : foundTerm) {

        // create a  new link annotation
        LinkAnnotation linkAnnotation = (LinkAnnotation)
                AnnotationFactory.buildAnnotation(
                        document.getPageTree().getLibrary(),
                        Annotation.SUBTYPE_LINK,
                        lineText.getBounds().getBounds());
        // create a new URI action
        org.icepdf.core.pobjects.actions.Action action =
                createURIAction(document.getPageTree().getLibrary(),
                        "http://www.icepdf.org");
        // add the action to the annotation
        linkAnnotation.addAction(action);
        
        // create a component to wrap the annotation 
        AnnotationComponent annotationComponent =
                AnnotationComponentFactory.buildAnnotationComponent(
                        linkAnnotation,
                        controller.getDocumentViewController(),
                        pageViewComponent,
                        controller.getDocumentViewController().getDocumentViewModel());
        
        // add it to the pageComponent, not the page, as we won't
        // see it until the page is re-initialized.
        pageViewComponent.addAnnotation(annotationComponent);
    }
}
// removed the search highlighting
searchController.clearSearchHighlight(pageIndex
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.