Skip to content

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

Merged
ssddanbrown merged 3 commits intodevelopmentfrom
dompdf_font_loading
Apr 22, 2026
Merged

PDF: Started building system to allow custom DOMPDF font loading#6109
ssddanbrown merged 3 commits intodevelopmentfrom
dompdf_font_loading

Conversation

@ssddanbrown
Copy link
Copy Markdown
Member

@ssddanbrown ssddanbrown commented Apr 20, 2026

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 Article inaccessible after updating to Version 25.12.4 #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.

@ssddanbrown ssddanbrown added this to the Next Feature Release milestone Apr 22, 2026
@ssddanbrown ssddanbrown self-assigned this Apr 22, 2026
@ssddanbrown ssddanbrown merged commit 4b62459 into development Apr 22, 2026
20 checks passed
@ssddanbrown ssddanbrown deleted the dompdf_font_loading branch April 22, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant