Class: DragonflyPdf::Processors::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_pdf/processors/page.rb

Instance Method Summary collapse

Instance Method Details

#call(content, page_number = 1, _opts = {}) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dragonfly_pdf/processors/page.rb', line 6

def call(content, page_number = 1, _opts = {})
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  pdf_properties = DragonflyPdf::Analysers::PdfProperties.new.call(content)
  raise DragonflyPdf::PageNotFound unless pdf_properties['page_numbers'].include?(page_number)

  content.shell_update(ext: 'pdf') do |old_path, new_path|
    "#{gs_command} -dFirstPage=#{page_number} -dLastPage=#{page_number} -o \"#{new_path}\" -f \"#{old_path}\""
  end
end