class Paperclip::Document::Processors::Freezer
This processor converts document to PDF
Public Class Methods
new(file, options = {}, attachment = nil)
click to toggle source
Calls superclass method
Paperclip::Document::Processor::new
# File lib/paperclip/document/processors/freezer.rb, line 6 def initialize(file, options = {}, attachment = nil) super @format = options[:format] unless @format == :pdf raise Paperclip::Error, 'Valid format (pdf) must be specified' end end
Public Instance Methods
make()
click to toggle source
Convert the document to pdf
# File lib/paperclip/document/processors/freezer.rb, line 15 def make destination_path = tmp_dir.to_s destination_file = File.join(destination_path, basename + ".#{@format}") if pdf_format? destination_file = file_path.to_s else Docsplit.extract_pdf(file_path.to_s, output: destination_path) end File.open(destination_file) end
pdf_format?()
click to toggle source
# File lib/paperclip/document/processors/freezer.rb, line 26 def pdf_format? File.open(file_path, 'rb', &:readline).to_s =~ /\A\%PDF-\d+(\.\d+)?$/ end