Class: Paperclip::Document::Processors::Freezer

Inherits:
Paperclip::Document::Processor show all
Defined in:
lib/paperclip/document/processors/freezer.rb

Overview

This processor converts document to PDF

Instance Attribute Summary

Attributes inherited from Paperclip::Document::Processor

#instance, #tmp_dir

Instance Method Summary collapse

Methods inherited from Paperclip::Document::Processor

#basename, #file_path

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Freezer

Returns a new instance of Freezer.



7
8
9
10
11
12
13
# File 'lib/paperclip/document/processors/freezer.rb', line 7

def initialize(file, options = {}, attachment = nil)
  super
  @format = options[:format]
  unless @format == :pdf
    raise Paperclip::Error, "Valid format (pdf) must be specified"
  end
end

Instance Method Details

#makeObject

Convert the document to pdf



16
17
18
19
20
21
22
23
24
25
# File 'lib/paperclip/document/processors/freezer.rb', line 16

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
  return File.open(destination_file)
end

#pdf_format?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/paperclip/document/processors/freezer.rb', line 28

def pdf_format?
  File.open(file_path, "rb", &:readline).to_s =~ /\A\%PDF-\d+(\.\d+)?$/
end