我正试图通过ring / compojure直接提供clj-http生成的文档。
我认为ring.util / piped-output-stream会起作用,但似乎我不明白这里的东西......
此:
(defn laminat-pdf-t
[natno]
(piped-input-stream
(fn [output-stream])
(pdf
[ {:title (str "Omanimali-Kuscheltierpass" natno)
:orientation :landscape
:size :a6
:author "Omanimali - Stefanie Tuschen"
:register-system-fonts true
}
;; [:svg {} (clojure.java.io/file
;; (str "/einbuergern/" natno "/svg" ))]
[:paragraph "Some Text"] ]
output-stream)))
(defn laminat-pdf
"generate individualized cuddly toy passport page"
[natno]
{:headers {"Content-Type" "application/pdf"}
:body (laminat-pdf-t natno)})
导致空洞反应......
我需要做些什么不同的事情?
谢谢,
的Mathias
答案 0 :(得分:5)
我认为您的代码中可能有一个不合适的括号(请查看下面的laminat-pdf-t
函数 - 我稍微调整了一下)。
这就是我所做的(首先用leiningen 2.3.4
创建一个名为pdf-play的项目)并在IE 11.0.9600.16521
,Firefox 28.0
和{{{{}}中正确显示PDF 1}}(所有在Windows上 - 抱歉这些是我安装的唯一浏览器,我没有Linux或Mac机,但我认为浏览器没有任何区别):
Chrome 33.0.1750.154
(defproject pdf-play "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.6"]
[clj-pdf "1.11.15"]]
:plugins [[lein-ring "0.8.10"]]
:ring {:handler pdf-play.handler/app})
然后在命令提示符下启动它,如下所示:
(ns pdf-play.handler
(:use compojure.core
ring.util.io
clj-pdf.core)
(:require [compojure.handler :as handler]
[compojure.route :as route]))
(defn laminat-pdf-t
[natno]
(piped-input-stream
(fn [output-stream]
(pdf
[{:title (str "Omanimali-Kuscheltierpass" natno)
:orientation :landscape
:size :a6
:author "Omanimali - Stefanie Tuschen"
:register-system-fonts true
}
;; [:svg {} (clojure.java.io/file
;; (str "/einbuergern/" natno "/svg" ))]
[:paragraph "Some Text"]]
output-stream))))
(defn laminat-pdf
"generate individualized cuddly toy passport page"
[natno]
{:headers {"Content-Type" "application/pdf"}
:body (laminat-pdf-t natno)})
(defroutes app-routes
(GET "/" [] (laminat-pdf 1234))
(route/resources "/")
(route/not-found "Not Found"))
(def app (handler/site app-routes))
并浏览了一下浏览器中有一个PDF文件" Some Text"印在里面。