DEV Community

IronSoftware
IronSoftware

Posted on

Manage Fonts in PDF with C# (.NET Guide)

Our brand guidelines mandated Montserrat font. PDFs displayed correctly on our machines but broke on client systems. They didn't have Montserrat installed. Text rendered in Times New Roman instead.

Font embedding solved this. Here's how to manage fonts in PDFs.

How Do I Embed Custom Fonts in PDFs?

Use EnableWebFonts for HTML-to-PDF conversion:

using IronPdf;
// Install via NuGet: Install-Package IronPdf

var renderer = new [ChromePdfRenderer](https://ironpdf.com/blog/videos/how-to-render-html-string-to-pdf-in-csharp-ironpdf/)();
renderer.RenderingOptions.EnableWebFonts = true;

var html = @"
<style>
@font-face {
    font-family: 'Montserrat';
    src: url('https://fonts.gstatic.com/s/montserrat/v25/JTUSjIg1_i6t8kCHKm459WlhyyTh89Y.woff2');
}
body { font-family: 'Montserrat', sans-serif; }
</style>
<h1>Brand Document</h1>";

var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("embedded-font.pdf");
Enter fullscreen mode Exit fullscreen mode

The font embeds in the PDF. Displays correctly anywhere.

Why Embed Fonts in PDFs?

Brand consistency: Custom corporate fonts display everywhere
Cross-platform compatibility: PDFs look identical on all systems
Typography preservation: Avoid font substitution issues
Professional appearance: Maintain design integrity

I embed all custom fonts for client-facing documents. Eliminates "font not found" issues.

What Are Standard PDF Fonts?

PDFs support 14 standard fonts (Base 14) that work without embedding:

Serif fonts: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
Sans-serif fonts: Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
Monospace fonts: Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique
Symbol fonts: Symbol, ZapfDingbats

Use these to minimize file size:

var html = "<style>body { font-family: Helvetica, sans-serif; }</style><p>Text</p>";

var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

No embedding needed. All PDF viewers support these fonts natively.

How Do I Load Custom Font Files?

Load TTF or OTF files from disk:

var html = @"
<style>
@font-face {
    font-family: 'CustomFont';
    src: url('file:///C:/Fonts/CustomFont.ttf');
}
body { font-family: 'CustomFont', sans-serif; }
</style>
<h1>Custom Typography</h1>";

renderer.RenderingOptions.EnableWebFonts = true;
var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

The font embeds automatically when EnableWebFonts is true.

Can I Embed Google Fonts?

Yes, reference them in your HTML:

var html = @"
<link href='https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap' rel='stylesheet'>
<style>
body { font-family: 'Roboto', sans-serif; }
</style>
<h1>Google Fonts Work</h1>";

renderer.RenderingOptions.EnableWebFonts = true;
var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

IronPDF downloads and embeds the font during PDF generation.

What's the Impact on File Size?

Embedded fonts: Add 50-500KB per font depending on character set
Standard fonts: Zero bytes (not embedded)
Subsetted fonts: Only includes used characters, reduces size

For a 200-page document with Montserrat embedded: ~150KB overhead. Usually acceptable for brand consistency.

I use standard fonts for internal reports (smaller files) and custom fonts for client deliverables (brand compliance).

How Do I Reduce Font File Size?

Use font subsetting (only embed used characters):

renderer.RenderingOptions.EnableWebFonts = true;
renderer.RenderingOptions.CreatePdfFormsFromHtml = false; // Reduces overhead
Enter fullscreen mode Exit fullscreen mode

Or use web-safe fallbacks:

body { font-family: 'CustomFont', Arial, sans-serif; }
Enter fullscreen mode Exit fullscreen mode

If the custom font fails, Arial substitutes.

Can I Replace Fonts in Existing PDFs?

IronPDF focuses on generation, not post-processing font replacement. For existing PDFs, use specialized tools like Adobe Acrobat or Aspose.PDF.

To "replace" fonts, regenerate the PDF with different fonts:

// Original HTML with Montserrat
var htmlOld = "<style>body { font-family: 'Montserrat'; }</style><p>Text</p>";

// New HTML with Arial
var htmlNew = "<style>body { font-family: 'Arial'; }</style><p>Text</p>";

var pdf = renderer.RenderHtmlAsPdf(htmlNew);
Enter fullscreen mode Exit fullscreen mode

How Do I Handle Missing Fonts?

If a font isn't available, PDFs substitute with a default font (usually Arial or Times). To prevent this:

  1. Embed fonts during generation
  2. Include fallback fonts in your CSS
  3. Test on clean systems without your fonts installed
body {
    font-family: 'Montserrat', 'Helvetica', 'Arial', sans-serif;
}
Enter fullscreen mode Exit fullscreen mode

Browsers try each font in order until one is found.

Can I Use System Fonts?

Yes, if installed on the server:

var html = "<style>body { font-family: 'Segoe UI', sans-serif; }</style><p>Windows Font</p>";

renderer.RenderingOptions.EnableWebFonts = true;
var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

Segoe UI embeds from the Windows system fonts. Works only if the font is installed where IronPDF runs.

How Do I Verify Fonts Embedded Correctly?

Open the PDF in Adobe Acrobat: File → Properties → Fonts tab. Lists all embedded fonts.

Or check programmatically:

var pdf = PdfDocument.FromFile("document.pdf");

// IronPDF doesn't expose font inspection directly
// Use third-party tools or Acrobat for verification
Enter fullscreen mode Exit fullscreen mode

For testing, generate a sample PDF and inspect it manually.

What About Icon Fonts?

Icon fonts (Font Awesome, Material Icons) work like any other font:

var html = @"
<link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css' rel='stylesheet'>
<i class='fas fa-check'></i> Completed";

renderer.RenderingOptions.EnableWebFonts = true;
var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

The icon font embeds. Icons render correctly in the PDF.

How Do I Handle Unicode and Special Characters?

Use UTF-8 encoding and ensure your font supports the character set:

var html = @"
<meta charset='UTF-8'>
<style>
body { font-family: 'Noto Sans', sans-serif; }
</style>
<p>日本語 | العربية | Русский</p>";

renderer.RenderingOptions.EnableWebFonts = true;
var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

Noto Sans supports extensive Unicode ranges. Perfect for multilingual documents.

Can I Embed Multiple Fonts?

Yes, define multiple @font-face rules:

var html = @"
<style>
@font-face { font-family: 'Heading'; src: url('heading.ttf'); }
@font-face { font-family: 'Body'; src: url('body.ttf'); }
h1 { font-family: 'Heading'; }
p { font-family: 'Body'; }
</style>
<h1>Title</h1>
<p>Content</p>";

renderer.RenderingOptions.EnableWebFonts = true;
var pdf = renderer.RenderHtmlAsPdf(html);
Enter fullscreen mode Exit fullscreen mode

Both fonts embed independently.

What If EnableWebFonts Is Disabled?

Fonts don't embed. PDFs use standard fonts or system fallbacks. Text may display incorrectly on other machines.

Always enable for custom fonts:

renderer.RenderingOptions.EnableWebFonts = true;
Enter fullscreen mode Exit fullscreen mode

How Do Licenses Affect Font Embedding?

Check your font license. Some prohibit embedding in PDFs. Commercial fonts often require licensing for distribution.

Safe options:

  • Google Fonts (open license)
  • Standard PDF fonts (always allowed)
  • Fonts with embedding permissions (check license)

I use Google Fonts for most projects to avoid licensing issues.


Written by Jacob Mellor, CTO at Iron Software. Jacob created IronPDF and leads a team of 50+ engineers building .NET document processing libraries.

Top comments (0)