diff --git a/iparapheur-core/src/main/java/coop/libriciel/utils/poppler/PopplerUtils.java b/iparapheur-core/src/main/java/coop/libriciel/utils/poppler/PopplerUtils.java index a6f0b758a228ee60e4b8c53f7a5c4f180aae5540..06bae2c9784e8b3cc730fea8908cde071020558f 100644 --- a/iparapheur-core/src/main/java/coop/libriciel/utils/poppler/PopplerUtils.java +++ b/iparapheur-core/src/main/java/coop/libriciel/utils/poppler/PopplerUtils.java @@ -90,37 +90,34 @@ public class PopplerUtils { } public TagSearchResult getTextLocation(String path, String toFind) { - int count = getPageCount(path); - - for (int i = 0; i < count; i++) { - TagSearchResult tagSearchResult = new TagSearchResult(); - PopplerCallResult result = doCall( - CommandType.LOCATE.value(), toFind, - CommandType.PAGE.value(), String.valueOf(i), - CommandType.FILE.value(), path - ); - if (result.resultCode == 0) { - // Top, Right, Bottom, Left - String[] rectData = result.output.split(","); - if (rectData.length != 4) { - log.error(result.output); - log.error(result.error); - return null; - } - Rectangle rectangle = new Rectangle(); - rectangle.width = Math.abs(Math.round(Float.parseFloat(rectData[1].trim()) - Float.parseFloat(rectData[3].trim()))); - rectangle.height = Math.round(Float.parseFloat(rectData[0].trim()) - Float.parseFloat(rectData[2].trim())); - rectangle.x = Math.round(Float.parseFloat(rectData[3].trim())); - rectangle.y = Math.round(Float.parseFloat(rectData[2].trim()) - Math.abs(rectangle.height)); - tagSearchResult.page = i + 1; - tagSearchResult.rectangle = rectangle; - return tagSearchResult; - } else { - if (!result.error.isEmpty()) { - log.error(result.error); - } + TagSearchResult tagSearchResult = new TagSearchResult(); + PopplerCallResult result = doCall( + CommandType.LOCATE.value(), toFind, + CommandType.FILE.value(), path + ); + + if (result.resultCode == 0) { + // Top, Right, Bottom, Left + String[] rectData = result.output.split(","); + if (rectData.length != 5) { + log.error(result.output); + log.error(result.error); + return null; + } + Rectangle rectangle = new Rectangle(); + rectangle.width = Math.abs(Math.round(Float.parseFloat(rectData[1].trim()) - Float.parseFloat(rectData[3].trim()))); + rectangle.height = Math.round(Float.parseFloat(rectData[0].trim()) - Float.parseFloat(rectData[2].trim())); + rectangle.x = Math.round(Float.parseFloat(rectData[3].trim())); + rectangle.y = Math.round(Float.parseFloat(rectData[2].trim()) - Math.abs(rectangle.height)); + tagSearchResult.page = Integer.parseInt(rectData[4].trim()) + 1; + tagSearchResult.rectangle = rectangle; + return tagSearchResult; + } else { + if (!result.error.isEmpty()) { + log.error(result.error); } } + return null; }