Class: Paperclip::DocsplitPdf
Instance Attribute Summary
#attachment, #options, #src
Instance Method Summary
collapse
#initialize
Instance Method Details
#make ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/docsplit-paperclip-processor.rb', line 32
def make
begin
src_path = File.expand_path(@src.path)
dst_dir = Dir.tmpdir
dst_path = File.join(dst_dir, "#{@basename}.pdf")
if pdf_format?(src_path)
dst_path = File.join(dst_dir, "_#{@basename}.pdf")
FileUtils.copy_file(src_path, dst_path)
else
Docsplit.(src_path, :output => dst_dir)
end
rescue Exception => e
Rails.logger.error e.message
raise PaperclipError, "There was an error converting #{@basename} to pdf"
end
File.open(dst_path)
end
|
51
52
53
54
55
56
|
# File 'lib/docsplit-paperclip-processor.rb', line 51
def pdf_format?(file)
file_magic = FileMagic.new
type = file_magic.file(file)
file_magic.close
type =~ /pdf/i
end
|