Class: Dhalang::PDF

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

Overview

Allows consumers of this library to create PDFs with Puppeteer.

Class Method Summary collapse

Class Method Details

.get_from_html(html, options = {}) ⇒ String

Captures the full HTML as PDF. Useful when creating dynamic content, for example invoices.

Parameters:

  • html (String)

    The html to get as PDF.

  • options (Hash) (defaults to: {})

    User configurable options.

Returns:

  • (String)

    The PDF that was created as binary.



25
26
27
28
29
30
31
32
33
34
# File 'lib/PDF.rb', line 25

def self.get_from_html(html, options = {})
  html_file = FileUtils.create_temp_file("html", html)
  url = "file://" + html_file.path
  begin
      binary_pdf_content = get(url, options)
  ensure
    FileUtils.delete(html_file)
  end
  return binary_pdf_content
end

.get_from_url(url, options = {}) ⇒ String

Captures the full webpage under the given url as PDF.

Parameters:

  • url (String)

    The url to get as PDF.

  • options (Hash) (defaults to: {})

    User configurable options.

Returns:

  • (String)

    The PDF that was created as binary.



13
14
15
16
# File 'lib/PDF.rb', line 13

def self.get_from_url(url, options = {})
  UrlUtils.validate(url)
  get(url, options)
end