title: Using Private TTF Fonts in PDFsharp
body: <p>I am working on a C# .NET WPF desktop application that will generate a PDF that needs a very specific font that would not be installed on the system.  I am using PdfSharp-WPF v1.32.  The file <code>importantSc.ttf</code> is in the project resources folder.</p>
  
  <p>My best bet is that my URI path is wrong, but I think I have it correct.  I do have the font family name correct, as it worked while the font was installed on my dev computer.</p>
  
  <pre><code>using System;
  using PdfSharp.Drawing;
  using PdfSharp.Pdf;
  using PdfSharp.Pdf.IO;
  using Microsoft.Win32;
  using PdfSharp.Drawing.Layout;
  using System.Collections.Generic;
  using System.Windows.Input;
  using System.Windows;
  
  namespace MyProject
  {
      public class MyPdfFile
      {
          private PdfDocument doc;
  
          public void MakePdf()
          {
              Double x1, y1;      
              XBrush brush = XBrushes.Black;
              XGraphics xgf = XGraphics.FromPdfPage(page);
              doc = new PdfDocument();
              PdfPage page = doc.AddPage();
  
              // Load in a private font to use.
              XPrivateFontCollection privateFontCollection = new XPrivateFontCollection();
              String fontFamilyName = "Important Script AM";
              String fontUriPath = @"pack://application:,,,/importantSc.ttf";
  
              Uri fontUri = new Uri( fontUriPath );
              privateFontCollection.Add(fontUri, "./#" + fontFamilyName);
  
              XFont font = new XFont(fontFamilyName, 9, XFontStyle.Regular); // &lt;-- the error happens here
  
              //Add text to page
              x1 = 1.96 * 72;
              y1 = 3.25 * 72;
              String printString = "I wish this would work!";
              xgf.DrawString(printString, font, brush, x1, y1);
  
              xgf.Dispose();
          }
      }
  }
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <p><strong>An unhandled exception of type 'System.InvalidOperationException' occured in PdfSharp-WPF.dll</strong></p>
  
  <p><strong>Additional Information: Cannot get a matching glyph typeface for font <em>'Important Script AM'.</em></strong></p>