Created
August 4, 2009 02:43
-
-
Save lrenn/160995 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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