verbb / wishlist

A Craft CMS plugin for wishlists for your users to save things to
Other
11 stars 12 forks source link

How to use custom fonts in a craft setup #138

Open JulieVelghe opened 5 months ago

JulieVelghe commented 5 months ago

Question

Hello, for a clients website, we would like to be be able to style the generated pdf's with a custom font. For our pdf settings (in wishlist.php), we have the following settings: // PDF 'pdfFilenameFormat' => 'karakters-{id}', 'pdfPath' => '_pdf/template', 'pdfAllowRemoteImages' => true, 'pdfPaperSize' => 'A4', 'pdfPaperOrientation' => 'portrait',

in our template twig file we have for example this code: @font-face { font-family: 'Mona Sans Wide'; font-style: italic; font-weight: 800; src: url({{ "#{currentSite.baseUrl}assets/dist/fonts/Mona-Sans/Mona-Sans-ExtraBoldWideItalic.ttf" }}) format('truetype'); }

and we use a css file like this:

screenshot of our folder structure: image

Unfortunately the fonts get ignored. Is there any way to get to use those ttf files?

Additional context

No response

engram-design commented 5 months ago

I wouldn't recommend using self-hosted fonts for PDFs, and I believe there's performance hits with DomPDF in doing so. You should also use inline CSS in the PDF's Twig template, not a separate CSS file.

You may also need the isRemoteEnabled => true config setting as well. You might want to Google around for DomPDF and using custom fonts.