/ring-wicked-pdf

Plugin to render PDF from HTML using wkhtmltopdf

Primary LanguageClojure

ring-wicked-pdf

Simple (m|f)iddleware for sending a webpage to wkhtmltopdf for rendering as a PDF file

Usage

Add [ring-wicked-pdf "0.4.2"] to your leingingen dependencies.

Require it via (:require [ring.wicked.pdf :as wicked])

"wkhtmltopdf" needs to be in your webapp's binary executable path.

To render a page as a pdf, simply call (wicked/as-pdf contents) with the full html contents to render with wkhtmltopdf.

##Compojure Example The following route renders /pdf directly as a pdf.

(GET "/pdf" [] (wicked/as-pdf "<html><body><h1>Hello World</h1></body></html>"))

##Noir Example

The following renders the /pdf page directly to the browser as a pdf file.

(defpage "/" []
  "<html><body><h1>Hello World</h1></html></body>")

(defpage "/pdf" []
  (resp/content-type "application/pdf" (wicked/as-pdf (render "/"))))

##Options You can optionally pass in:

Itemoptiondefaultpossibilities
resource directory:resource-dir"resources/public/"<sub-directory string>
tmp directory:tmp-dir"/tmp"<directory string>
page orientation:orientation:portrait:portrait :landscape
io-type (file or stream):io-type:stream :stream :file
papersize:papersize"Letter""Letter", "A4", etc.

(wicked/as-pdf contents :orientation :landscape :resource-dir "my-resource-subdir" :tmp-dir "my-temp-dir" :io-type :file)

NB: Resources (css/images) default to "resources/public/" path in the main directory of your web app.

License

Copyright (C) 2013 Greg Berenfield

Distributed under the Eclipse Public License, the same as Clojure.