A small helper class to generate urls to a Doc-Juan instance.
Give a url, a filename and options the DocJuan to generate a url to a DocJuan server including the calculated hmac key.
You need to provide your secret key and the host of the Doc-Juan instance.
DocJuan.configure do |config|
config.host = 'doc-juan.it'
config.secret = 'my-special-secret'
end
If you are using Rails an initializer would be the appropriate place for this.
If your site is behind HTTP Basic Authentication DocJuan.config.username
and DocJuan.config.password
is your friends.
BEWARE! Setting these will append your credentials to every DocJuan url generated and, depending on how you use them, can be fully visible to your users. The authentication credentials is foremost available for testing in your staging environment.
The DocJuan.url
method generates a url to your Doc-Juan instance. It takes an url and a filename as the required arguments. You can supply an (optional) hash of options as the third argument.
Valid options are:
title
- PDF title, defaults to the title of the HTML document.print_stylesheet
- If set totrue
the print stylesheet of the resource will be used.width
- Page width in millimeters.height
- Page height in millimeters.size
- a4, letter etc. This will be ignored if width and height is set. List of sizes.orientation
-landscape
orportrait
. Defaults to portrait.lowquality
- Renders the pdf in low quality if set totrue
.format
- Output file format,pdf
orjpg
. Defaults topdf
.
url = DocJuan.url 'http://example.com', 'example.pdf'
url = DocJuan.url 'http://example.com', 'le-pdf.pdf', title: 'My PDF-version', size: 'A5'
Add this line to your application's Gemfile:
gem 'doc_juan'
And then execute:
$ bundle
Or install it yourself as:
$ gem install doc_juan
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request