ExtractText NiFi Custom Processor Powered by Apache Tika
ExtractText NiFi Custom Processor Powered by Apache Tika
Apache Tika is amazing, it is very easy to use it to analyze file and then to extract text with it. Apache Tika uses other powerful Apache projects like Apache PDFBox and Apache POI.

Example Usage
- Feed in documents, I use my LinkProcessor which grabs links from a website and returns a JSON List.
- Split the resulting JSON list into individual JSON rows with SplitJSON.
- EvaluateJSONPath to extract just the URLs.
- InvokeHTTP to do a GET on that parsed URL.
- RouteOnAttribute to only process file types I am interested in like Microsoft Word.
- The new ExtractTextProcessor to extract the text of the document.

- Then we save the text as a file in some data store, perhaps HDFS.


If you have a directory of files, you can just use GetFile to ingest them en masse.
LinkProcessor (https://github.com/tspannhw/linkextractorprocessor)
URL: http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.5.3/index.html
This is an example of a URL that I want to grab all the documents from. You can point it at any URL that has links to documents (HTML, Word, Excel, PowerPoint, etc...).
RouteOnAttribute
I only want to process a few types of files, so I limit them here.
${filename:endsWith('.doc'):or(${filename:endsWith('.pdf')}):or(${filename:endsWith('.rtf')}):or(${filename:endsWith('.ppt')}):or(
${filename:endsWith('.docx')}):or(${filename:endsWith('.pptx')}):or(${filename:endsWith('.html')}):or(${filename:endsWith('.htm')}):or(${filename:endsWith('.xls')}):or(
${filename:endsWith('.xlsx')}):or(${filename:endsWith('.xml')}):or(${Content-Type:contains('text/html')}):or(${Content-Type:contains('application/pdf')}):or(
${Content-Type:contains('application/msword')}):or(${Content-Type:contains('application/vnd')}):or(${Content-Type:contains('text/xml')})}
Release:
https://github.com/tspannhw/nifi-extracttext-processor/releases/tag/1.0
Reference:
- https://tika.apache.org/
- https://tika.apache.org/1.14/formats.html
- http://pdfbox.apache.org/
- https://pdfbox.apache.org/1.8/cookbook/documentcreation.html
- http://poi.apache.org/
- https://community.hortonworks.com/repos/81693/nifi-custom-processor-for-extracting-text-from-doc.html?shortDescriptionMaxLength=140
- https://dzone.com/articles/cool-projects-big-data-machine-learning-apache-nifi

