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 GenerationIncorporate 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.
-
1Install IronPDF with NuGet Package Manager
-
2Copy 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");C# -
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library IronPDF for setting fonts in PDFs
- Use HTML to import or request fonts from an external source
- Delay the rendering process to ensure proper font loading
- Render the HTML to PDF as usual
- Import font file using the
@font-facerule in CSS styling
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.
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");Imports IronPdf
' HTML contains webfont
Private 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>"
Private renderer As New ChromePdfRenderer()
' Wait for font to load
renderer.RenderingOptions.WaitFor.AllFontsLoaded(2000)
' Render HTML to PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
' Export the PDF
pdf.SaveAs("font-test.pdf")Explore more WaitFor options, such as those for fonts, JavaScript, HTML elements, and network idle on the 'Class Documentation'. For responsive designs that adapt fonts based on screen size, check our guide on responsive CSS for PDF rendering.
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
@importorlinktags - 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:
- Fallback font chains: Define multiple fonts in your CSS
font-familydeclaration - Extended wait times: Increase the
AllFontsLoadedtimeout for slower connections - Local font embedding: Use
@font-facewith base64-encoded fonts for guaranteed availability - 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.
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");Imports IronPdf
' Import custom font
Private html As String = "<!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>"
Private renderer As New ChromePdfRenderer()
' Render HTML to PDF
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf(html)
' Export the PDF
pdf.SaveAs("customFont.pdf")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
The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.
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:
- Embedding fonts as base64-encoded strings in your CSS
- Using only web fonts from CDNs
- Pre-rendering PDFs in a supported environment
- Upgrading to a higher Azure tier with full font support
https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face
Frequently Asked Questions
How can I incorporate web fonts in PDFs using IronPDF?
You can incorporate web fonts in PDFs using IronPDF by loading font files via external services like Google Fonts or by using local font files with CSS `@font-face` rules. IronPDF supports delaying the rendering process using the `WaitFor.AllFontsLoaded` method to ensure all fonts are loaded before generating the PDF.
What methods does IronPDF provide for font loading success?
IronPDF provides several methods for ensuring font loading success, including using the `WaitFor.AllFontsLoaded` method to delay rendering, defining fallback font chains, extending wait times, embedding local fonts using `@font-face`, and preloading fonts with HTML preload tags.
How do local fonts differ from web fonts when using IronPDF?
Local fonts are best used when working offline or needing guaranteed availability, while web fonts, such as those from Google Fonts, are ideal for projects with internet connectivity that require frequent updates and a large font selection. IronPDF supports both options, allowing flexibility based on project needs.
Which font formats are supported by IronPDF?
IronPDF supports a variety of font formats including TTF, OTF, WOFF, WOFF2, EOT, and SVG fonts, allowing you to customize the typography in your PDFs to suit different display and professional requirements.
What happens if fonts fail to load in IronPDF-generated PDFs?
If fonts fail to load, IronPDF falls back to system default fonts, which can impact visual design. To avoid this, you can set longer wait times for font loading, embed fonts directly, or use defined fallback fonts to ensure visual consistency in the generated PDFs.
Can IronPDF render PDFs with icon fonts?
Yes, IronPDF can render PDFs with icon fonts, such as FontAwesome and Bootstrap Icons, by integrating them into the HTML content via CSS and loading them with webfont or local font mechanisms.
Why is font loading time important in PDF generation with IronPDF?
Font loading time is crucial because if a font is not loaded properly before PDF generation, it may result in blank pages or improper rendering. IronPDF uses the `WaitFor.AllFontsLoaded` method to manage this, ensuring that all fonts are loaded at specified wait times.
Which online font services does IronPDF support?
IronPDF supports a wide range of online font services, including Google Fonts, Adobe Fonts, Font Awesome, Bootstrap Icons, and Material Design Icons, among others, providing vast typography options for PDF customization.
How does IronPDF handle font rendering on Azure?
IronPDF handles font rendering on Azure by supporting font rendering in its Virtual Machines, Web Roles, and Premium and Isolated tiers. However, lower Azure tiers like Free and Shared have limitations due to sandboxing restrictions.
What are the limitations of using SVG fonts with IronPDF on Azure?
The Azure hosting platform does not support SVG fonts in its lower shared web app tiers due to sandboxing restrictions. To overcome these limitations, fonts can be embedded as base64-encoded strings, or one might upgrade to a higher Azure tier that provides full font support.

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.