Fixed multiline annotations

This commit is contained in:
deiflaender 2020-10-01 15:04:51 +02:00
parent ecdfd29803
commit 247e57208a

View File

@ -227,7 +227,7 @@ public class AnnotationHighlightService {
PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
annotation.constructAppearances();
annotation.setRectangle(toPDRectangle(rectangles.get(0)));
annotation.setRectangle(toPDRectangle(rectangles));
annotation.setQuadPoints(toQuadPoints(rectangles));
if (popup) {
annotation.setAnnotationName(id);
@ -252,13 +252,34 @@ public class AnnotationHighlightService {
}
private PDRectangle toPDRectangle(Rectangle rectangle) {
private PDRectangle toPDRectangle(List<Rectangle> rectangles) {
float x1 = Float.MAX_VALUE;
float x2 = 0;
float y1 = 0;
float y2 = Float.MAX_VALUE;
for(Rectangle rectangle : rectangles){
if (rectangle.getTopLeft().getX() < x1){
x1 = rectangle.getTopLeft().getX();
}
if(rectangle.getTopLeft().getX() + rectangle.getWidth() > x2){
x2 = rectangle.getTopLeft().getX() + rectangle.getWidth();
}
if(rectangle.getTopLeft().getY() + rectangle.getHeight() > y1){
y1 = rectangle.getTopLeft().getY() + rectangle.getHeight();
}
if(rectangle.getTopLeft().getY() < y2){
y2 = rectangle.getTopLeft().getY();
}
}
PDRectangle annotationPosition = new PDRectangle();
annotationPosition.setLowerLeftX(rectangle.getTopLeft().getX());
annotationPosition.setLowerLeftY(rectangle.getTopLeft().getY() + rectangle.getHeight());
annotationPosition.setUpperRightX(rectangle.getTopLeft().getX() + rectangle.getWidth());
annotationPosition.setUpperRightY(rectangle.getTopLeft().getY());
annotationPosition.setLowerLeftX(x1);
annotationPosition.setLowerLeftY(y1);
annotationPosition.setUpperRightX(x2);
annotationPosition.setUpperRightY(y2);
return annotationPosition;
}