Skip to content

Instantly share code, notes, and snippets.

@lrenn
Created August 4, 2009 02:43
Show Gist options
  • Save lrenn/160995 to your computer and use it in GitHub Desktop.
Save lrenn/160995 to your computer and use it in GitHub Desktop.
(import 'java.io.ByteArrayOutputStream)
(import 'java.io.ByteArrayInputStream)
(import 'com.lowagie.text.Document)
(import 'com.lowagie.text.DocumentException)
(import 'com.lowagie.text.Paragraph)
(import 'com.lowagie.text.pdf.PdfWriter)
(defn gen-pdf-stream [title]
(let [doc (new Document)
stream (ByteArrayOutputStream.)
writer (PdfWriter/getInstance doc stream)]
(.open doc)
(.add doc (Paragraph. title))
(.close doc)
(ByteArrayInputStream. (.toByteArray stream))))
(defroutes example-app
(GET "/pdf" [{:headers {"Content-Type" "application/pdf"}}
(gen-pdf-stream "Lorum Ipsum")]))
(run-server {:port 8080} "/*" (servlet example-app))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment