Giter Site home page Giter Site logo

rajanverma-me / dhalang Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nielssteensma/dhalang

0.0 1.0 0.0 60 KB

Ruby gem for Puppeteer. Create PDF's and make screenshots of webpages from html

License: MIT License

Ruby 88.13% JavaScript 11.87%

dhalang's Introduction

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

dhalang's People

Contributors

nielssteensma avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.