WebFonts and WebIcons, Issues with Azure PDF

CSS includes Web Fonts, allowing you to specify font files to be downloaded along with your website as it is accessed. Here's a walkthrough how to use WebFonts and Icons in your ASP.NET pages and Azure PDF projects.

Code Examples

WebFonts in ASPNET Page
private static void Main(string[] args)

{

string desktoppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

var outfile = Path.Combine(desktoppath, "font-test.pdf");

HtmlToPdf myHtmlToPdf = new IronPdf.HtmlToPdf();

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>";

PdfDocument doc = myHtmlToPdf.RenderHtmlAsPdf(html);

doc.SaveAs(outfile);

Process.Start(outfile);

}
Public Shared Sub Main(ByVal args() As String)


Dim desktoppath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

Dim outfile = Path.Combine(desktoppath, "font-test.pdf")

Dim myHtmlToPdf As HtmlToPdf = New IronPdf.HtmlToPdf()

Dim 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>"

Dim doc As PdfDocument = myHtmlToPdf.RenderHtmlAsPdf(html)

doc.SaveAs(outfile)

Process.Start(outfile)

End Sub
Jump to Article
Try IronPDF free for development


Step 1

1. Install IronPDF Library

To work with this tutorial and the CSS WebFonts in a C# project, first we'll download the free for development IronPDF library. You can get it direct download or by accessing the NuGet package manager.


 PM > Install-Package IronPdf


How to Tutorial

2. Use WebFonts and Icons

WebFonts allow you to identify fonts for download with your website. This means that any supporting browser can have the exact fonts you specify available to it.

Icon fonts are fonts that are made up of symbols and glyphs and not letters or numbers.

IronPDF supports WebFonts (such as Google Fonts and the Adobe web font API) and Icon fonts such as those applied by Bootstrap and FontAwesome.

Learn more about working with PDF and SVG WebFonts.

Here is a small example on how to make use a WebFont named Lobster in your ASP.NET pages and IronPDF.

private static void Main(string[] args)

{

string desktoppath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

var outfile = Path.Combine(desktoppath, "font-test.pdf");

HtmlToPdf myHtmlToPdf = new IronPdf.HtmlToPdf();

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>";

PdfDocument doc = myHtmlToPdf.RenderHtmlAsPdf(html);

doc.SaveAs(outfile);

Process.Start(outfile);

}
Public Shared Sub Main(ByVal args() As String)


Dim desktoppath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

Dim outfile = Path.Combine(desktoppath, "font-test.pdf")

Dim myHtmlToPdf As HtmlToPdf = New IronPdf.HtmlToPdf()

Dim 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>"

Dim doc As PdfDocument = myHtmlToPdf.RenderHtmlAsPdf(html)

doc.SaveAs(outfile)

Process.Start(outfile)

End Sub
VB   C#


3. Limitations on Azure PDF

The Azure hosting platform does not support servers loading SVG fonts in their cheaper shared webapp tiers. Azure's VPS and Web Role are not sandboxed in the same way and will support web font rendering.