diff --git a/README.md b/README.md index 67712e8..40f19c7 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ When set to a map, the map should include CSS styles for the HTML `` tag o default styles shown above. Two additional keys can be set in this map: * `:styles` a single file or vector of filenames pointing to any additional CSS stylesheets to be included. -* `:fonts` a sequence of maps of the form `{:font-family "font-family-name-here" :src "/path/to/custom-font.ttf"}` which allows you to use custom fonts in other CSS style definitions using the `:font-family` name specified here. +* `:fonts` a sequence of maps of the form `{:font-family "font-family-name-here" :src "file:/path/to/custom-font.ttf"}` which allows you to use custom fonts in other CSS style definitions using the `:font-family` name specified here. Note that to use a relative font path with `:src`, just drop the `file:` prefix and of course don't include a leading slash. If you want to include your own custom CSS styles without the base `htmltopdf-base.css` stylesheet being included nor any other base styles being injected, then you can specify either a single CSS filename or a vector of multiple CSS diff --git a/project.clj b/project.clj index 0ab8545..82c7b3a 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject clj-htmltopdf "0.2.1" +(defproject clj-htmltopdf "0.2" :description "Simple Clojure wrapper for Open HTML to PDF" :url "https://github.com/gered/clj-htmltopdf" :license {:name "GNU Lesser General Public License v3.0" diff --git a/src/clj_htmltopdf/options.clj b/src/clj_htmltopdf/options.clj index e061a41..5588441 100644 --- a/src/clj_htmltopdf/options.clj +++ b/src/clj_htmltopdf/options.clj @@ -209,7 +209,8 @@ (fn [{:keys [font-family src]}] ["@font-face" {:font-family font-family - :src (str "url(\"" (utils/string->url-or-file src) "\")")}]) + ; TODO: maybe should use whatever the current uri-resolver function is for this ? + :src (str "url(\"" src #_(utils/string->url-or-file src) "\")")}]) fonts))) (defn build-base-css-styles diff --git a/test-resources/FirstTimeWriting-DOy8d.ttf b/test-resources/FirstTimeWriting-DOy8d.ttf new file mode 100644 index 0000000..4aead4e Binary files /dev/null and b/test-resources/FirstTimeWriting-DOy8d.ttf differ diff --git a/test/clj_htmltopdf/test/pdfdoc_manual_tests.clj b/test/clj_htmltopdf/test/pdfdoc_manual_tests.clj index 6017a0e..3b7f633 100644 --- a/test/clj_htmltopdf/test/pdfdoc_manual_tests.clj +++ b/test/clj_htmltopdf/test/pdfdoc_manual_tests.clj @@ -185,3 +185,21 @@ :page nil :debug {:display-html? true :display-options? true}}))) + +(comment + (let [filename "test-custom-font.pdf" + relative-font-path "FirstTimeWriting-DOy8d.ttf" + absolute-font-path (str (io/resource relative-font-path))] + (println "\n **** " filename " **** \n") + (->pdf + [:div + [:h1 "Custom fonts!"] + [:p {:style "font-family: custom-font-relative"} "This should be styled in a custom font, specified via relative path!"] + [:p {:style "font-family: custom-font-absolute"} "This should also be styled with a custom font, but specified via an absolute path!"]] + filename + {:styles {:fonts [{:font-family "custom-font-relative" + :src relative-font-path} + {:font-family "custom-font-absolute" + :src relative-font-path}]} + :debug {:display-html? true + :display-options? true}})))