Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lib/paperclip_processors/text.rb
- module Paperclip
- # Handles extracting plain text from PDF file attachments
- class Text < Processor
- attr_accessor :whiny
- # Creates a Text extract from PDF
- def make
- src = @file
- dst = Tempfile.new([@basename, 'txt'].compact.join("."))
- command = <<-end_command
- "#{ File.expand_path(src.path) }"
- "#{ File.expand_path(dst.path) }"
- end_command
- begin
- success = Paperclip.run("/usr/bin/pdftotext -nopgbrk", command.gsub(/\s+/, " "))
- Rails.logger.info "Processing #{src.path} to #{dst.path} in the text processor."
- rescue PaperclipCommandLineError
- raise PaperclipError, "There was an error processing the text for #{@basename}" if @whiny
- end
- dst
- end
- end
- end
Add Comment
Please, Sign In to add comment