(ns pdf-try.core
(:use clj-pdf.core)
(:require clojure.java.io))
(defn gen-pdf []
(let [superman (javax.imageio.ImageIO/read "sample_logos/batman.jpeg")
batman (javax.imageio.ImageIO/read "sample_logos/superman.jpeg")]
(println (new java.util.Date))
(pdf [{} (for [i (range 80000)]
(do [:paragraph
[:image superman]
[:image batman]]))] "super.pdf")
(println (new java.util.Date))))
(defn -main
"I don't do a whole lot."
[& args]
(println "Hello, World!")
(gen-pdf))
我得到了:
Exception in thread "main" java.lang.IllegalArgumentException: No matching method found: read
What am I missing here ?
答案 0 :(得分:1)
因为没有这样的静态read
方法接受String
作为ImageIO
类中的参数。使用该路径创建一个文件,并将File作为参数传递。
(defn gen-pdf []
(let [superman (javax.imageio.ImageIO/read "sample_logos/batman.jpeg")
batman (javax.imageio.ImageIO/read (java.io.File. "sample_logos/superman.jpeg"))]
(println (java.util.Date.))
(pdf [{} (for [i (range 80000)]
(do [:paragraph
[:image superman]
[:image batman]]))] "super.pdf")
(println (java.util.Date.))))
并且,您错误地从Clojure调用Java类构造函数。您需要使用类似(Classname. args*)
来从Clojure调用Java类构造函数。有关详细信息,请查看clojure-java-interop