How To Load Font From Filename (TTF) To Use In PDF Document Generated by .NET Library PDF Mosaic

This sample shows how to add and use text font from file.

TTF font

C# :

/*
Description:
This sample shows how to use fonts in PDFMosaic library.

*/
using PDFMosaic;
using System.Drawing;

namespace FontFromFile
{
  class Fonts
  {
    static void Main()
    {
      PDFDocument document = new PDFDocument();
      document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
      PDFCanvas canvas = document.Pages[0].Canvas;

      PDFBrush brush = new PDFSolidBrush();
      
      // load font from filename
      PDFFont fontFromFile = PDFFont.FromFile("..\\..\\arial.ttf", 12);
      canvas.DrawString("Font from file.", fontFromFile, brush, 10, 120);

      document.Save("FontFromFile.pdf", true);
    }
  }
}

VB.NET :

'Description
'This sample shows how to use fonts in PDFMosaic library.
'

Imports PDFMosaic
Imports System.Drawing

Module FontFromFile
  Sub Main()    
    Dim document As New PDFDocument()
    document.Pages.Add(New PDFPage(PDFPaperFormat.A4))
    Dim canvas = document.Pages(0).Canvas

    Dim brush As New PDFSolidBrush()

    ' load font from filemane
    Dim fontFromFile = PDFFont.FromFile("..\\..\\arial.ttf", 12)
    canvas.DrawString("Font from file.", fontFromFile, brush, 10, 120)

    document.Save("FontFromFile.pdf", True)
  End Sub
End Module