Class: Wkhtmltopdf

Inherits:
Object
  • Object
show all
Defined in:
lib/wkhtmltopdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Wkhtmltopdf

Returns a new instance of Wkhtmltopdf.



5
6
7
8
9
10
11
# File 'lib/wkhtmltopdf.rb', line 5

def initialize(options)
  # @pdf_file = "#{options[:file_path]}/#{options[:pdf]}.pdf"
  @html_file = options[:html_file] if options.has_key?(:html_file)
  @source = options[:source] if options.has_key?(:source)
  @optional_params = options[:wkhtmltopdf_options] if options.has_key?(:wkhtmltopdf_options)
  create_params_string
end

Instance Attribute Details

#html_fileObject

Returns the value of attribute html_file.



3
4
5
# File 'lib/wkhtmltopdf.rb', line 3

def html_file
  @html_file
end

#optional_paramsObject

Returns the value of attribute optional_params.



3
4
5
# File 'lib/wkhtmltopdf.rb', line 3

def optional_params
  @optional_params
end

#params_stringObject

Returns the value of attribute params_string.



3
4
5
# File 'lib/wkhtmltopdf.rb', line 3

def params_string
  @params_string
end

#pdf_fileObject

Returns the value of attribute pdf_file.



3
4
5
# File 'lib/wkhtmltopdf.rb', line 3

def pdf_file
  @pdf_file
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/wkhtmltopdf.rb', line 3

def source
  @source
end

Instance Method Details

#generateObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/wkhtmltopdf.rb', line 13

def generate
  wkhtml_call = "wkhtmltopdf "
  if !@source.nil?
    wkhtml_call << "#{@source}"
  else
    wkhtml_call << "#{@html_file}"
  end
  wkhtml_call << " #{@params_string} - -q"
  return `#{wkhtml_call}`
end