fix: position of rectangle, add test

This commit is contained in:
Clarissa.Dietrich 2021-04-22 15:20:52 +02:00
parent d0cbb5293a
commit 3052b82842
3 changed files with 3 additions and 9 deletions

View File

@ -216,7 +216,7 @@ public class PdfSegmentationService {
// set Image, Position and type for merged Image
//set position for merged image with values of image1 and the height of both
Rectangle2D pos = new Rectangle2D.Float();
pos.setRect(image1.getPosition().getX(), image1.getPosition().getY(), width,height1+height2);
pos.setRect(image1.getPosition().getX(), image2.getPosition().getY(), width,height1+height2);
newPdfImage = new PdfImage(mergedImage,pos,0);
// Graphics need to be disposed
newPdfImage.getImage().flush();

View File

@ -121,14 +121,6 @@ public class SectionsBuilderService {
paragraphMap.computeIfAbsent(1, x -> new TreeSet<>()).add(paragraph);
}
// first page is always a paragraph, else we can't process pages 1..N,
// where N is the first found page with a paragraph
if (paragraphMap.get(1) == null) {
Paragraph paragraph = new Paragraph();
document.getParagraphs().add(paragraph);
paragraphMap.computeIfAbsent(1, x -> new TreeSet<>()).add(paragraph);
}
for (Page page : document.getPages()) {
for (PdfImage image : page.getImages()) {
SortedSet<Paragraph> paragraphsOnPage = paragraphMap.get(page.getPageNumber());

View File

@ -74,6 +74,8 @@ public class PdfSegmentationServiceTest {
ClassPathResource pdfFileResource = new ClassPathResource("files/Minimal Examples/270Rotated.pdf");
Document document = pdfSegmentationService.parseDocument(pdfFileResource.getInputStream());
assertThat(document.getPages().get(0).getImages().size()).isEqualTo(1);
assertThat(document.getPages().get(1).getImages().size()).isEqualTo(0);
}
@Test