A seductive API for converting HTML documents into specified format. Relies on nginx's XSendfile for delivering converted documents.
GET /render
url
- The resource that should be converted to specified format. Required.
filename
- Filename of the rendered document. Required.
format
- Output format. Defaults to pdf, the other valid formats are jpg and png.
options
- Options for renderer, see below.
key
- A base64 encoded string of a HMAC digest of ENV['DOC_JUAN_SECRET'] and the parameters sorted by name.
require 'openssl'
sha1 = OpenSSL::Digest::Digest.new('sha1')
key = OpenSSL::HMAC.hexdigest(sha1, SECRET, 'filename:test-options_title:Test-url:http://example.com')
width
- Page width in millimeters.height
- Page height in millimeters.username
- Username for HTTP authenticationpassword
- Password for HTTP authentication
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.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
.
quality
- JPEG Quality of rendered file, should be 0 to 100
/render?url=http://example.com/document.html&filename=a-document&options[page_size]=A4&key=ABCDEFG
HTTP/1.1 200 OK
Date: Wed, 20 Jun 2012 14:11:30 GMT
Content-Type: application/pdf
Content-Disposition: inline; filename="a-document.pdf"
Cache-Control: public,max-age=2592000
[pdf data]
Doc-Juan is configured by environment variables. The following config variables are available:
DOC_JUAN_SECRET
- secret for generating key.DOC_JUAN_DOCUMENT_PATH
- directory to put generated documents.DOC_JUAN_DOCUMENT_URI
- what path theDOC_JUAN_DOCUMENT_PATH
directory is available via nginx.
Example:
DOC_JUAN_SECRET=thesupersecret
DOC_JUAN_DOCUMENT_PATH=/app/shared/documents
DOC_JUAN_DOCUMENT_URI=/documents
Doc-Juan supports error notifications with AirBrake.
To enable AirBrake support, set the environment variable AIRBRAKE_API_KEY
to your airbrake api key.
- Ruby 1.9
- nginx
- wkhtmltopdf tested with v0.9.9
http://code.google.com/p/wkhtmltopdf/
http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html
http://wiki.nginx.org/XSendfile
- PNG output support
- Stats for detecting load
- 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