Dhalang Build Status

Dhalang is a Ruby wrapper for Google's Puppeteer.

Features

  • Generate PDFs from pages
  • Generate PDFs from html ( external images/stylesheets supported )

More will come.

Installation

Add this line to your application's Gemfile:

gem 'dhalang'

And then execute:

$ bundle update

Install puppeteer in your application's root directory:

$ npm install puppeteer

NodeJS v7.6.0 or greater is required

Usage

Get a PDF of a website url
Dhalang::PDF.get_from_url("https://www.google.com")
It is important to pass the complete url, leaving out https://, http:// or www. will result in an error.

Get a PDF of a HTML string
Dhalang::PDF.get_from_html("<html><head></head><body><h1>examplestring</h1></body></html>")

Both methods return a string containing the PDF in binary.

To return the PDF from a Rails controller you can do the following:

def example_controller_method  
    binary_pdf = Dhalang::PDF.get_from_url("https://www.google.com")  
    send_data(binary_pdf, filename: 'pdfofgoogle.pdf', type: 'application/pdf')  
end