From 17de40a8200260defa2f4777a84df5361093f90f Mon Sep 17 00:00:00 2001 From: Alexander Dyuzhev Date: Thu, 31 Oct 2024 20:57:36 +0300 Subject: [PATCH] removing temp empty links, #293 --- .../metanorma/fop/annotations/Annotation.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/metanorma/fop/annotations/Annotation.java b/src/main/java/org/metanorma/fop/annotations/Annotation.java index c2d05f6..afb2d5a 100644 --- a/src/main/java/org/metanorma/fop/annotations/Annotation.java +++ b/src/main/java/org/metanorma/fop/annotations/Annotation.java @@ -299,6 +299,9 @@ public void process(File pdf, String xmlReview) throws IOException { HashMap hashMapDocumentAnnotations = new HashMap<>(); hashMapDocumentAnnotations = getAnnotationIDmap(document); + + clearEmptyAnnotations(document); + document.save(pdf); } catch (IOException | NumberFormatException | ParserConfigurationException | DOMException | TransformerException | SAXException | XPathException ex) { @@ -333,4 +336,18 @@ private HashMap getAnnotationIDmap(PDDocument document) thr return hashMapDocumentAnnotations; } + private void clearEmptyAnnotations(PDDocument document) throws IOException { + for (int i = 0; i < document.getNumberOfPages(); i++) + { + List pageAnnotations = new ArrayList<>(); + PDPage page = document.getPage(i); + for(PDAnnotation pageAnnotation: page.getAnnotations()) { + if(!(pageAnnotation.getContents().startsWith("Annot___"))) { + pageAnnotations.add(pageAnnotation); + } + } + document.getPage(i).setAnnotations(pageAnnotations); + } + } + }