Add command line option to skip pages that contain font data
If a page contains font data, the script would abort, unless -f was given, in which case it would use pdftoppm to rasterize the font into a bitmap and then attempt to OCR it. -f is almost certainly not what users want unless they want to debug OCR or something. If a PDF already has fonts it either was OCR'd already, or it is a composite file containing, for example, some scanned documents appended to a text report. In the latter case, this -s option provides OCR on pages that don't have it without changing those that do, and if a PDF was completely OCRed it will be converted to PDF/A. In batch jobs with a mix of OCR and non-OCR the implicit conversion to PDF/A is also useful.
This commit is contained in:
+7
-2
@@ -23,6 +23,7 @@ OVERSAMPLING_DPI="${11}" # Oversampling resolution in dpi
|
||||
PDF_NOIMG="${12}" # Request to generate also a PDF page containing only the OCRed text but no image (helpful for debugging)
|
||||
TESS_CFG_FILES="${13}" # Specific configuration files to be used by Tesseract during OCRing
|
||||
FORCE_OCR="${14}" # Force to OCR, even if the page already contains fonts
|
||||
SKIP_TEXT="${15}" # Skip OCR on pages that contain fonts and include the page anyway
|
||||
|
||||
|
||||
|
||||
@@ -119,8 +120,12 @@ dpi=$DEFAULT_DPI # default resolution
|
||||
getImgInfo "$page" "$widthPDF" "$heightPDF" "$curImgInfo"
|
||||
ret_code="$?"
|
||||
|
||||
# in case the page contains text do not OCR, unless the FORCE_OCR flag is set
|
||||
if ([ "$ret_code" -eq "1" ] && [ "$FORCE_OCR" -eq "0" ]); then
|
||||
# Handle pages that already contain a text layer
|
||||
if ([ "$ret_code" -eq "1" ] && [ "$SKIP_TEXT" -eq "1" ]); then
|
||||
echo "Page $page: Skipping processing because page contains text..."
|
||||
pdfseparate -f $page -l $page ${FILE_INPUT_PDF} $curOCRedPDF
|
||||
exit 0
|
||||
elif ([ "$ret_code" -eq "1" ] && [ "$FORCE_OCR" -eq "0" ]); then
|
||||
echo "Page $page: Exiting... (Use the -f option to force OCRing, even though fonts are available in the input file)" && exit $EXIT_BAD_INPUT_FILE
|
||||
elif ([ "$ret_code" -eq "1" ] && [ "$FORCE_OCR" -eq "1" ]); then
|
||||
[ $VERBOSITY -ge $LOG_WARN ] && echo "Page $page: OCRing anyway, assuming a default resolution of $dpi dpi"
|
||||
|
||||
Reference in New Issue
Block a user