Hello all.I was writed a how to in spanish forums to integrate tesseract OCR into alfresco. I repeat the post here because that will be useful for somebody.Sorry for my bad language. I will try to do my best.Before beging the howto, it is importante to make a few considerations:1- Tesseract only support tif files.2- Tesseract 2.x do not work with files ended with .tiff extension. Only work with .tif extensions. Versión 3.x can3- Because alfresco store the temporary files with an extension as your own mime type (ex. if you upload a .tif file, alfresco make a node for that file with the .tiff extension), we need to make a wrapper to deal with this issue (copy the node to .tif extension)4- Tesseract append to the output file the .txt extension, so if you use:tesseract input_file.tif output_file.txt
you will get a file output_file.txt.txtSo we will not add the .txt extension.Before anything, ensure you have installed tesseract, and the dictionaries for the language you want to made OCR. Also add the english too.The first step to do is test tesseract from the command line:tesseract input_file.tif output_file -l eng
The syntax parameter -l indicate the tesseract will use the english dictionary. You can modify this to spa for spanish, and so on. If the above command produce a text file with the content of the OCR, then we can continue.Create a file extension, named ocrtiff-transform-context.xml into /tomcat/shared/classes/alfresco/extenssion with the following content: <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="transformer.worker.ocr.tiff" class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker">
<property name="mimetypeService">
<ref bean="mimetypeService" />
</property>
<property name="checkCommand">
<bean class="org.alfresco.util.exec.RuntimeExec">
<property name="commandsAndArguments">
<map>
<entry key=".*">
<list>
<!– <value>tesseract</value> –>
<value>/opt/alfresco/ocr</value>
</list>
</entry>
</map>
</property>
<property name="errorCodes">
<value>2</value>
</property>
</bean>
</property>
<property name="transformCommand">
<bean class="org.alfresco.util.exec.RuntimeExec">
<property name="commandsAndArguments">
<map>
<entry key=".*">
<list>
<!– <value>tesseract</value>
<value>${source}</value>
<value>${target}</value>
<value>-l</value>
<value>eng</value> –>
<value>/opt/alfresco/ocr</value>
<value>${source}</value>
<value>${target}</value>
</list>
</entry>
</map>
</property>
<property name="errorCodes">
<value>1,2</value>
</property>
</bean>
</property>
<property name="explicitTransformations">
<list>
<bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails">
<property name="sourceMimetype"><value>image/tiff</value></property>
<property name="targetMimetype"><value>text/plain</value></property>
</bean>
</list>
</property>
</bean>
<bean id="transformer.ocr.tiff" class="org.alfresco.repo.content.transform.ProxyContentTransformer" parent="baseContentTransformer">
<property name="worker">
<ref bean="transformer.worker.ocr.tiff" />
</property>
</bean>
</beans>
Then create a wrapper file, named "ocr" and put into the alfresco root directory. In my case I put into /opt/alfresco. #!/bin/bash
# save arguments to variables
SOURCE=$1
TARGET=$2
TMPDIR=/tmp
FILENAME=`basename $SOURCE`
OCRFILE=$FILENAME.tif
# to see what happens
#echo "from $SOURCE to $TARGET" >>/tmp/ocrtransform.log
cp -f $SOURCE $TMPDIR/$OCRFILE
# call tesseract and redirect output to $TARGET
tesseract $TMPDIR/$OCRFILE ${TARGET%\.*} -l eng
rm -f $TMPDIR/$OCRFILE
Made then as executable file (chown 755 ocr)Restart alfresco, and upload a tif file. Then if you are into alfresco explorer, click on the "I" (info) icon to see the strings that tesseract can extract from the fif file. Also you can made a search into alfresco explorer, or share (in this last, you need to upload the file under your site).EnjoyPD: If you can improve this how to, let me know.