Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use custom fonts in a craft setup #138

Open
JulieVelghe opened this issue Jun 3, 2024 · 1 comment
Open

How to use custom fonts in a craft setup #138

JulieVelghe opened this issue Jun 3, 2024 · 1 comment
Labels

Comments

@JulieVelghe
Copy link

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:

<style>{{ source('_pdf/assets/css/layout.css') }}</style>

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants