Class: Common::ConvertToPdf
- Inherits:
-
Object
- Object
- Common::ConvertToPdf
- Defined in:
- lib/common/convert_to_pdf.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ ConvertToPdf
constructor
A new instance of ConvertToPdf.
- #run ⇒ Object
Constructor Details
#initialize(file) ⇒ ConvertToPdf
Returns a new instance of ConvertToPdf.
7 8 9 |
# File 'lib/common/convert_to_pdf.rb', line 7 def initialize(file) @file = file end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/common/convert_to_pdf.rb', line 11 def run in_file = Common::FileHelpers.generate_clamav_temp_file(@file.read) return in_file if @file.content_type == Mime[:pdf].to_s unless @file.content_type.starts_with?('image/') File.delete(in_file) raise IOError, "PDF conversion failed, unsupported file type: #{@file.content_type}" end out_file = "#{Common::FileHelpers.random_file_path}.pdf" begin MiniMagick::Tool::Convert.new do |convert| convert << '-units' << 'pixelsperinch' << '-density' << '72' << '-page' << 'letter' convert << in_file convert << out_file end ensure File.delete(in_file) end out_file end |