How to set fonts in PDFs C#

Set Fonts in PDFs with IronPDF C#

IronPDF allows C# developers to create PDFs with custom web fonts and icon fonts from HTML. It supports both external font services like Google Fonts and local font files through CSS @font-face rules, ensuring consistent typography across all generated PDFs.

A webfont is a specialized font designed for use on websites. These fonts are hosted on web servers and downloaded by web browsers to ensure consistent and visually appealing text rendering on websites, regardless of the user's local font availability. Additionally, icon fonts, which use symbols and glyphs, are often used in web design to create scalable, customizable icons and maintain a visually consistent user interface through CSS manipulation. With IronPDF's font management capabilities, developers can easily integrate these fonts into their PDF generation workflow.

CSS includes web fonts, enabling you to specify font files for download when your website is accessed. IronPDF supports font loading and rendering to PDF from HTML, making it ideal for creating documents that require specific branding or typography standards. For developers working with international content, IronPDF also provides UTF-8 and international language support.

Quickstart: Using WebFonts in PDF Generation

Incorporate web and icon fonts into your PDFs using IronPDF's C# library. This guide shows you how to render HTML content with custom fonts, ensuring consistent and visually appealing PDFs. Simply render the HTML with IronPDF and save your styled document in seconds. Before starting, ensure you have installed IronPDF in your project.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    new IronPdf.ChromePdfRenderer { RenderingOptions = { WaitFor = IronPdf.Rendering.WaitFor.AllFontsLoaded(2000) } }
        .RenderHtmlAsPdf("<link href=\"https://fonts.googleapis.com/css?family=Lobster\" rel=\"stylesheet\">" +
                         "<link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css\" rel=\"stylesheet\">" +
                         "<p style=\"font-family:'Lobster', serif; font-size:30px;\">Hello Google Font</p>" +
                         "<i class=\"fa fa-coffee\" style=\"font-size:40px; color:#b00;\"></i>")
        .SaveAs("webfonts-icons.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

How Do I Use WebFonts and Icons in PDFs?

IronPDF supports WebFonts (such as Google Fonts and the Adobe web font API) and icon fonts, such as those used by Bootstrap and FontAwesome. This support makes IronPDF suitable for projects requiring sophisticated typography, from simple documents to complex reports with branded elements.

Fonts often require a delay in rendering to load properly. When a font is not loaded correctly, it can lead to a blank page without any text. You can use the WaitFor.AllFontsLoaded method to wait until all fonts are loaded by assigning a maximum wait time to it. The default maximum wait time is 500ms. For more complex scenarios involving JavaScript or dynamic content, explore our HTML to PDF tutorial which covers advanced rendering techniques.

Here is a small example of how to use a WebFont named Lobster in your project.

:path=/static-assets/pdf/content-code-examples/how-to/webfonts-webicons-render-webfont.cs
using IronPdf;

// HTML contains webfont
var html = @"<link href=""https://fonts.googleapis.com/css?family=Lobster"" rel=""stylesheet"">
<p style=""font-family: 'Lobster', serif; font-size:30px;"" > Hello Google Fonts</p>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Wait for font to load
renderer.RenderingOptions.WaitFor.AllFontsLoaded(2000);

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

// Export the PDF
pdf.SaveAs("font-test.pdf");
$vbLabelText   $csharpLabel

Explore more WaitFor options, such as those for fonts, JavaScript, HTML elements, and network idle on the 'WaitFor' Class Documentation](/how-to/waitfor/).' For responsive designs that adapt fonts based on screen size, check our guide on responsive CSS for PDF rendering](/how-to/html-to-pdf-responsive-css/).

Why Does Font Loading Time Matter?

When a font is not loaded correctly, it can lead to a blank page without any text. You can use the WaitFor.AllFontsLoaded method to wait until all fonts are loaded by assigning a maximum wait time to it. The default maximum wait time is 500ms. This timing consideration is particularly important when working with complex web applications or when rendering WebGL content to PDF, where multiple resources need to load sequentially.

Font loading delays can vary based on several factors including network speed, font file size, and server response time. When working with multiple custom fonts or icon libraries, it's recommended to increase the wait time to ensure all typography renders correctly. This is especially crucial for professional documents where missing fonts could impact readability and brand consistency.

Which Font Services Are Supported?

IronPDF supports WebFonts (such as Google Fonts and the Adobe web font API) and icon fonts, such as those used by Bootstrap and FontAwesome. Additionally, IronPDF supports:

  • Google Fonts (entire catalog)
  • Adobe Fonts (Typekit)
  • Font Awesome icons (all versions)
  • Bootstrap Icons
  • Material Design Icons
  • Custom web font services via CSS @import or link tags
  • Self-hosted font files in various formats (TTF, OTF, WOFF, WOFF2)

What Happens If Fonts Don't Load Properly?

Fonts often require a delay in rendering to load properly. When a font is not loaded correctly, it can lead to a blank page without any text. In such cases, browsers typically fall back to system default fonts, which can disrupt your document's visual consistency. IronPDF provides several mechanisms to handle font loading failures:

  1. Fallback font chains: Define multiple fonts in your CSS font-family declaration
  2. Extended wait times: Increase the AllFontsLoaded timeout for slower connections
  3. Local font embedding: Use @font-face with base64-encoded fonts for guaranteed availability
  4. Font preloading: Use HTML preload tags to prioritize font loading

