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. <img> 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
This commit is contained in:
Gered 2018-07-03 11:15:36 -04:00
parent 01f12c6f2c
commit ce2a7f78fe

View file

@ -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