My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

; Copyright (c) Zeljko Zirikovic. All rights reserved.
; You must not remove this notice, or any other, from this software.

(ns com.revolucion.movieindexer.pdf
"MovieIndexer PDF exporter. Experimental."
(:use [clojure.contrib.duck-streams :as fileio]
[clojure.contrib.java-utils :as jutils])
(:import
(javax.xml.parsers DocumentBuilderFactory)
(java.io FileOutputStream StringReader)
(org.xml.sax InputSource)
(org.xhtmlrenderer.pdf ITextRenderer)))

; Currently not used.
; Test: (save-as-pdf (jutils/file "C:\\") "fajl.pdf" "<html><body><p>aaaa</p></body></html>")

(defn save-as-pdf [dir file-name text]
(let [pdf-file (jutils/file dir file-name)
out (FileOutputStream. pdf-file)
document (.. DocumentBuilderFactory (newInstance) (newDocumentBuilder) (parse (InputSource. (StringReader. text))))
renderer (ITextRenderer.)]
(do
(.setDocument renderer document nil)
(.layout renderer)
(.createPDF renderer out)
(.close out)
(println (str "Saved movie description as: " pdf-file)))))

Change log

r3 by joshefin on May 13, 2010   Diff
First commit
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1034 bytes, 29 lines
Powered by Google Project Hosting