From ce2a7f78fe6d41482eae2e55740f5e0a91686eb9 Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 3 Jul 2018 11:15:36 -0400 Subject: [PATCH] fix default base-uri option to point to "resources" dir on classpath this should fix the most common usage scenario where you would probably like to be able to use e.g. tags to point to image files that exist locally within your project's "resources" directory somewhere. the :base-uri option can still be overridden in the call to ->pdf for the more uncommon scenarios --- src/clj_htmltopdf/options.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/clj_htmltopdf/options.clj b/src/clj_htmltopdf/options.clj index 970820c..4dab1a9 100644 --- a/src/clj_htmltopdf/options.clj +++ b/src/clj_htmltopdf/options.clj @@ -8,6 +8,14 @@ [org.jsoup.nodes Document Element] [org.jsoup.parser Tag])) +(defn- get-base-resource-path-url + [] + (if-let [css-resource (io/resource "htmltopdf-base.css")] + (-> (io/file css-resource) + (.getParentFile) + (.toURL)) + "")) + (defn append-style-tag! ^Element [^Element parent css-styles] (let [element (.appendElement parent "style")] @@ -32,7 +40,7 @@ (def default-options {:logging? false - :base-uri "" + :base-uri (get-base-resource-path-url) :styles true :page {:size :letter :orientation :portrait