mat*_*asp 7 pdf clojure compojure ring clj-pdf
我正在尝试通过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)})
Run Code Online (Sandbox Code Playgroud)
导致空洞的回应......
我需要做些什么不同的事情?
谢谢,
马蒂亚斯
我想你的代码中可能有一个不合适的括号(看看laminat-pdf-t下面的函数 - 我稍微调整了一下).
这正是我所做的(首先用leiningen创建一个2.3.4名为pdf-play 的项目),它正确地显示了PDF IE 11.0.9600.16521,Firefox 28.0并且Chrome 33.0.1750.154(所有在Windows上 - 抱歉这些是我安装的唯一浏览器,我没有Linux或者Mac盒子,但我不认为浏览器有任何区别):
(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})
Run Code Online (Sandbox Code Playgroud)
(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))
Run Code Online (Sandbox Code Playgroud)
然后在命令提示符下启动它,如下所示:
lein ring server
Run Code Online (Sandbox Code Playgroud)
并在浏览器中查看,其中印有"Some Text"的PDF.