Custom Fonts in HTML to PDF
IronPDF's pixel-perfect rendering of PDF documents from HTML documents also includes the accurate rendering of custom web fonts, including font icons provided by libraries such as Font Awesome and Bootstrap Components.
IronPDF supports custom WOFF and SVG CSS font packages. This includes custom web fonts provided by online type foundries such as Google Fonts.
To convert a web page containing one or more custom fonts into a PDF properly, developers must set a PDF rendering delay on IronPDF's HTML-to-PDF rendering engine. This can be achieved by setting the renderDelay
property of a ChromePdfRenderOptions
instance to a proper value using its setRenderDelay
method, as demonstrated in the example below. A minimum value of 500 milliseconds (or half a second) will suffice in most cases to ensure that all custom font/icon assets fully load before IronPDF converts all of the web page content into a PDF.
Please note, however, that web fonts do not work on Windows Apps hosted by Azure due to security reasons.
// Example demonstrating the use of IronPDF to render HTML to PDF with a custom delay to ensure web fonts are loaded.
using IronPdf;
class PdfRenderer
{
static void Main(string[] args)
{
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Create ChromePdfRenderOptions with render delay setting
var renderOptions = new ChromePdfRenderOptions();
// Set the render delay to 500 milliseconds to allow custom fonts to load
renderOptions.RenderDelay = 500;
// Assign the render options to the renderer
renderer.RenderingOptions = renderOptions;
// Define the URL or HTML content to render to PDF
string url = "http://example.com/your-custom-fonts-page";
// Render the web page to a PDF file
var pdf = renderer.RenderUrlAsPdf(url);
// Save the generated PDF file to disk
pdf.SaveAs("Output.pdf");
}
}
// Example demonstrating the use of IronPDF to render HTML to PDF with a custom delay to ensure web fonts are loaded.
using IronPdf;
class PdfRenderer
{
static void Main(string[] args)
{
// Create a new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Create ChromePdfRenderOptions with render delay setting
var renderOptions = new ChromePdfRenderOptions();
// Set the render delay to 500 milliseconds to allow custom fonts to load
renderOptions.RenderDelay = 500;
// Assign the render options to the renderer
renderer.RenderingOptions = renderOptions;
// Define the URL or HTML content to render to PDF
string url = "http://example.com/your-custom-fonts-page";
// Render the web page to a PDF file
var pdf = renderer.RenderUrlAsPdf(url);
// Save the generated PDF file to disk
pdf.SaveAs("Output.pdf");
}
}
' Example demonstrating the use of IronPDF to render HTML to PDF with a custom delay to ensure web fonts are loaded.
Imports IronPdf
Friend Class PdfRenderer
Shared Sub Main(ByVal args() As String)
' Create a new instance of ChromePdfRenderer
Dim renderer = New ChromePdfRenderer()
' Create ChromePdfRenderOptions with render delay setting
Dim renderOptions = New ChromePdfRenderOptions()
' Set the render delay to 500 milliseconds to allow custom fonts to load
renderOptions.RenderDelay = 500
' Assign the render options to the renderer
renderer.RenderingOptions = renderOptions
' Define the URL or HTML content to render to PDF
Dim url As String = "http://example.com/your-custom-fonts-page"
' Render the web page to a PDF file
Dim pdf = renderer.RenderUrlAsPdf(url)
' Save the generated PDF file to disk
pdf.SaveAs("Output.pdf")
End Sub
End Class