Fonts
Including Fonts
Fonts are installed into the deployed image. Place additional font files in the
repository /fonts folder in .otf or .ttf format and rebuild the image.
The Docker images copy those files into the system font directories and refresh
the font cache so WeasyPrint can find them when rendering generated documents.
Font Families Included
Below is a list of all currently included font families and typical CSS usage:
Font Family |
Suggested fallback |
CSS Usage |
|---|---|---|
Futura PT |
|
|
Gotham |
|
|
Metropolis |
|
|
Sentinel |
|
|
Using Fonts in a Document
Use fonts in the css_template.content field sent to /pdf/generate. The
HTML references normal classes or elements; the CSS chooses the font family and
weight.
{
"data": {
"title": "Invoice",
"customer": "Alice Example"
},
"html_template": {
"filename": null,
"content": "<html><body><h1>{{ data.title }}</h1><p class=\"customer\">{{ data.customer }}</p></body></html>"
},
"css_template": {
"filename": null,
"content": "body { font-family: 'Futura PT', 'DejaVu Sans', sans-serif; } h1 { font-family: 'Sentinel', 'DejaVu Serif', serif; font-weight: 700; }"
}
}
The same pattern can be written more readably in a CSS file or string before it is sent in the request:
body {
font-family: 'Futura PT', 'DejaVu Sans', sans-serif;
font-weight: 400;
}
h1 {
font-family: 'Sentinel', 'DejaVu Serif', serif;
font-weight: 700;
}
.customer {
font-family: 'Futura PT', 'DejaVu Sans', sans-serif;
font-weight: 500;
}
WeasyPrint uses the system font cache when the images are built. For bundled
families, prefer the font family names shown above. If you need to force a
specific file, declare an @font-face rule in the same CSS:
@font-face {
font-family: 'Futura PT';
src: url('file:///usr/share/fonts/truetype/FuturaCyrillicBook.ttf') format('truetype');
font-weight: 400;
}
@font-face {
font-family: 'Futura PT';
src: url('file:///usr/share/fonts/truetype/FuturaCyrillicBold.ttf') format('truetype');
font-weight: 700;
}
body {
font-family: 'Futura PT', 'DejaVu Sans', sans-serif;
}
Available Futura PT files include Book, Light, Medium, Demi, Bold, Extra Bold,
and Heavy. Use CSS font-weight values that match the intended weight, such
as 300 for Light, 400 for Book, 500 for Medium, 600 for Demi,
700 for Bold, 800 for Extra Bold, and 900 for Heavy.
Note
The only other fonts available in the very basic Linux image used to run Influxion are the DejaVu fonts
(https://dejavu-fonts.github.io/). All other fonts must be included in the /fonts folder as described above.
Refer to the /fonts folder in the repository for the actual font files.