GemBox.Pdf
  • Overview
  • Examples
  • Free version
  • Support
  • Pricelist

    Show / Hide Table of Contents

    PdfFonts Class

    Namespace:
    GemBox.Pdf.Content
    Assembly:
    GemBox.Pdf.dll

    Provides enumeration support for PdfFontFamily and PdfFontFace objects.

    • C#
    • VB.NET
    public static class PdfFonts
    Public Module PdfFonts
    Inheritance:
    Object
    PdfFonts
    Remarks

    Custom font location is usually used in medium trust environments to bypass file system operations restrictions imposed for file locations that are not under the application's jurisdiction.

    Properties

    StandardFontFaces

    Gets the collection of PdfFontFace objects that represent the PDF standard Type 1 fonts.

    • C#
    • VB.NET
    public static ICollection<PdfFontFace> StandardFontFaces { get; }
    Public Shared ReadOnly Property StandardFontFaces As ICollection(Of PdfFontFace)
    Property Value
    ICollection<PdfFontFace>

    An ICollection<T> of PdfFontFace objects that represent the PDF standard Type 1 fonts.

    See Also
    PDF Specification ISO 32000-1:2008, section '9.6.2.2 Standard Type 1 Fonts (Standard 14 Fonts)'

    StandardFontFamilies

    Gets the collection of PdfFontFamily objects that represent the PDF standard Type 1 fonts.

    • C#
    • VB.NET
    public static ICollection<PdfFontFamily> StandardFontFamilies { get; }
    Public Shared ReadOnly Property StandardFontFamilies As ICollection(Of PdfFontFamily)
    Property Value
    ICollection<PdfFontFamily>

    An ICollection<T> of PdfFontFamily objects that represent the PDF standard Type 1 fonts.

    See Also
    PDF Specification ISO 32000-1:2008, section '9.6.2.2 Standard Type 1 Fonts (Standard 14 Fonts)'

    SystemFontFaces

    Gets the collection of PdfFontFace objects from the default system font location.

    • C#
    • VB.NET
    public static ICollection<PdfFontFace> SystemFontFaces { get; }
    Public Shared ReadOnly Property SystemFontFaces As ICollection(Of PdfFontFace)
    Property Value
    ICollection<PdfFontFace>

    An ICollection<T> of PdfFontFace objects that represent the fonts in the system fonts collection.

    SystemFontFamilies

    Gets the collection of PdfFontFamily objects from the default system font location.

    • C#
    • VB.NET
    public static ICollection<PdfFontFamily> SystemFontFamilies { get; }
    Public Shared ReadOnly Property SystemFontFamilies As ICollection(Of PdfFontFamily)
    Property Value
    ICollection<PdfFontFamily>

    An ICollection<T> of PdfFontFamily objects that represent the fonts in the system fonts collection.

    Methods

    GetFontFaces(String)

    Returns the collection of PdfFontFace objects from a string value that represents the location of the fonts.

    • C#
    • VB.NET
    public static ICollection<PdfFontFace> GetFontFaces(string location)
    Public Shared Function GetFontFaces(location As String) As ICollection(Of PdfFontFace)
    Parameters
    location
    String

    The location that contains the fonts.

    Returns
    ICollection<PdfFontFace>

    An ICollection<T> of PdfFontFace objects that represent the fonts in location.

    Remarks

    If location is null or Empty, GetCurrentDirectory() is used.

    If location is relative, it is converted to absolute with GetFullPath(String) method.

    If you are developing ASP.NET application, then use Server.MapPath(System.String) as the value of the location parameter.

    GetFontFaces(String, String)

    Returns the collection of PdfFontFace objects embedded as resources in the specified assembly at the specified location.

    Read the Remarks for details about the arguments of the GetFontFaces(String, String) method for desktop and web applications.

    • C#
    • VB.NET
    public static ICollection<PdfFontFace> GetFontFaces(string assemblyName, string location)
    Public Shared Function GetFontFaces(assemblyName As String, location As String) As ICollection(Of PdfFontFace)
    Parameters
    assemblyName
    String

    The name of the assembly that contains the fonts.

    location
    String

    The location of the fonts in the assembly.

    Returns
    ICollection<PdfFontFace>

    An ICollection<T> of PdfFontFace objects embedded as resources in the specified assembly at the specified location.

    Remarks
    important

    When you add fonts as resources to your application, make sure you are setting the <Resource> element when targeting .NET Framework or when targeting .NET Core with enabled WPF.

    Otherwise, use <EmbeddedResource> element for the build action.

    Also, make sure System.Windows.Application.ResourceAssembly is correctly initialized, if you want to format text that uses embedded fonts with WPF or WPFDisplay text formatting mode.

    The following image shows an example of a Windows Console project structure with font files added as resources.

    Packaging Fonts in Windows application

    The Following table illustrates the various assemblyName and location values that you can specify to retrieve fonts from the above Windows Console project structure.

    Retrieved fontassemblyNamelocationNotes
    Font1.ttfnull, Empty or "MyConsoleApplication"null or EmptyFont resource files are in the root of the entry assembly.
    Font2.ttfnull, Empty or "MyConsoleApplication""MyFonts"Font resource files are in the subfolder of the entry assembly.
    Font3.ttf"MyClassLibrary"null or EmptyFont resource files are in the root of the referenced assembly.
    Font4.ttf"MyClassLibrary""MyFonts"Font resource files are in the subfolder of the referenced assembly.

    The following image shows an example of a Web ASP.NET project structure with font files added as resources.

    Packaging Fonts in Web application

    The following table illustrates the various assemblyName and location values that you can specify to retrieve fonts from the above Web ASP.NET project structure.

    Since ASP.NET assembly is actually a class library referenced from ASP.NET web server, assemblyName must always be specified.

    Retrieved fontassemblyNamelocationNotes
    Font1.ttf"MyWebApplication"null or EmptyFont resource files are in the root of the main assembly.
    Font2.ttf"MyWebApplication""MyFonts"Font resource files are in the subfolder of the main assembly.
    Font3.ttf"MyClassLibrary"null or EmptyFont resource files are in the root of the referenced assembly.
    Font4.ttf"MyClassLibrary""MyFonts"Font resource files are in the subfolder of the referenced assembly.

    GetFontFamilies(String)

    Returns the collection of PdfFontFamily objects from a string value that represents the location of the fonts.

    • C#
    • VB.NET
    public static ICollection<PdfFontFamily> GetFontFamilies(string location)
    Public Shared Function GetFontFamilies(location As String) As ICollection(Of PdfFontFamily)
    Parameters
    location
    String

    The location that contains the fonts.

    Returns
    ICollection<PdfFontFamily>

    An ICollection<T> of PdfFontFamily objects that represent the fonts in location.

    Remarks

    If location is null or Empty, GetCurrentDirectory() is used.

    If location is relative, it is converted to absolute with GetFullPath(String) method.

    If you are developing ASP.NET application, then use Server.MapPath(System.String) as the value of the location parameter.

    GetFontFamilies(String, String)

    Returns the collection of PdfFontFamily objects embedded as resources in the specified assembly at the specified location.

    Read the Remarks for details about the arguments of the GetFontFamilies(String, String) method for desktop and web applications.

    • C#
    • VB.NET
    public static ICollection<PdfFontFamily> GetFontFamilies(string assemblyName, string location)
    Public Shared Function GetFontFamilies(assemblyName As String, location As String) As ICollection(Of PdfFontFamily)
    Parameters
    assemblyName
    String

    The name of the assembly that contains the fonts.

    location
    String

    The location of the fonts in the assembly.

    Returns
    ICollection<PdfFontFamily>

    An ICollection<T> of PdfFontFamily objects embedded as resources in the specified assembly at the specified location.

    Remarks
    important

    When you add fonts as resources to your application, make sure you are setting the <Resource> element when targeting .NET Framework or when targeting .NET Core with enabled WPF.

    Otherwise, use <EmbeddedResource> element for the build action.

    Also, make sure System.Windows.Application.ResourceAssembly is correctly initialized, if you want to format text that uses embedded fonts with WPF or WPFDisplay text formatting mode.

    The following image shows an example of a Windows Console project structure with font files added as resources.

    Packaging Fonts in Windows application

    The Following table illustrates the various assemblyName and location values that you can specify to retrieve fonts from the above Windows Console project structure.

    Retrieved fontassemblyNamelocationNotes
    Font1.ttfnull, Empty or "MyConsoleApplication"null or EmptyFont resource files are in the root of the entry assembly.
    Font2.ttfnull, Empty or "MyConsoleApplication""MyFonts"Font resource files are in the subfolder of the entry assembly.
    Font3.ttf"MyClassLibrary"null or EmptyFont resource files are in the root of the referenced assembly.
    Font4.ttf"MyClassLibrary""MyFonts"Font resource files are in the subfolder of the referenced assembly.

    The following image shows an example of a Web ASP.NET project structure with font files added as resources.

    Packaging Fonts in Web application

    The following table illustrates the various assemblyName and location values that you can specify to retrieve fonts from the above Web ASP.NET project structure.

    Since ASP.NET assembly is actually a class library referenced from ASP.NET web server, assemblyName must always be specified.

    Retrieved fontassemblyNamelocationNotes
    Font1.ttf"MyWebApplication"null or EmptyFont resource files are in the root of the main assembly.
    Font2.ttf"MyWebApplication""MyFonts"Font resource files are in the subfolder of the main assembly.
    Font3.ttf"MyClassLibrary"null or EmptyFont resource files are in the root of the referenced assembly.
    Font4.ttf"MyClassLibrary""MyFonts"Font resource files are in the subfolder of the referenced assembly.

    Examples

    Private fonts example
    Back to top

    Facebook • Twitter • LinkedIn

    © GemBox Ltd. — All rights reserved.