Configuring Custom Fonts
PDF files are supposed to be rendered exactly the same, no matter which PDF viewer you’re using. One reason why this is the case is because a PDF file can embed the fonts required to render it.
However, sometimes — due to the size or other considerations — fonts aren’t embedded, which makes the PDF viewer look for fonts on the current system. Depending on the fonts that are available, this can cause rendering problems.
While the best option is to always embed fonts in the PDF, this isn’t always possible, especially if you’re working with third-party PDF files. This is where custom font path support comes in.
A font that includes all characters is usually more than 200 MB in size. That’s tough for a web browser. To render fonts effectively (and to make this work at all in older browsers), we need a server. That’s why we built custom font path support into PSPDFKit Server.
You can expose a directory of fonts from the host machine to the Docker container by adding the following to your
pspdfkit: volumes: - /font-directory-path-on-the-host:/custom-fonts
Note that after you add the fonts, you might still see the PDFs rendered with an incorrect font in the Web viewer. This is because there are multiple layers of caching involved, and you’re still seeing the old rendered page. In order to solve this, follow these steps:
Clear the browser cache — this clears rendering artifacts cached by the browser.
Restart the PSPDFKit Server — this clears the in-memory Server cache for rendered pages.
Only if you use Redis — delete the keys starting with the
PSPDFKit-PageCache-prefixes to remove all rendered artifacts cached by PSPDFKit Server. Note that there may be considerable performance implications in the case of high-volume deployments (since all the previously cached pages will need to be rerendered by PSPDFKit Server), in which case you should apply Redis eviction policies that will remove the keys from the cache gradually.
The font directory can be any directory that is accessible to your app, and all
.otf files will be added to the font list of PSPDFKit.
“Core fonts for the Web was a project started by Microsoft in 1996 to create a standard pack of fonts for the World Wide Web. It included the proprietary fonts Andalé Mono, Arial, Arial Black, Comic Sans MS, Courier New, Georgia, Impact, Times New Roman, Trebuchet MS, Verdana and Webdings, all of them in TrueType font format…”
While Microsoft no longer offers these files directly, they can be legally downloaded. The EULA prohibits redistribution, but you can download them and add them to our server product as a custom font. You can use free software such as 7-Zip to extract the TTF font files from the downloaded packages.
These fonts are widely used on the web and PDF files and will improve render fidelity for PDF documents that use them.