Skip to content

Commit 48ffb06

Browse files
committed
add brew to jna path
1 parent aca504a commit 48ffb06

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

jablib/src/main/java/org/jabref/logic/ocr/OcrService.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package org.jabref.logic.ocr;
22

3+
import java.io.File;
4+
import java.nio.file.Path;
5+
6+
import org.jabref.model.strings.StringUtil;
7+
8+
import com.sun.jna.Platform;
39
import net.sourceforge.tess4j.Tesseract;
410
import net.sourceforge.tess4j.TesseractException;
5-
import org.jabref.model.strings.StringUtil; // JabRef utility class
611
import org.slf4j.Logger;
712
import org.slf4j.LoggerFactory;
813

9-
import java.io.File;
10-
import java.nio.file.Path;
11-
1214
/**
1315
* Service for performing Optical Character Recognition (OCR) on PDF files.
1416
* This class provides a high-level interface to OCR functionality,
1517
* abstracting away the specific OCR engine implementation details.
1618
*/
1719
public class OcrService {
1820
private static final Logger LOGGER = LoggerFactory.getLogger(OcrService.class);
19-
21+
private static final String JNA_LIBRARY_PATH = "jna.library.path";
2022
// The OCR engine instance
2123
private final Tesseract tesseract;
2224

@@ -25,6 +27,13 @@ public class OcrService {
2527
* Currently uses Tesseract with English language support.
2628
*/
2729
public OcrService() {
30+
if (Platform.isMac()) {
31+
if (Platform.isARM()) {
32+
System.setProperty(JNA_LIBRARY_PATH, JNA_LIBRARY_PATH + File.pathSeparator + "/opt/homebrew/lib/");
33+
} else {
34+
System.setProperty(JNA_LIBRARY_PATH, JNA_LIBRARY_PATH + File.pathSeparator + "/usr/local/cellar/");
35+
}
36+
}
2837
this.tesseract = new Tesseract();
2938

3039
// Configure Tesseract
@@ -66,8 +75,8 @@ public String performOcr(Path pdfPath) throws OcrException {
6675

6776
LOGGER.info("OCR completed successfully. Extracted {} characters", result.length());
6877
return result;
69-
70-
} catch (TesseractException e) {
78+
} catch (
79+
TesseractException e) {
7180
LOGGER.error("OCR failed for file: {}", pdfFile.getName(), e);
7281
throw new OcrException(
7382
"Failed to perform OCR on file: " + pdfFile.getName() +

0 commit comments

Comments
 (0)