Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #lib/paperclip_processors/text.rb
  2. module Paperclip
  3. # Handles extracting plain text from PDF file attachments
  4. class Text < Processor
  5.  
  6. attr_accessor :whiny
  7.  
  8. # Creates a Text extract from PDF
  9. def make
  10. src = @file
  11. dst = Tempfile.new([@basename, 'txt'].compact.join("."))
  12. command = <<-end_command
  13. "#{ File.expand_path(src.path) }"
  14. "#{ File.expand_path(dst.path) }"
  15. end_command
  16.  
  17. begin
  18. success = Paperclip.run("/usr/bin/pdftotext -nopgbrk", command.gsub(/\s+/, " "))
  19. Rails.logger.info "Processing #{src.path} to #{dst.path} in the text processor."
  20. rescue PaperclipCommandLineError
  21. raise PaperclipError, "There was an error processing the text for #{@basename}" if @whiny
  22. end
  23. dst
  24. end
  25. end
  26. end
Add Comment
Please, Sign In to add comment