diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java index 39e52c79..8b123983 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java @@ -159,7 +159,7 @@ public class AnnotationHighlightService { redactionLogEntry.getPositions().addAll(rectanglesPerLine); - annotations.addAll(createAnnotation(rectanglesPerLine, entityPositionSequence.getId(), createAnnotationContent(entity), getColor(entity, ruleSetId, requestedToRemove), comments, !isHint(entity, ruleSetId))); + annotations.addAll(createAnnotation(rectanglesPerLine, entityPositionSequence.getId(), createAnnotationContent(entity), getColor(entity, ruleSetId, requestedToRemove), comments, !isHint(entity, ruleSetId), pdPage.getMediaBox(), pdPage.getCropBox())); } redactionLogEntry.setId(entityPositionSequence.getId()); @@ -225,7 +225,7 @@ public class AnnotationHighlightService { if (!rectanglesOnPage.isEmpty() && !approvedAndShouldBeInDictionary(manualRedactionEntry)) { annotations.addAll(createAnnotation(rectanglesOnPage, id, createAnnotationContent(manualRedactionEntry), getColorForManualAdd(manualRedactionEntry - .getType(), ruleSetId, manualRedactionEntry.getStatus()), manualRedactions.getComments().get(id), true)); + .getType(), ruleSetId, manualRedactionEntry.getStatus()), manualRedactions.getComments().get(id), true, pdPage.getMediaBox(), pdPage.getCropBox())); classifiedDoc.getRedactionLogEntities().add(redactionLogEntry); } } @@ -281,15 +281,15 @@ public class AnnotationHighlightService { private List createAnnotation(List rectangles, String id, String content, float[] color, - List comments, boolean popup) { + List comments, boolean popup, PDRectangle mediaBox, PDRectangle cropBox) { List annotations = new ArrayList<>(); PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT); annotation.constructAppearances(); - PDRectangle pdRectangle = toPDRectangle(rectangles); + PDRectangle pdRectangle = toPDRectangle(rectangles, mediaBox, cropBox); annotation.setRectangle(pdRectangle); - annotation.setQuadPoints(toQuadPoints(rectangles)); + annotation.setQuadPoints(toQuadPoints(rectangles, mediaBox, cropBox)); if (popup) { annotation.setContents(content); } @@ -329,7 +329,7 @@ public class AnnotationHighlightService { } - private PDRectangle toPDRectangle(List rectangles) { + private PDRectangle toPDRectangle(List rectangles, PDRectangle mediaBox, PDRectangle cropBox) { float lowerLeftX = Float.MAX_VALUE; float upperRightX = 0; @@ -351,22 +351,27 @@ public class AnnotationHighlightService { } } + var x1 = lowerLeftX + cropBox.getLowerLeftX() - mediaBox.getLowerLeftY(); + var y1 = lowerLeftY + (mediaBox.getLowerLeftY() - cropBox.getLowerLeftY()); + var x2 = upperRightX + cropBox.getLowerLeftX() - mediaBox.getLowerLeftY(); + var y2 = upperRightY - (mediaBox.getLowerLeftY() - cropBox.getLowerLeftY()); + PDRectangle annotationPosition = new PDRectangle(); - annotationPosition.setLowerLeftX(lowerLeftX); - annotationPosition.setLowerLeftY(lowerLeftY); - annotationPosition.setUpperRightX(upperRightX); - annotationPosition.setUpperRightY(upperRightY); + annotationPosition.setLowerLeftX(x1); + annotationPosition.setLowerLeftY(y1); + annotationPosition.setUpperRightX(x2); + annotationPosition.setUpperRightY(y2); return annotationPosition; } - private float[] toQuadPoints(List rectangles) { + private float[] toQuadPoints(List rectangles,PDRectangle mediaBox, PDRectangle cropBox) { float[] quadPoints = new float[rectangles.size() * 8]; int i = 0; for (Rectangle rectangle : rectangles) { - float[] quadPoint = toQuadPoint(rectangle); + float[] quadPoint = toQuadPoint(rectangle, mediaBox, cropBox); for (int j = 0; j <= 7; j++) { quadPoints[i + j] = quadPoint[j]; } @@ -376,14 +381,26 @@ public class AnnotationHighlightService { } - private float[] toQuadPoint(Rectangle rectangle) { + private float[] toQuadPoint(Rectangle rectangle, PDRectangle mediaBox, PDRectangle cropBox) { + + var x1 = rectangle.getTopLeft().getX() + cropBox.getLowerLeftX() - mediaBox.getLowerLeftY(); + var y1 = rectangle.getTopLeft().getY() + (mediaBox.getLowerLeftY() - cropBox.getLowerLeftY()); + var x2 = rectangle.getTopLeft().getX() + rectangle.getWidth() + cropBox.getLowerLeftX() - mediaBox.getLowerLeftY(); + var y2 = rectangle.getTopLeft().getY() + rectangle.getHeight() - (mediaBox.getLowerLeftY() - cropBox.getLowerLeftY()); + // quadPoints is array of x,y coordinates in Z-like order (top-left, top-right, bottom-left,bottom-right) // of the area to be highlighted - return new float[]{rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), rectangle.getTopLeft() - .getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(), rectangle.getTopLeft() - .getY() + rectangle.getHeight(), rectangle.getTopLeft() - .getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()}; + return new float[]{ + x1, + y1, + x2, + y2, + x1, + y2 - rectangle.getHeight(), + x2, + y1 - rectangle.getHeight() + }; } diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java index bdb781a1..3624d7d6 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java @@ -423,7 +423,7 @@ public class RedactionIntegrationTest { System.out.println("redactionTest"); long start = System.currentTimeMillis(); - ClassPathResource pdfFileResource = new ClassPathResource("files/Metolachlor/S-Metolachlor_RAR_02_Volume_2_2018-09-06.pdf"); + ClassPathResource pdfFileResource = new ClassPathResource("files/new/Lambda-cyhalothrin - Toxicokinetics - Rat - Spain - 2006.pdf"); RedactionRequest request = RedactionRequest.builder() .ruleSetId(TEST_RULESET_ID) diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/files/new/Lambda-cyhalothrin - Toxicokinetics - Rat - Spain - 2006.pdf b/redaction-service-v1/redaction-service-server-v1/src/test/resources/files/new/Lambda-cyhalothrin - Toxicokinetics - Rat - Spain - 2006.pdf new file mode 100644 index 00000000..89cb018c Binary files /dev/null and b/redaction-service-v1/redaction-service-server-v1/src/test/resources/files/new/Lambda-cyhalothrin - Toxicokinetics - Rat - Spain - 2006.pdf differ