Skip to content
English
  • There are no suggestions because the search field is empty.

[Public] Embedding Custom Fonts in PDFs on Linux with IronPDF

How to embed custom fonts in generated PDF inside Linux based Docker Containers

 

IronPDF allows you to embed custom fonts in your generated PDFs. While this works seamlessly on Windows, developers often encounter issues when deploying to Linux environments, especially inside Docker containers or Kubernetes clusters.

When doing so, users might encounter the following:

  • Fonts embedded correctly when generating PDFs on Windows.

  • Fonts not embedded when generating PDFs inside a Linux-based Docker container.

  • Instead of Arial or the intended font, Linux rendered DejaVu Sans, which is a common fallback font used.

 

Root Cause

On Linux systems, especially in Docker containers, fonts must be explicitly installed or referenced. If a font isn’t available to the rendering engine or isn’t properly embedded in the HTML, IronPDF will substitute a default system font (like DejaVu Sans), causing visual differences and embedding failures.

 

Embedding Fonts on Linux

 

1. Install Microsoft Core Fonts (Arial, Times New Roman, etc.)

Add the following to your Dockerfile to install fonts commonly used on Windows:

RUN apt update && apt install -y ttf-mscorefonts-installer

 

This ensures that fonts like Arial are present and accessible on Linux.

 

2. Embed Custom Fonts (e.g., Poppins, Roboto, etc.)

If you want to use non-system fonts (like Poppins), embed them using @font-face in your HTML:

<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: 'Poppins';
src: url('fonts/Poppins-Regular.ttf'); /* Ensure this path is correct */
}
p {
font-family: 'Poppins';
font-size: 70px;
}
</style>
</head>
<body>
<p>Custom font</p>
</body>
</html>

Place the .ttf font file in a relative path accessible to the HTML renderer (e.g., bundled inside your Docker image or hosted via web server).

 

3. Use PdfCssMediaType.Print

Ensure your rendering uses the Print CSS media type to ensure print-specific styles (like font-face declarations) are applied:

renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

 

 

Verifying Font Embedding

After generating your PDF:

  • Open the PDF in Adobe Acrobat or a browser PDF viewer.

  • Check Document Properties > Fonts to see if your custom font is embedded or substituted.

Compare outputs from both environments (Windows and Linux) to verify consistent rendering.

Additional Tips

  • Make sure fonts are readable and accessible in your Docker container.

  • You may need to install additional fonts or copy custom fonts into the container during build.

  • Test with the latest version of IronPDF for the most accurate rendering and font support.