RED-7607 - Rotating pages leads to lost annotations (RM & DM)
- fix PMD findings
This commit is contained in:
parent
b8ef55e6e2
commit
f2c0991987
@ -9,6 +9,7 @@ import org.apache.pdfbox.text.TextPosition;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -22,7 +23,7 @@ public class MarkedContentUtils {
|
||||
public List<Rectangle2D> getMarkedContentBboxPerLine(List<PDMarkedContent> markedContents, String subtype) {
|
||||
|
||||
if (markedContents == null) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
var markedContentByYPosition = markedContents.stream()
|
||||
@ -37,7 +38,7 @@ public class MarkedContentUtils {
|
||||
.collect(Collectors.groupingBy(TextPosition::getY));
|
||||
|
||||
if (markedContentByYPosition.isEmpty()) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return markedContentByYPosition.values().stream()
|
||||
|
||||
@ -53,7 +53,9 @@ public class ExtractMarkedContentTest {
|
||||
@SneakyThrows
|
||||
public void testExtractTestWPhromma() throws IOException {
|
||||
System.out.printf("\n\n===\n%s\n===\n", "testWPhromma.pdf");
|
||||
PDDocument document = Loader.loadPDF(new ClassPathResource("files/bdr/Drucksache_19_9865.pdf").getFile());
|
||||
PDDocument document = null;
|
||||
try {
|
||||
document = Loader.loadPDF(new ClassPathResource("files/bdr/Drucksache_19_9865.pdf").getFile());
|
||||
|
||||
Map<PDPage, Map<Integer, PDMarkedContent>> markedContents = new HashMap<>();
|
||||
|
||||
@ -70,6 +72,10 @@ public class ExtractMarkedContentTest {
|
||||
|
||||
PDStructureNode root = document.getDocumentCatalog().getStructureTreeRoot();
|
||||
showStructure(root, markedContents);
|
||||
} finally {
|
||||
if (null != document )
|
||||
document.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +93,10 @@ public class ExtractMarkedContentTest {
|
||||
@Test
|
||||
public void testExtractResMultipage() throws IOException {
|
||||
System.out.printf("\n\n===\n%s\n===\n", "res_multipage.pdf");
|
||||
PDDocument document = Loader.loadPDF(new ClassPathResource("files/bdr/Drucksache_19_9865.pdf").getFile());
|
||||
|
||||
PDDocument document = null;
|
||||
try {
|
||||
document = Loader.loadPDF(new ClassPathResource("files/bdr/Drucksache_19_9865.pdf").getFile());
|
||||
|
||||
Map<PDPage, Map<Integer, PDMarkedContent>> markedContents = new HashMap<>();
|
||||
|
||||
@ -104,6 +113,10 @@ public class ExtractMarkedContentTest {
|
||||
|
||||
PDStructureNode root = document.getDocumentCatalog().getStructureTreeRoot();
|
||||
showStructure(root, markedContents);
|
||||
} finally {
|
||||
if (document != null)
|
||||
document.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +134,9 @@ public class ExtractMarkedContentTest {
|
||||
@Test
|
||||
public void testExtractDailyReport() throws IOException {
|
||||
System.out.printf("\n\n===\n%s\n===\n", "Daily Report.pdf");
|
||||
PDDocument document = Loader.loadPDF(new ClassPathResource("files/bdr/Drucksache_19_9865.pdf").getFile());
|
||||
PDDocument document = null;
|
||||
try {
|
||||
document = Loader.loadPDF(new ClassPathResource("files/bdr/Drucksache_19_9865.pdf").getFile());
|
||||
|
||||
Map<PDPage, Map<Integer, PDMarkedContent>> markedContents = new HashMap<>();
|
||||
|
||||
@ -138,7 +153,11 @@ public class ExtractMarkedContentTest {
|
||||
|
||||
PDStructureNode root = document.getDocumentCatalog().getStructureTreeRoot();
|
||||
showStructure(root, markedContents);
|
||||
} finally {
|
||||
if (null != document)
|
||||
document.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #testExtractTestWPhromma()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user