rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.71k stars 123 forks source link

Ferrum::Browser load inline page or from local file #260

Closed davidwessman closed 2 years ago

davidwessman commented 2 years ago

Hello.

I read through the documentation and the options for Ferrum::Browser.new but could not find any way to load a browser from a local file or string instead of an url.

The use-case I have is to render PDFs where there is no URL to load the HTML from.

html = generate_html
browser = Ferrum::Browser.new
browser.load(html)
tmp = Tempfile.new("pdf-chrome-#{filename}")
browser.pdf(
  path: tmp.path,
  format: :A4,
  landscape: false,
  margin: {top: 36, right: 36, bottom: 36, left: 36},
  preferCSSPageSize: true,
  printBackground: true
)
browser.quit
pdf_data = File.read(tmp.path)

I am sorry if I missed some option for this, thankful for any help 🙂