PDF: Started building system to allow custom DOMPDF font loading #6109

Merged
ssddanbrown merged 3 commits from dompdf_font_loading into development 2026-04-22 14:30:48 +02:00
ssddanbrown commented 2026-04-20 16:50:27 +02:00 (Migrated from github.com)

Adds a way for custom fonts to be loaded for use with DomPDF.

On export, BookStack scans the storage/fonts/dompdf folder for *.ttf font files, then for each attempts to build the required .ufm (font-metrics) file where they don't already exist.
Then it auto-converts the naming scheme to suit dompdf.

Considerations

This is just one side of things, making the font available. It would also need to be used in styles. We could attempt to auto-inject styles, but then things may get complex with factors like font ordering, different fonts for different uses etc...

Might be best, at least for now, if we provide guidance (alongside guidance for this system) on how to set the relevant styles (via custom HTML head content).

Custom head example:

<style>
.export-format-pdf.export-engine-dompdf * {
  font-family: 'Noto Sans Thai', 'DejaVu Sans', sans-serif;
}
</style>

Todo

  • Cover with testing
  • Consider potential breaks due to new storage/fonts sub-folders.
    • Related to #6023
    • Will maybe cause the same issues, but think it's important that these folders pre-exist (for users to add fonts to) rather than generate at run-time, but this time we can pre-prepare with an update advisory. Plus the occurance is lesser here as it's only at PDF export time.
  • Ensure lack of write access creates clear error message.

Docs Updates

  • Upgrade advisory: Due to some changes in how fonts are used for exports, you may need to ensure that the storage/fonts folder (and all folders within that) are accessible & writable to the web-server.
  • Document process for adding/using new fonts, including the font naming scheme, and how to set the required CSS.
Adds a way for custom fonts to be loaded for use with DomPDF. On export, BookStack scans the `storage/fonts/dompdf` folder for `*.ttf` font files, then for each attempts to build the required `.ufm` (font-metrics) file where they don't already exist. Then it auto-converts the naming scheme to suit dompdf. ### Considerations This is just one side of things, making the font available. It would also need to be used in styles. We could attempt to auto-inject styles, but then things may get complex with factors like font ordering, different fonts for different uses etc... Might be best, at least for now, if we provide guidance (alongside guidance for this system) on how to set the relevant styles (via custom HTML head content). Custom head example: ```html <style> .export-format-pdf.export-engine-dompdf * { font-family: 'Noto Sans Thai', 'DejaVu Sans', sans-serif; } </style> ``` ### Todo - [x] Cover with testing - [x] Consider potential breaks due to new `storage/fonts` sub-folders. - Related to #6023 - Will maybe cause the same issues, but think it's important that these folders pre-exist (for users to add fonts to) rather than generate at run-time, but this time we can pre-prepare with an update advisory. Plus the occurance is lesser here as it's only at PDF export time. - [x] Ensure lack of write access creates clear error message. ### Docs Updates - Upgrade advisory: Due to some changes in how fonts are used for exports, you may need to ensure that the `storage/fonts` folder (and all folders within that) are accessible & writable to the web-server. - Document process for adding/using new fonts, including the font naming scheme, and how to set the required CSS.
Sign in to join this conversation.
No description provided.