Giter VIP home page Giter VIP logo

doc-juan's Introduction

Doc-Juan

A seductive API for converting HTML documents into specified format. Relies on nginx's XSendfile for delivering converted documents.

Endpoint

Render

GET /render

Parameters

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.

Generating a valid key

require 'openssl'
sha1 = OpenSSL::Digest::Digest.new('sha1')
key = OpenSSL::HMAC.hexdigest(sha1, SECRET, 'filename:test-options_title:Test-url:http://example.com')

Options

  • width - Page width in millimeters.
  • height - Page height in millimeters.
  • username - Username for HTTP authentication
  • password - Password for HTTP authentication
PDF specific
  • title - PDF title, defaults to the title of the HTML document.
  • print_stylesheet - If set to true 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 or portrait. Defaults to portrait.
  • lowquality - Renders the pdf in low quality if set to true.
JPG specific
  • quality - JPEG Quality of rendered file, should be 0 to 100

Example

/render?url=http://example.com/document.html&filename=a-document&options[page_size]=A4&key=ABCDEFG

Returned data

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]	

Configuration

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 the DOC_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

Error notifications

Doc-Juan supports error notifications with AirBrake.

To enable AirBrake support, set the environment variable AIRBRAKE_API_KEY to your airbrake api key.

Requirements

Helper for generating Doc-Juan URLs

Doc-Juan-Helper

Reference resources

http://blog.jcoglan.com/2012/06/09/why-you-should-never-use-hash-functions-for-message-authentication/

http://code.google.com/p/wkhtmltopdf/

http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html

http://wiki.nginx.org/XSendfile

Future

  • PNG output support
  • Stats for detecting load

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

doc-juan's People

Contributors

arvida avatar

Stargazers

David Turnbull avatar

Watchers

Jonas Nicklas avatar Fred Bergman avatar Joel Junström avatar James Cloos avatar Alexander Berthelsen avatar Jesper Nilsson avatar Tom Baro avatar

Forkers

varvet

doc-juan's Issues

Extract the options related code in DocJuan::Pdf

Maybe we should have an PdfOptions object to handle the defaults / whitelist / sanitation.

CommandLineOptions is not necessary until DocJuan::Pdf#generate so we could do with

def generate
  unless exists?
    path = File.join directory, identifier
    args = [self.class.executable]
    args << %Q{"#{url}"}
    args << %Q{"#{path}"}
    args << CommandLineOptions.new self.options
    args << '--quiet'

    run_command args.join(' ')
  end

  generated
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.