Skip to content

Commit

Permalink
Merge pull request #40 from UB-Mannheim/config-improvements
Browse files Browse the repository at this point in the history
Improvements for handling configurations issues
  • Loading branch information
zuphilip authored May 28, 2022
2 parents 09afa82 + 52f4d2f commit 515a2c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions chrome/content/preferences.xul
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
</preferences>
<groupbox>
<caption label="OCR parameters"/>
<label value="You can indicate here the path to your OCR engine:"/>
<label value="Full location of the tesseract executable (when empty, some standard locations are searched for it):"/>
<textbox id="pref-zoteroocr-ocrPath-value" flex="1" preference="pref-zoteroocr-ocrPath"/>
<label value="You can indicate here the path to pdftoppm:"/>
<label value="Full location of the pdftoppm executable:"/>
<textbox id="pref-zoteroocr-pdftoppmPath-value" flex="1" preference="pref-zoteroocr-pdftoppmPath"/>
<hbox>
<label value="Choose a language/script you want to use for recognition (default is eng):"/>
Expand Down
15 changes: 13 additions & 2 deletions chrome/content/zoteroocr.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@ Zotero.OCR = new function() {
let ocrEngine = Zotero.Prefs.get("zoteroocr.ocrPath");
let found = false;
if (ocrEngine) {
let pathOrFile = FileUtils.File(ocrEngine);
// If a directory is given, then try for the standard name of the tool.
if (pathOrFile.isDirectory()) {
if (Zotero.isWin) {
ocrEngine = OS.Path.join(ocrEngine, "tesseract.exe");
}
else {
ocrEngine = OS.Path.join(ocrEngine, "tesseract");
}
Zotero.Prefs.set("zoteroocr.ocrPath", ocrEngine);
}
found = yield OS.File.exists(ocrEngine);
}
else {
let path = ["/usr/local/bin/", "/usr/bin/", "C:\\Program Files\\Tesseract-OCR\\", ""];
let path = ["", "/usr/local/bin/", "/usr/bin/", "C:\\Program Files\\Tesseract-OCR\\", "/opt/homebrew/bin/", "/usr/local/homebrew/bin/"];
for (ocrEngine of path) {
ocrEngine += "tesseract";
if (Zotero.isWin) {
Expand All @@ -49,7 +60,7 @@ Zotero.OCR = new function() {
}
}
if (!found) {
alert("No " + ocrEngine + " executable found.");
alert("Tesseract executable not found. Tried: " + ocrEngine);
return;
}

Expand Down

0 comments on commit 515a2c7

Please sign in to comment.