Skip to content

Commit

Permalink
added hashmap for id and annotations, #293
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Oct 31, 2024
1 parent c0c7f21 commit b1e32c1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/main/java/org/metanorma/fop/annotations/Annotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ public void process(File pdf, String xmlReview) throws IOException {
}

fdfDoc.close();


HashMap<String,PDAnnotation> hashMapDocumentAnnotations = new HashMap<>();
hashMapDocumentAnnotations = getAnnotationIDmap(document);

document.save(pdf);

} catch (IOException | NumberFormatException | ParserConfigurationException | DOMException | TransformerException | SAXException | XPathException ex) {
Expand All @@ -311,5 +314,23 @@ public void process(File pdf, String xmlReview) throws IOException {
}

}


private HashMap<String,PDAnnotation> getAnnotationIDmap(PDDocument document) throws IOException {
HashMap<String,PDAnnotation> hashMapDocumentAnnotations = new HashMap<>();
for(int i = 0; i< document.getNumberOfPages(); i++) {
PDPage page = document.getPage(i);
for (PDAnnotation pdAnnotation: page.getAnnotations()){
COSDictionary pdAnnotationDict = pdAnnotation.getCOSObject();
if (pdAnnotationDict != null) {
// subject contains id 'Annot___', see xfdf_simple.xsl, attribute 'subject'
String subj = pdAnnotationDict.getString(COSName.SUBJ);
if (subj != null) {
hashMapDocumentAnnotations.put(subj, pdAnnotation);
}
}
}
}
return hashMapDocumentAnnotations;
}

}

0 comments on commit b1e32c1

Please sign in to comment.