Dragonfly PhantomJS

Build Status Gem Version Coverage Status

This Dragonfly plugin uses PhantomJS headless browser to convert HTML or SVG documents to GIF, JPEG, PDF or PNG

If passed an SVG and the viewport_size is not specified in the options, the viewport_size is automatically set to the dimensions of the SVG file.

IMPORTANT: Requires PhantomJS


Add this line to your application's Gemfile:

gem 'dragonfly_phantomjs'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dragonfly_phantomjs


Add the plugin to Dragonfly:

Dragonfly.app.configure do
  plugin :phantomjs


html.rasterize(format, options)
svg.rasterize(format, options)

Formats: :gif, :jpeg, :pdf, :png


:border         - {number, string}, defaults to 0, supported units are 'mm', 'cm', 'in', 'px'
:format         - {string}, defaults to 'A4', supported formats are 'A4', 'A3', 'A5', 'Legal', 'Letter', 'Tabloid'
:paper_size     - {string}, 'width*height', '300mm*300mm', supported units are 'mm', 'cm', 'in', 'px'
:viewport_size  - {string}, 'width*height', '1440*900'
:zoom_factor    - {number}, defaults to 1
:header         - {hash}, {height: '10mm', content: 'Header content', hide_on: [1]}
:footer         - {hash}, {height: '10mm', content: 'Footer content', hide_on: [1]}

For now refer to the phantomjs api for more details on how to construct the string for the header/footer. You can use pageNum and numPages as variables. The hide_on option takes an array of page numbers where the header and/or footer will be hidden.


  1. Fork it ( https://github.com/tomasc/dragonfly_phantomjs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request