Skip to content

Commit 2520c2b

Browse files
Merge pull request dwhly-proj#106 from dwhly-proj/paul/ocr_force_update
Paul/ocr force update
2 parents f6bdd0a + 805ca05 commit 2520c2b

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

droppdf/apps/_static/apps/js/ocr_pdf_upload.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@
7979
$('#run-button')
8080
.addClass('disabled')
8181
.attr('disabled', true)
82+
83+
} else if (response.file_info.has_text) {
84+
85+
$('#run-button').hide();
86+
$('#upload-has-text').show();
87+
8288
} else {
8389
$('#run-button')
8490
.removeClass('disabled')
8591
.attr('disabled', false)
92+
.show()
8693
}
8794
};
8895
},
@@ -164,8 +171,13 @@
164171
$(document).ready(function() {
165172
upload_in_progress = false;
166173
$('.button-box').hide();
174+
$('#upload-has-text').hide();
167175
$('#in-progress').hide();
168-
$('#pdf-file').attr('disabled', false);
176+
177+
$('#pdf-file')
178+
.attr('disabled', false)
179+
.val('')
180+
169181
$('#progress-bar-inner').css('width', '0%');
170182
$('#pdf-file')
171183
.attr('disabled', false)

droppdf/apps/_templates/ocr_pdf.html

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@
8080
color: red;
8181
}
8282

83+
.success-msg {
84+
padding-top: 1em;
85+
color: green;
86+
}
87+
88+
.black-text {
89+
color: #000;
90+
}
91+
8392
.button-box {
8493
display: flex;
8594
flex: 1;
@@ -245,7 +254,7 @@
245254
Add text to an image PDF.
246255
</div>
247256

248-
<form id="param-form" action="/ocr/upload/" method="POST" enctype="multipart/form-data">
257+
<form id="param-form" action="/ocr/upload/" method="POST" autocomplete="off" enctype="multipart/form-data">
249258

250259
<div class="option-box">
251260
</div>
@@ -288,19 +297,27 @@ <h3 id="filename"></h3>
288297
<i class="fa fa-upload"></i>
289298
Run OCR
290299
</div>
291-
292-
<div id="run-force" class="button" style="width: 8em" onclick="runOCR(true)">
293-
<i class="fa fa-upload"></i>
294-
Force OCR
295-
</div>
296-
<div class="help-label">
297-
<i class="fa fa-question-circle" title="Forcing OCR will replace any existing text with OCRd text. If there is a question, it's likely better to try 'Run OCR' first."></i>
298-
</div>
299300
</div>
300301

301302
<div id="upload-error" class="small error" style="display: none;">
302303
</div>
303304

305+
<div id="upload-has-text" class="small success-msg" style="display: none;">
306+
<span style="font-size: 1.2em">
307+
<i class="fa fa-check"></i>
308+
</span>
309+
This document already has selectable text and is most likely ready to use for annotations.
310+
<br><br>
311+
If the quality of the current OCR'd text is not acceptable you can redo the OCR process which may give better results.
312+
<br>
313+
(This process will take some time and in rare instances will not be successful, depending on the qualities of the uploaded document).
314+
<br><br>
315+
<div id="run-force" class="button black-text" style="width: 8em" onclick="runOCR(true)">
316+
<i class="fa fa-upload"></i>
317+
Redo OCR
318+
</div>
319+
</div>
320+
304321
</div>
305322

306323
</form>

droppdf/apps/_templates/ocr_pdf_result.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
OCR in progress. Started at <span id="time-start"></span>
163163
</p>
164164
<p>
165-
Large files can sometimes take several minutes, or up to five or ten if the Force OCR option is used.
165+
Large files can sometimes take several minutes, or up to five or ten if the OCR is a redo with existing text.
166166
</p>
167167
<p>
168168
A clickable download link will appear when processing is complete.

droppdf/apps/apps/ocr/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def upload(request):
7070

7171
#already_has_text?
7272
if check_pdf_has_text(new_filename):
73-
processing_error = 'This PDF already has text. Use the "Force OCR" button to overwrite text with a fresh OCR if desired. If file was OCRd on previous upload those results will be provided'
73+
#processing_error = 'This PDF already has text. Use the "Force OCR" button to overwrite text with a fresh OCR if desired. If file was OCRd on previous upload those results will be provided'
74+
has_text = True
75+
else:
76+
has_text = False
7477

7578

7679
if not existing_name:
@@ -114,7 +117,7 @@ def upload(request):
114117
data = {'file_info': {'filename': filename, 'size': file_.size,
115118
'new_filename': new_filename, 'processing_error': processing_error,
116119
'tempfile_path': tempfile_path, 'already_exists': already_exists,
117-
'md5_hash': md5_hash}}
120+
'md5_hash': md5_hash, 'has_text': has_text}}
118121

119122
return JsonResponse(data)
120123

droppdf/droppdf/celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django.conf import settings
77

8-
app = Celery('financial_planning_app', broker=settings.BROKER_URL)
8+
app = Celery('droppdf_app', broker=settings.BROKER_URL)
99

1010
app.config_from_object('django.conf:settings', namespace='CELERY')
1111
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

0 commit comments

Comments
 (0)