How Do I Import Font Files Directly?

To use an existing font file, apply the @font-face rule in CSS styling. It also works when using a combination of the @font-face rule and embedding base64-encoded woff files. In the following example, I will be using Pixelify Sans Font.

:path=/static-assets/pdf/content-code-examples/how-to/webfonts-webicons-custom-font.cs
using IronPdf;

// Import custom font
string html = @"<!DOCTYPE html>
<html>
<head>
<style>
@font-face {font-family: 'Pixelify';
src: url('fonts\PixelifySans-VariableFont_wght.ttf');
}
p {
    font-family: 'Pixelify';
    font-size: 70px;
}
</style>
</head>
<body>
<p>Custom font</p>
</body>
</html>";

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Render HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(html);

// Export the PDF
pdf.SaveAs("customFont.pdf");
$vbLabelText   $csharpLabel

Which Font File Formats Can I Use?

To use an existing font file, apply the @font-face rule in CSS styling. It also works when using a combination of the @font-face rule and embedding base64-encoded woff files. IronPDF supports the following font file formats:

  • TTF (TrueType Font): Widely supported, ideal for both screen and print
  • OTF (OpenType Font): Advanced typography features, suitable for professional documents
  • WOFF (Web Open Font Format): Compressed format optimized for web use
  • WOFF2: Improved compression over WOFF, smaller file sizes
  • EOT (Embedded OpenType): Legacy format for older browsers
  • SVG fonts: Vector-based fonts (with limitations on some platforms)

When Should I Use Local Fonts vs Web Fonts?

To use an existing font file, apply the @font-face rule in CSS styling. The choice between local and web fonts depends on several factors:

Use Local Fonts When:

  • Working offline or in restricted network environments
  • Requiring guaranteed font availability
  • Dealing with proprietary or licensed fonts
  • Optimizing for faster rendering without network delays
  • Creating documents with strict compliance requirements

Use Web Fonts When:

  • Using large font libraries like Google Fonts
  • Requiring automatic updates to font files
  • Minimizing application bundle size
  • Working with frequently changing typography requirements
  • Building applications that already depend on internet connectivity

What Are the Limitations When Using Azure?

The Azure hosting platform does not support servers loading SVG fonts in their lower shared web app tiers. However, Azure's VPS and Web Role are not sandboxed in the same way and do support web font rendering. For detailed Azure deployment guidance, refer to our Azure deployment guide which covers all tier-specific limitations and workarounds.

Which Azure Tiers Support Font Rendering?

However, Azure's VPS and Web Role are not sandboxed in the same way and do support web font rendering. Here's a breakdown of Azure tier support:

Full Font Support:

  • Azure Virtual Machines (all sizes)
  • Azure Web Roles
  • App Service Premium tiers (P1v2, P2v2, P3v2)
  • App Service Isolated tiers

Limited Font Support:

  • App Service Basic tier (B1, B2, B3) - Web fonts only
  • App Service Standard tier (S1, S2, S3) - Some SVG font restrictions

No Custom Font Support:

  • App Service Free tier (F1)
  • App Service Shared tier (D1)

Why Do Lower Azure Tiers Have Font Restrictions?

The Azure hosting platform does not support servers loading SVG fonts in their lower shared web app tiers due to sandboxing restrictions and resource limitations. Lower tiers implement strict security boundaries that prevent certain system-level operations required for custom font rendering. These restrictions help Azure maintain multi-tenant isolation and prevent resource abuse in shared environments.

To work around these limitations, consider:

  1. Embedding fonts as base64-encoded strings in your CSS
  2. Using only web fonts from CDNs
  3. Pre-rendering PDFs in a supported environment
  4. Upgrading to a higher Azure tier with full font support

Frequently Asked Questions

How can I use Google Fonts in my PDF documents?

IronPDF supports Google Fonts through HTML rendering. Simply include the Google Fonts link in your HTML head section and apply the font-family in CSS. IronPDF will download and render these fonts when generating the PDF, ensuring your custom typography appears correctly in the final document.

Why aren't my web fonts appearing correctly in the generated PDF?

Web fonts often require time to load before rendering. IronPDF provides a WaitFor.AllFontsLoaded() option in the RenderingOptions that allows you to set a delay (in milliseconds) to ensure fonts are fully loaded before PDF generation. This prevents missing or incorrectly rendered fonts.

Can I use FontAwesome icons in my PDFs?

Yes, IronPDF fully supports FontAwesome and other icon fonts. Include the FontAwesome CSS in your HTML and use the appropriate icon classes. IronPDF will render these icon fonts as vector graphics in your PDF, maintaining their scalability and visual quality.

How do I use local font files with @font-face?

IronPDF supports CSS @font-face rules for loading local font files. Define your @font-face rule in your CSS, specifying the font file path, and then apply the font-family to your HTML elements. IronPDF will embed these custom fonts directly into the PDF during rendering.

What font formats are supported for PDF generation?

IronPDF supports standard web font formats including WOFF, WOFF2, TTF, and OTF files when used through CSS @font-face rules or external font services. This ensures compatibility with most modern web fonts and icon fonts available today.

How can I ensure consistent typography across different systems?

IronPDF embeds web fonts directly into the generated PDF files, ensuring that your custom typography displays consistently regardless of the fonts installed on the viewer's system. This makes it ideal for maintaining brand consistency in distributed documents.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released