Module: FerrumPdf

Defined in:
lib/ferrum_pdf.rb,
lib/ferrum_pdf/railtie.rb,
lib/ferrum_pdf/version.rb,
lib/ferrum_pdf/controller.rb,
lib/ferrum_pdf/html_preprocessor.rb

Defined Under Namespace

Modules: Controller, HTMLPreprocessor Classes: Railtie

Constant Summary collapse

DEFAULT_HEADER_TEMPLATE =
"<div class='date text left'></div><div class='title text center'></div>"
<<~HTML
  <div class='url text left grow'></div>
  <div class='text right'><span class='pageNumber'></span>/<span class='totalPages'></span></div>
HTML
VERSION =
"0.3.0"
@@include_controller_module =
true

Class Method Summary collapse

Class Method Details

.browser(**options) ⇒ Object



19
20
21
# File 'lib/ferrum_pdf.rb', line 19

def browser(**options)
  @browser ||= Ferrum::Browser.new(options)
end

.render(host:, protocol:, html: nil, url: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ferrum_pdf.rb', line 35

def render(host:, protocol:, html: nil, url: nil)
  browser.create_page do |page|
    if html
      page.content = FerrumPdf::HTMLPreprocessor.process(html, host, protocol)
      page.network.wait_for_idle
    else
      page.go_to(url)
    end
    yield page
  end
rescue Ferrum::DeadBrowserError
  retry
end

.render_pdf(html: nil, url: nil, host: nil, protocol: nil, pdf_options: {}) ⇒ Object



23
24
25
26
27
# File 'lib/ferrum_pdf.rb', line 23

def render_pdf(html: nil, url: nil, host: nil, protocol: nil, pdf_options: {})
  render(host: host, protocol: protocol, html: html, url: url) do |page|
    page.pdf(**pdf_options.with_defaults(encoding: :binary))
  end
end

.render_screenshot(html: nil, url: nil, host: nil, protocol: nil, screenshot_options: {}) ⇒ Object



29
30
31
32
33
# File 'lib/ferrum_pdf.rb', line 29

def render_screenshot(html: nil, url: nil, host: nil, protocol: nil, screenshot_options: {})
  render(host: host, protocol: protocol, html: html, url: url) do |page|
    page.screenshot(**screenshot_options.with_defaults(encoding: :binary, full: true))
  end
end