ZingPDF logo

Guide

How to use Google Fonts in a PDF in C#

Reference ZingPDF.GoogleFonts, create a GoogleFontsClient, register the requested family, and then use that font like any other embedded TrueType font.

This is a good fit when you want a specific web font family without bundling the font file into your own application up front.

Register the font and write text

Once the font is registered, the rest of the write path looks like any other embedded font workflow.

using ZingPDF;
using ZingPDF.GoogleFonts;
using ZingPDF.Graphics;
using ZingPDF.Syntax.CommonDataStructures;

using var pdf = Pdf.Create();
var page = await pdf.GetPageAsync(1);

var client = new GoogleFontsClient("<google-fonts-api-key>");
var font = await pdf.RegisterGoogleFontAsync(
    client,
    new GoogleFontRequest
    {
        Family = "Inter",
        Variant = "regular"
    });

await page.AddTextAsync(
    "Hello from Google Fonts",
    Rectangle.FromDimensions(320, 80),
    font,
    18,
    RGBColour.Black);

await pdf.SaveAsync(File.Create("google-fonts.pdf"));

Add the Google Fonts package alongside the core package

The download and registration helpers live in ZingPDF.GoogleFonts. Most applications still use that package together with the main ZingPDF package rather than instead of it.

Choose the family and variant you actually want

The GoogleFontRequest tells the client which family and variant to download. That keeps the registration call explicit and makes it easier to control typography in generated documents.

Use it when fetching fonts at build time is acceptable

If your application already ships with a local font file, plain TrueType registration is simpler. The Google Fonts path is more useful when you want a remote source for a known family and have an API key in the runtime environment.

Need a local font file instead?

The embedded TrueType guide covers the offline path.

Open TrueType guide Open fonts docs