class AnnotationsDistiller {

    public LookupTable<PDAnnotation> retainRelevantAnnotations(LookupTable<PDPage> relevantPages) {
        LOG.debug("Filtering annotations");
        for (PDPage page : relevantPages.keys()) {
            try {
                Set<PDAnnotation> keptAnnotations = new LinkedHashSet<>();
                for (PDAnnotation annotation : page.getAnnotations()) {
                    PDAnnotation mapped = annotationsLookup.lookup(annotation);
                    if (nonNull(mapped)) {
                        keptAnnotations.add(mapped);
                    } else {
                        if (annotation instanceof PDAnnotationLink) {
                            processLinkAnnotation(relevantPages, keptAnnotations, (PDAnnotationLink) annotation);
                        } else {
                            processNonLinkAnnotation(relevantPages, keptAnnotations, annotation);
                        }
                    }
                }
                relevantPages.lookup(page).setAnnotations(new ArrayList<>(keptAnnotations));
            } catch (IOException e) {
                LOG.warn("Failed to process annotations for page", e);
            }
        }
        return annotationsLookup;
    }

    public  AnnotationsDistiller(PDDocument document);

}