<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
    (XML comments only allowed after xml processor instruction.)

    https://opensourceconnections.com/blog/2019/11/26/tika-and-tesseract-outside-of-solr/
    which links to their sample tika-config.xml (copied below) which configures the PDF and OCR Parsers to behave just as the old PDFParser.props and OCR Parser properties files did.
    
    - new way of one tika-config.xml: https://github.com/o19s/pdf-discovery-demo/blob/crazy_tika_tesseract_inside_of_solr/ocr/tika-config.xml
    - old way of 2 props files: https://github.com/o19s/pdf-discovery-demo/tree/6f5b37305dd863a73af4617db64cbe853c5ecd2a/ocr/tika-properties/org/apache/tika/parser

    Further useful information on configuring tika for OCR (or no OCR) at:
    - https://tika.apache.org/1.16/configuring.html
    - https://issues.apache.org/jira/browse/TIKA-2624
    - https://stackoverflow.com/questions/51655510/how-do-you-enable-the-tesseractocrparser-using-tikaconfig-and-the-tika-command-l#51668962 (out of date?)
    - https://stackoverflow.com/questions/56232720/is-there-a-way-to-disable-ocr-mode-in-tika-without-uninstalling-tesseract
-->
<properties>
  <parsers>
    <parser class="org.apache.tika.parser.DefaultParser">
      <parser-exclude class="org.apache.tika.parser.ocr.TesseractOCRParser"/>
      <parser-exclude class="org.apache.tika.parser.pdf.PDFParser"/>
    </parser>
    <parser class="org.apache.tika.parser.ocr.TesseractOCRParser">
      <params>
	<!-- Setting the following 2 params is unnecessary, since sourcing Greenstone puts the Tesseract binary
	     on the path AND also sets the TESSDATA_PREFIX env var needed by Tesseract -->
        <!--
	    <param name="tesseractPath" type="string">/path/to/GS3/gs2build/ext/tesseract/linux/bin</param>
            <param name="tessdataPath" type="string">/path/to/GS3/gs2build/ext/tesseract/linux/tessdata</param>
	-->

	<!-- IMPORTANT!! -->
        <param name="outputType" type="string">hocr</param><!-- Choose one of: hocr, txt -->
	<!-- hocr is preferred as Tesseract produces nicely formatted html that better reflects
	     the placement of the original text in the scanned page. (Can compare running with horc vs txt)
	     
	     However, initially, the above value had to be fixed as "txt", as outputType value = hocr prevented
	     Tika+Tesseract from OCR-ing pdfs (no OCR output).
	     Until $GEXT_INSTALLED/tessdata/configs/hocr (tesseract config file) was created containing specific
	     property values in point 2b below.

	     To get Tika to work with Tesseract to OCR pages of a scanned PDF:
	     1. always pass in this file as &#45;&#45;config=/path/to/tika-config.xml to tika-app-*.jar cmd,
	     2. AND do one of the following:
	        a. Set the above outputType param to "txt" so Tesseract produces the OCR in .txt format, and things should work,
	        b. OR if you want the OCR generated by Tesseract to be in hocr (html ocr) format, then set the outputType above
		to "hocr" AND ensure a config file also called hocr exists in $TESSDATA_PREFIX/configs containing the following
		(taken from
		https://github.com/tesseract-ocr/tessconfigs/blob/3decf1c8252ba6dbeef0bf908f4b0aab7f18d113/configs/hocr):
	           tessedit_create_hocr 1
	           hocr_font_info 0

		More information about tesseract config options by running:
		   tesseract &#45;&#45;print-parameters 
	-->
        <param name="language" type="string">eng</param>
        <param name="pageSegMode" type="string">1</param>
      </params>
    </parser>
    <parser class="org.apache.tika.parser.pdf.PDFParser">
      <params>
        <param name="ocrStrategy" type="string">ocr_and_text</param>
      </params>
    </parser>

  </parsers>
</properties>
