Guide
How to embed a TrueType font in a PDF in C#
Register the font with RegisterTrueTypeFontAsync(...), then pass the returned
PdfFont into Page.AddTextAsync(...).
This is the path to use when you need a specific font file rather than one of the built-in PDF faces.
Register the font from disk and use it on the page
If you already have the font file on disk, register it once for the document and use the returned font object for page text.
using ZingPDF;
using ZingPDF.Graphics;
using ZingPDF.Syntax.CommonDataStructures;
using var pdf = Pdf.Create();
var page = await pdf.GetPageAsync(1);
var font = await pdf.RegisterTrueTypeFontAsync("NotoSans-Regular.ttf");
await page.AddTextAsync(
"Custom font text",
Rectangle.FromDimensions(240, 80),
font,
18,
RGBColour.Black);
await pdf.SaveAsync(File.Create("truetype-font.pdf"));
Register from a stream if the font does not live on disk
If your font comes from storage, a database, or another service, use the stream overload instead.
using var fontStream = File.OpenRead("NotoSans-Regular.ttf");
var font = await pdf.RegisterTrueTypeFontAsync(fontStream);
Use this path when the font choice matters
Embedded TrueType fonts are the right fit when the output needs a brand font, a specific document look, or a font file that is part of your application.
If Helvetica, Times, or Courier are enough, the standard font helpers keep the write path smaller.
Current text encoding note
The current high-level text path targets WinAnsi or Windows-1252 text. If your output needs a broader text range, test the exact characters you intend to write before you rely on the result.
Need the actual text-writing call?
Once the font is registered, the next step is placing text on the page with the right bounds and size.