How font resolution works

EggPdf resolves fonts in this order:

  1. @font-face declarations in CSS (loaded from file when basePath is set)
  2. System-installed TrueType/OpenType fonts matched by name
  3. Built-in PDF standard fonts: Helvetica, Times, Courier

Any matched TrueType font is automatically subset — only the glyphs actually used in the document are embedded, keeping PDF size small.

CSS font-family

Use any installed font name in CSS:

body { font-family: Arial, sans-serif; }
h1   { font-family: 'Georgia', serif; }
code { font-family: 'Courier New', monospace; }

If the named font is installed on the machine running EggPdf, it will be found, subset, and embedded. If not found, EggPdf falls back to the next font in the stack, and ultimately to Helvetica.

Built-in PDF fonts

These 14 fonts are always available without embedding — zero overhead:

  • Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
  • Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
  • Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique
  • Symbol, ZapfDingbats

These are the 14 standard PDF fonts defined in the PDF specification. Every PDF viewer renders them without needing a font file embedded in the document.

@font-face — load from file

Load fonts that aren't installed system-wide by providing a file path in @font-face and setting basePath when calling the API:

<style>
@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter-Regular.ttf');
    font-weight: 400;
}
@font-face {
    font-family: 'Inter';
    src: url('fonts/Inter-Bold.ttf');
    font-weight: 700;
}
body { font-family: 'Inter', Helvetica, sans-serif; }
</style>

Then render with basePath:

byte[] pdf = HtmlToPdf.Render(html, basePath: "./assets/");

The url('fonts/Inter-Regular.ttf') path resolves relative to basePath. Use absolute paths in src: url(...) if you prefer not to set basePath.

Weight and style

Standard CSS values are supported: font-weight: 400, font-weight: 700, font-weight: bold, font-style: italic, font-style: normal. EggPdf selects the best matching font file from the system — for example, Arial-Bold.ttf for font-family: Arial; font-weight: bold.

When an exact weight/style variant is not found, EggPdf applies the CSS font-weight matching algorithm to pick the closest available variant rather than substituting a different typeface.