Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a51e3b0
Initial implementation using tess4j
Kaan0029 Jun 12, 2025
aca504a
merge
Siedlerchr Jun 12, 2025
48ffb06
add brew to jna path
Siedlerchr Jun 12, 2025
5a256ae
Adapted Exception handling and configured tessdata variable
Kaan0029 Jun 19, 2025
f80cec8
addressed mentor code feedback after 19.06.25
Kaan0029 Jul 3, 2025
db1f577
Merge branch 'upstream-main' into gsoc-ocr-tess4j-initial-implementation
Kaan0029 Jul 10, 2025
4020d3a
fix java modules
Siedlerchr Jul 10, 2025
4987978
fix tessdata path
Siedlerchr Jul 10, 2025
9842dd4
fix tessdata path amd module infor for lept4j
Siedlerchr Jul 10, 2025
8b133e6
fix tessdata path amd module infor for lept4j
Siedlerchr Jul 10, 2025
42704ea
fix module access
Siedlerchr Jul 10, 2025
a64e1ea
fix module access
Siedlerchr Jul 10, 2025
6069bc1
fix module access
Siedlerchr Jul 10, 2025
5734252
Avoid throwing exception in configureTessdata when tessdata is missing
Kaan0029 Jul 10, 2025
ab98a3a
Use Path.of instead of Paths.get for modern Java style
Kaan0029 Jul 10, 2025
62dce25
Add OCR tessdata path setting to AI preferences tab and add abstracti…
Kaan0029 Jul 10, 2025
0949300
Merge remote-tracking branch 'origin/gsoc-ocr-tess4j-initial-implemen…
Kaan0029 Jul 10, 2025
e4e45f3
fix(ocr): restore deleted files
InAnYan Jul 10, 2025
15272a6
fix(ocr): restore deleted IconThemes
InAnYan Jul 10, 2025
14332af
Update gradle to 9.1.0-jabref
koppor Jul 11, 2025
5488deb
fix(submodules): fix submodules
InAnYan Jul 11, 2025
26a8500
Update gradle
koppor Jul 11, 2025
e0da447
Merge branch 'gsoc-ocr-tess4j-initial-implementation' of https://gith…
koppor Jul 11, 2025
f1a06ac
Update gradle
koppor Jul 11, 2025
42d34ca
Workaround for gradle bug
calixtus Jul 12, 2025
3ffa1c1
Merge remote-tracking branch 'upstream/main' into gsoc-ocr-tess4j-ini…
calixtus Jul 12, 2025
59d87a2
Workaround for gradle bug
calixtus Jul 12, 2025
bc36a94
Fix submodules
calixtus Jul 12, 2025
e7a043d
Added Debugging Testing file for jna
Kaan0029 Jul 13, 2025
caa48f1
Attempt to enforce specific jna version
Kaan0029 Jul 13, 2025
9b51b23
Merge remote-tracking branch 'origin/gsoc-ocr-tess4j-initial-implemen…
Kaan0029 Jul 13, 2025
c115803
Fix jna include
calixtus Jul 13, 2025
f16c1f4
Add jna-jpms
koppor Jul 13, 2025
8c51016
fix arm64 crash
Kaan0029 Jul 15, 2025
5843c69
fix tessdata path issue
Kaan0029 Jul 15, 2025
1bd2e5b
revert previous tessdata change
Kaan0029 Jul 15, 2025
c7fcc6b
fixed lifecycle
Kaan0029 Jul 16, 2025
a8bab25
fixed bug related to life cylce issue
Kaan0029 Jul 16, 2025
9b9c7b7
Deleted unnecessary comments
Kaan0029 Jul 16, 2025
edc0343
use StringUtil.isBlank
Kaan0029 Jul 16, 2025
695e2b4
Use @NonNull
Kaan0029 Jul 16, 2025
e5e651e
Added TODO comment
Kaan0029 Jul 16, 2025
9ffdbff
delete /tessdata from .gitignore
Kaan0029 Jul 16, 2025
facb463
delete TO-DO comments in FilePreferences
Kaan0029 Jul 16, 2025
265a312
Delete unnecessary comment in OcrProvider
Kaan0029 Jul 16, 2025
e4d16c2
Adjust AI preferences and make them fit with jabref conventions
Kaan0029 Jul 17, 2025
cd52669
Merge remote-tracking branch 'upstream/main' into gsoc-ocr-tess4j-ini…
calixtus Jul 17, 2025
2eb2df2
Fix submodules
calixtus Jul 17, 2025
809e5a1
Remove error_log.txt
calixtus Jul 17, 2025
d0a20e7
Fix gradle issues
calixtus Jul 17, 2025
ce0328d
Resolve uncaught exception issue in JabRefGUI.stop()
Kaan0029 Jul 21, 2025
da6b8c8
fix tessdata path issue by removing getParent call
Kaan0029 Jul 21, 2025
a4e5d20
delete OcrException and return optional or result (OcrResult) instead
Kaan0029 Jul 21, 2025
af085b9
adjust commenting style to be in line with JabRef conventions
Kaan0029 Jul 21, 2025
dd8d211
implemented string constant for 'tessdata' as it it used more than once
Kaan0029 Jul 21, 2025
a3a90a8
separate final and non-final fields
Kaan0029 Jul 21, 2025
e7dba5e
store whole exception object instead of only exception message
Kaan0029 Jul 21, 2025
d13ea24
implement OcrBackgroundTask class
Kaan0029 Jul 21, 2025
14cf72d
add method for getting property in filepreferences
Kaan0029 Jul 21, 2025
c5b0860
Add initial implementation of embedded text layer using pdfbox
Kaan0029 Jul 24, 2025
66bfdd6
Initial implementation of ocrmypdf as alternative to pdfbox
Kaan0029 Jul 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions jablib/src/main/java/org/jabref/logic/ocr/TesseractOcrProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,40 +156,35 @@ private void configureTessdata() {
*/
private boolean setTessdataPath(String pathStr) {
try {
Path path = Path.of(pathStr);

// Resolve symbolic links to get the real path
Path realPath = path.toRealPath();
LOGGER.debug("Original path: {}, Real path: {}", path, realPath);

// Check if this is the tessdata directory itself
if (realPath.getFileName() != null && realPath.getFileName().toString().equals("tessdata")) {
Path engData = realPath.resolve("eng.traineddata");
LOGGER.debug("Checking for eng.traineddata at: {}", engData);
if (Files.exists(realPath) && Files.isDirectory(realPath) && Files.exists(engData)) {
// Tesseract expects the parent of tessdata
String parentPath = realPath.getParent().toString();
LOGGER.debug("Setting datapath to parent: {}", parentPath);
tesseract.setDatapath(parentPath);
return true;
}
} else {
// Check if this is the parent of tessdata
Path tessdata = realPath.resolve("tessdata");
Path engData = tessdata.resolve("eng.traineddata");
LOGGER.debug("Checking tessdata at: {} and eng.traineddata at: {}", tessdata, engData);
if (Files.exists(tessdata) && Files.isDirectory(tessdata) && Files.exists(engData)) {
LOGGER.debug("Setting datapath to: {}", realPath);
tesseract.setDatapath(realPath.toString());
Path path = Path.of(pathStr).toRealPath();
LOGGER.debug("Original path: {}, Real path: {}", pathStr, path);

// ─── Case1: caller already gave the tessdata folder ────────────────────
if ("tessdata".equals(path.getFileName().toString())) {
Path engData = path.resolve("eng.traineddata");
LOGGER.debug("Looking for eng.traineddata at {}", engData);
if (Files.isRegularFile(engData)) {
tesseract.setDatapath(path.toString());
return true;
}
}

// ─── Case2: caller gave parent directory ──────────────────────────────
Path tessdata = path.resolve("tessdata");
Path engData = tessdata.resolve("eng.traineddata");
LOGGER.debug("Looking for tessdata at {}, eng.traineddata at {}", tessdata, engData);
if (Files.isDirectory(tessdata) && Files.isRegularFile(engData)) {
tesseract.setDatapath(tessdata.toString());
return true;
}

} catch (Exception e) {
LOGGER.debug("Invalid path: {}", pathStr, e);
LOGGER.debug("Invalid tessdata path: {}", pathStr, e);
}
return false;
return false; // nothing usable found
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching generic Exception is too broad and masks specific issues. Should catch specific exceptions like IOException or SecurityException for better error handling.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, trag bot probably selected wrong lines, but overall he's right, the Exception is too generic


/**
* Gets the list of default tessdata paths based on the operating system.
*/
Expand Down