Example usage for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotation setAnnotationName

List of usage examples for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotation setAnnotationName

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotation setAnnotationName.

Prototype

public void setAnnotationName(String nm) 

Source Link

Document

This will set the name, a string intended to uniquely identify each annotation within a page.

Usage

From source file:airviewer.AbstractDocumentCommandWrapper.java

License:Apache License

/**
 * This method finds the "last" (upper most) annotation that contains the
 * specified x and y coordinates and adds the annotation to
 * selectedAnnotations if it is not already in selectedAnnotations. As a
 * side effect, this method adds unique annotation names to any selected
 * annotation that does not already have a name. At all times, every
 * selected annotation must have a name - subclasses may rely on this
 * property./*from   www. j  av a  2  s  .  com*/
 *
 * @param pageIndex Must be pageIndex >= 0 && pageIndex < getPageCount()
 * @param x An X coordinate in the PDF coordinate system
 * @param y A Y coordinate in the PDF coordinate system
 */
public void extendSelectionOnPageAtPoint(int pageIndex, float x, float y) {
    assert 0 <= pageIndex && pageIndex < getPageCount();

    PDAnnotation candidate = getLastAnnotationOnPageAtPoint(pageIndex, x, y);
    if (null != candidate && !selectedAnnotations.contains(candidate)) {
        if (null == candidate.getAnnotationName()) {
            // Other programs neglect to provide a name, so provide one 
            // to uniquely identify selectde annotations.
            candidate.setAnnotationName(new UID().toString());
        }

        getSelectedAnnotations().add(candidate);
        //System.out.println("Selected: " + selectedAnnotations.toString());

    }
}

From source file:airviewer.AIRViewerModel.java

License:Apache License

/**
 * Some PDF editors (and hand written files) produce unnamed annotations,
 * but the Model relies on annotations having unique names. Call this method
 * to ensure that all annotations on the specified page in wrappedDocument
 * have unique names regardless of the presence or absence of pre-existing
 * names.//from  w  w  w .j ava  2  s  .com
 *
 * @param pageIndex pageIndex >= 0 && pageIndex < numPages()
 * @return A list of uniquely named annotations.
 */
private List<PDAnnotation> getAllSanitizedAnnotationsOnPage(int pageIndex) {
    assert Integer.toString(pageIndex) != null;
    List<PDAnnotation> result = null;

    try {
        PDPage page = wrappedDocument.getPage(pageIndex);
        result = page.getAnnotations();
        for (PDAnnotation a : result) {
            // Other programs neglect to provide a name, so provide one
            // to uniquely identify selectde annotations.
            a.setAnnotationName(new UID().toString());

        }
    } catch (IOException ex) {
        Logger.getLogger(AbstractDocumentCommandWrapper.class.getName()).log(Level.SEVERE, null, ex);
    }

    return result;
}