Skip to content
Ruby gem for Puppeteer. Create PDF's and make screenshots of webpages from html
Ruby JavaScript
Branch: master
Clone or download
Latest commit c878e07 Mar 10, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Screenshots are now taken of full page, instead puppeteers default 80… Mar 10, 2019
spec Fix for wrong test name Mar 10, 2019
.gitignore Added .idea/ to git ignore Jan 24, 2019
.travis.yml
Dhalang.gemspec Added support for jpeg images Mar 10, 2019
Gemfile Initial commit Jan 24, 2019
Gemfile.lock Added support for jpeg images Mar 10, 2019
LICENSE Changed license from GNU to MIT Feb 7, 2019
README.md Fixxed typo in readme Mar 10, 2019
Rakefile Initial commit Jan 24, 2019
package.json Solved issues with CI Jan 25, 2019

README.md

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 )
  • Capture a screenshot of a webpage

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>")

Get a PNG screenshot of a website
Dhalang::Screenshot.get_from_url_as_png("https://www.google.com")

Get a JPEG screenshot of a website
Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.com")

All methods return a string containing the PDF or JPEG/PNG 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

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

def example_controller_method  
    binary_png = Dhalang::Screenshot.get_from_url_as_png("https://www.google.nl")
    send_data(binary_png, filename: 'screenshotofgoogle.png', type: 'image/png')   
end

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

def example_controller_method  
    binary_jpeg = Dhalang::Screenshot.get_from_url_as_jpeg("https://www.google.nl")
    send_data(binary_jpeg, filename: 'screenshotofgoogle.jpeg', type: 'image/jpeg')   
end
You can’t perform that action at this time.