Dragonfly PhantomJS
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
Installation
Add this line to your application's Gemfile:
gem 'dragonfly_phantomjs'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dragonfly_phantomjs
Usage
Add the plugin to Dragonfly:
Dragonfly.app.configure do
plugin :phantomjs
endRasterize
html.rasterize(format, options)
svg.rasterize(format, options)Formats: :gif, :jpeg, :pdf, :png
Options:
: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.
Contributing
- Fork it ( https://github.com/tomasc/dragonfly_phantomjs/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request