https://github.com/tomasc/dragonfly_phantomjs
Dragonfly PhantomJS plugin that converts .html or .svg to .gif, .jpeg, .pdf or .png.
https://github.com/tomasc/dragonfly_phantomjs
Last synced: about 1 year ago
JSON representation
Dragonfly PhantomJS plugin that converts .html or .svg to .gif, .jpeg, .pdf or .png.
- Host: GitHub
- URL: https://github.com/tomasc/dragonfly_phantomjs
- Owner: tomasc
- License: mit
- Created: 2014-07-09T08:59:36.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-06-12T15:20:45.000Z (about 9 years ago)
- Last Synced: 2025-04-03T22:23:11.003Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 26.4 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dragonfly PhantomJS
[](https://travis-ci.org/tomasc/dragonfly_phantomjs) [](http://badge.fury.io/rb/dragonfly_phantomjs) [](https://coveralls.io/r/tomasc/dragonfly_phantomjs)
This [Dragonfly](https://github.com/markevans/dragonfly) plugin uses [PhantomJS](https://github.com/ariya/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](http://phantomjs.org)
## 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:
```ruby
Dragonfly.app.configure do
plugin :phantomjs
end
```
## Rasterize
```ruby
html.rasterize(format, options)
svg.rasterize(format, options)
```
Formats: `:gif`, `:jpeg`, `:pdf`, `:png`
Options:
```Ruby
: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](http://phantomjs.org/api/webpage/property/paper-size.html) 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
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