class WkhtmltopdfRunner::Runner

Public Instance Methods

config() click to toggle source
# File lib/wkhtmltopdf_runner/runner.rb, line 43
def config
  @config ||= Configuration.new
end
Also aliased as: configuration
configuration()
Alias for: config
configure() { |config| ... } click to toggle source

Configure client with a block of settings.

# File lib/wkhtmltopdf_runner/runner.rb, line 49
def configure
  yield(config) if block_given?
  true
end
pdf_from_file(file, options = {}, &block) click to toggle source
# File lib/wkhtmltopdf_runner/runner.rb, line 24
def pdf_from_file(file, options = {}, &block)
  pdf_from_url("file://#{file.path}", options, &block)
end
pdf_from_string(string, options = {}, &block) click to toggle source
# File lib/wkhtmltopdf_runner/runner.rb, line 28
def pdf_from_string(string, options = {}, &block)
  Tempfile.open(['file-', '.html']) do |html_file|
    html_file.write(string)
    html_file.rewind

    pdf_from_file(html_file, options, &block)
  end
end
pdf_from_url(url, options = {}) { |pdf_file| ... } click to toggle source
# File lib/wkhtmltopdf_runner/runner.rb, line 8
def pdf_from_url(url, options = {})
  Tempfile.open(['file-', '.pdf']) do |pdf_file|
    pdf_file.binmode

    run(url, pdf_file, options)
    pdf_file.rewind

    if block_given?
      yield(pdf_file)
      return true
    end

    pdf_file.read
  end
end
run(url, file, options = {}) click to toggle source
# File lib/wkhtmltopdf_runner/runner.rb, line 37
def run(url, file, options = {})
  WkhtmltopdfRunner::Cmd
    .new(url: url, file: file, config: config, options: options)
    .run
end