diff --git a/src/main/java/org/metanorma/fop/annotations/Annotation.java b/src/main/java/org/metanorma/fop/annotations/Annotation.java index f2114a4..c2d05f6 100644 --- a/src/main/java/org/metanorma/fop/annotations/Annotation.java +++ b/src/main/java/org/metanorma/fop/annotations/Annotation.java @@ -295,7 +295,10 @@ public void process(File pdf, String xmlReview) throws IOException { } fdfDoc.close(); - + + HashMap hashMapDocumentAnnotations = new HashMap<>(); + hashMapDocumentAnnotations = getAnnotationIDmap(document); + document.save(pdf); } catch (IOException | NumberFormatException | ParserConfigurationException | DOMException | TransformerException | SAXException | XPathException ex) { @@ -311,5 +314,23 @@ public void process(File pdf, String xmlReview) throws IOException { } } - + + private HashMap getAnnotationIDmap(PDDocument document) throws IOException { + HashMap 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; + } + }