Search code examples
c#fontsasp.net-mvc-5visual-studio-2015pdfsharp

FontResolver to add **Myriad Pro** Font in PDFsharp 1.32


I am looking to add the Font(Myriad Pro) to the PDF Invoice generated via PDFsharp, but unable to do so.

What I have tried so far is:

  • EZFontResolver.cs class-file provided by a developer on the following link
    (And posted my comment-problem there as well, but did not recieve any response.)
    It gives me an exception {“Must not change font resolver after is was once used.”} when the following code line executes:
    GlobalFontSettings.FontResolver = fontResolver;
  • also tried Beta Version 1.50.xx

Solution

  • The font resolver is a global setting (as user "spender" pointed out in their comments). This global settings is shared by all instances of PdfDocument() and it can be set only once.

    The font resolver is a new feature of PDFsharp 1.50 (there was a breaking change with beta 2, so samples for beta 1 may no longer work with the current beta 3). For PDFsharp 1.32 a different approach must be used.

    When using the WPF build of PDFsharp 1.32, you will find a sample that shows the usage of private fonts in the samples folder that comes with the source package of PDFsharp (sample folder is PrivateFonts).