0.01
No commit activity in last 3 years
No release in over 3 years
Extract text from common office files. Based on the file's content type a command line tool is selected to do the job.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

~> 1.8.1
~> 1.2.1
 Project Readme

plaintext Build Status

This gem wraps command line tools to extract plain text from typical files such as

  • PDF
  • RTF
  • MS Office
    • Word (doc, docx)
    • Excel (xsl, xslx)
    • PowerPoint (ppt, pptx)
  • OpenOffice + Libre
    • Presentation
    • Text
    • Spreadsheet
  • Image files (png, jpeg, tiff), such as screenshots and scanned documents, through character recognition (OCR)
  • Plaintext (txt)
  • Comma-separated values (csv)

Acknowledgements

This gem bases on work by Jens Krämer / Planio, who originally provided it as a patch for Redmine. Now, it is a collaborative effort of both project management software providers Planio and OpenProject as both systems tackle the identical challenge to extract plain text from attachment files.

Installation

Add this line to your application's Gemfile:

gem 'plaintext'

And then execute:

$ bundle

Or install it yourself as:

$ gem install plaintext

Rails

In a Rails application save plaintext.yml.example in config/plaintext.yml and overwrite the settings to your needs.

Then load that configuration file in an initializer. Add the following lines to config/initializers/plaintext.rb:

path = Rails.root.join 'config', 'plaintext.yml'
if File.file?(path)
  config = File.read(path)
  Plaintext::Configuration.load(config)
end

Plain Ruby

Please overwrite Plaintext::Configuration.load.

Linux

On linux the default configuration should work. However, make sure that the following packages are installed

$ apt-get install catdoc unrtf poppler-utils tesseract-ocr

Mac OS X

On Mac things are still not complete. Please help us to have the same capabilities as under Linux. Right now we cannot extract text from presentation and spreadsheets.

Please use homebrew to install the missing command line tools.

$ brew install unrtf poppler tesseract

The plaintext.yml should look like this:

pdftotext:
  - /usr/local/bin/pdftotext
  - -enc
  - UTF-8
  - __FILE__
  - '-'

unrtf:
  - /usr/local/bin/unrtf
  - --text
  - __FILE__

tesseract:
  - /usr/local/bin/tesseract
  - __FILE__
  - stdout

catdoc:
  - /usr/bin/textutil
  - -convert
  - txt
  - -stdout
  - __FILE__

Usage

# `file` is of type File.
# `content_type` is a String.
fulltext = Plaintext::Resolver.new(file, content_type).text

To limit the number of bytes returned (default is 4MB), set the max_plaintext_bytes property on the resolver instance before calling text.

License

The plaintext gem is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the plugin. If not, see www.gnu.org/licenses.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/planio-gmbh/plaintext.