Class: Paperclip::Document::Processors::Freezer
- Inherits:
-
Paperclip::Document::Processor
- Object
- Processor
- Paperclip::Document::Processor
- Paperclip::Document::Processors::Freezer
- 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 Method Summary collapse
-
#initialize(file, options = {}, attachment = nil) ⇒ Freezer
constructor
A new instance of Freezer.
-
#make ⇒ Object
Convert the document to pdf.
- #pdf_format? ⇒ Boolean
Methods inherited from Paperclip::Document::Processor
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Freezer
Returns a new instance of Freezer.
6 7 8 9 10 11 12 |
# File 'lib/paperclip/document/processors/freezer.rb', line 6 def initialize(file, = {}, = nil) super @format = [:format] unless @format == :pdf raise Paperclip::Error, 'Valid format (pdf) must be specified' end end |
Instance Method Details
#make ⇒ Object
Convert the document to pdf
15 16 17 18 19 20 21 22 23 24 |
# 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? ⇒ Boolean
26 27 28 |
# 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 |