Compare commits

...

4 commits
master ... wip

Author SHA1 Message Date
Gered 28931c1d7c update README with notes about absolute/relative custom font paths 2021-12-08 17:02:17 -05:00
Gered 76bbb1afec update how custom font paths are interpreted
i don't actually think it was possible to supply a relative path
with the way this worked before? now it definitely is, which is super
nice for loading fonts from the classpath.

absolute font paths can still be used if needed, but they absolutely
must include a scheme prefix, e.g. 'file:/path/to/font.ttf'
2021-12-08 16:59:09 -05:00
Gered da6d229734 bump jsoup dependency up to version 1.14.3 2021-12-08 16:38:42 -05:00
Gered 6d31abe213 bump openhtmltopdf dependencies up to version 1.0.10 2021-12-08 16:30:03 -05:00
5 changed files with 26 additions and 7 deletions

View file

@ -116,7 +116,7 @@ When set to a map, the map should include CSS styles for the HTML `<body>` 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

View file

@ -4,11 +4,11 @@
:license {:name "GNU Lesser General Public License v3.0"
:url "https://www.gnu.org/licenses/lgpl.html"}
:dependencies [[com.openhtmltopdf/openhtmltopdf-core "1.0.8"]
[com.openhtmltopdf/openhtmltopdf-pdfbox "1.0.8"]
[com.openhtmltopdf/openhtmltopdf-rtl-support "1.0.8"]
[com.openhtmltopdf/openhtmltopdf-svg-support "1.0.8"]
[org.jsoup/jsoup "1.12.1"]
:dependencies [[com.openhtmltopdf/openhtmltopdf-core "1.0.10"]
[com.openhtmltopdf/openhtmltopdf-pdfbox "1.0.10"]
[com.openhtmltopdf/openhtmltopdf-rtl-support "1.0.10"]
[com.openhtmltopdf/openhtmltopdf-svg-support "1.0.10"]
[org.jsoup/jsoup "1.14.3"]
[commons-io/commons-io "2.6"]
[hiccup "1.0.5"]]

View file

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

Binary file not shown.

View file

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