Skip to content

Commit

Permalink
adding settings to enable/disable pdf ocr
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Feb 13, 2019
1 parent 5a0628a commit 51fadf7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions js/admin.elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ var fts_tesseract_elements = {
tesseract_ocr: null,
tesseract_psm: null,
tesseract_lang: null,
tesseract_pdf: null,

init: function () {
fts_tesseract_elements.tesseract_div = $('#files_ocr-tesseract');
fts_tesseract_elements.tesseract_psm = $('#tesseract_psm');
fts_tesseract_elements.tesseract_lang = $('#tesseract_lang');
fts_tesseract_elements.tesseract_ocr = $('#tesseract_ocr');
fts_tesseract_elements.tesseract_pdf = $('#tesseract_pdf');

fts_tesseract_elements.tesseract_ocr.on('change', fts_tesseract_elements.updateSettings);
fts_tesseract_elements.tesseract_psm.on('change', fts_tesseract_elements.updateSettings);
fts_tesseract_elements.tesseract_lang.on('change', fts_tesseract_elements.updateSettings);
fts_tesseract_elements.tesseract_pdf.on('change', fts_tesseract_elements.updateSettings);
},


Expand Down
4 changes: 3 additions & 1 deletion js/admin.settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var fts_tesseract_settings = {
fts_tesseract_elements.tesseract_ocr.prop('checked', (result.tesseract_enabled === '1'));
fts_tesseract_elements.tesseract_psm.val(result.tesseract_psm);
fts_tesseract_elements.tesseract_lang.val(result.tesseract_lang);
fts_tesseract_elements.tesseract_pdf.prop('checked', (result.tesseract_pdf === '1'));

fts_admin_settings.tagSettingsAsSaved(fts_tesseract_elements.tesseract_div);

Expand All @@ -69,7 +70,8 @@ var fts_tesseract_settings = {
var data = {
tesseract_enabled: (fts_tesseract_elements.tesseract_ocr.is(':checked')) ? 1 : 0,
tesseract_psm: fts_tesseract_elements.tesseract_psm.val(),
tesseract_lang: fts_tesseract_elements.tesseract_lang.val()
tesseract_lang: fts_tesseract_elements.tesseract_lang.val(),
tesseract_pdf: (fts_tesseract_elements.tesseract_pdf.is(':checked')) ? 1 : 0
};

$.ajax({
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class ConfigService {
const TESSERACT_ENABLED = 'tesseract_enabled';
const TESSERACT_PSM = 'tesseract_psm';
const TESSERACT_LANG = 'tesseract_lang';
const TESSERACT_PDF = 'tesseract_pdf';

public $defaults = [
self::TESSERACT_ENABLED => '0',
self::TESSERACT_PSM => '4',
self::TESSERACT_LANG => 'eng'
self::TESSERACT_LANG => 'eng',
self::TESSERACT_PDF => '0'
];


Expand Down
4 changes: 4 additions & 0 deletions lib/Service/TesseractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ private function ocrPdf(AFilesDocument $document, File $file): bool {
return false;
}

if ($this->configService->getAppValue(ConfigService::TESSERACT_PDF) !== '1') {
return true;
}

try {
$path = $this->getAbsolutePath($file);
$pdf = new Pdf($path);
Expand Down
12 changes: 12 additions & 0 deletions templates/settings.admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@
<input type="text" class="big" id="tesseract_lang" value=""/>
</div>
</div>

<div class="div-table-row tesseract_ocr_enabled">
<div class="div-table-col div-table-col-left">
<span class="leftcol">PDF</span>
<br/>
<em>enable the OCR of PDF (heavy on resource)</em>
</div>
<div class="div-table-col">
<input type="checkbox" id="tesseract_pdf" value="1"/>
</div>
</div>

</div>


Expand Down

0 comments on commit 51fadf7

Please sign in to comment.