Giter Club home page Giter Club logo

phantom-static's Introduction

Phantom Static

A library for obtaining static items from PhantomJS, such as images or a PDF document.

# use default options
file = PhantomStatic.as_file "http://google.com"

string = PhantomStatic.as_str "http://google.com" do |o|
  o.output = :pdf
end

Requirements

  • PhantomJS binary
  • Ruby
  • An internet connection

Configuration

PhantomStatic supports a configuration block (useful for initializers) which accepts the following arguments

  • location: The location to the PhantomJS bin.
PhantomStatic.configure do |config|

  config.location = "/my/own/special/bin/phantomjs"

end

If no location is specified, the location will automatically be determined from PATH.

Default settings

Default settings can be provided so that all calls to PhantomStatic inherit these options.

PhantomStatic.config.set_defaults do |settings|

  settings.A3
  settings.landscape
  settings.output = :pdf

end

set_defaults yields on a new or existing PhantomStatic::Builder object, which exposes the following methods

  • output=(extension)
  • Can be :jpg, :png, :gif or :pdf
  • A3()
  • Output must equal :pdf
  • A4()
  • Output must equal :pdf
  • A5()
  • Output must equal :pdf
  • legal()
  • Output must equal :pdf
  • letter()
  • Output must equal :pdf
  • tabloid()
  • Output must equal :pdf
  • border=(val)
  • Output must equal :pdf
  • landscape()
  • Output must equal :pdf
  • portrait()
  • Output must equal :pdf
  • width=(val), height=(val)
  • To be used if you don't wish to use PhantomJS' paper size presets
  • Output must equal :pdf

Running

Two methods will return the data from a PhantomJS render, PhantomStatic.as_file and as_str. As file will provide a Tempfile object, and as_str will provide a string of the read() IO file.

Both take in the address of the page and a optional PhantomStatic::Builder block.

# use default options
file = PhantomStatic.as_file "http://google.com"

file2 = PhantomStatic.as_file "http://google.com" do |c|
  c.output = :pdf
  c.A3
  c.landscape
end

Credit

phantom-static's People

Contributors

callumj avatar

Watchers

Pankaj Bagwan avatar 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.