GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / AddFontFromFileU Method
The file path of the resource font file.

Please note that adding a font, that consists from several resource font files, is currently not supported.

The name of the required font to add for use in the PDF document.
A member of the FontCharSet enumeration. Defines the character encoding system (character set) used by the specified font.
Set this parameter to true if you want to add the font in the bold style, otherwise set it to false.
Set this parameter to true if you want to add the font in the italic style, otherwise set it to false.
Example





In This Topic
AddFontFromFileU Method (GdPicturePDF)
In This Topic
Adds a font from a file to the currently loaded PDF document according to a font file path and other parameters you have specified. The displaying of Unicode characters is supported when using the font added by this method.

Supported font file formats are:

* .fon - Font resource file

* .fnt - Raw bitmap font file

* .ttf - Raw TrueType file

* .ttc - East Asian Windows: TrueType font collection

* .fot - TrueType resource file

* .otf - PostScript OpenType font

Syntax
'Declaration
 
Public Function AddFontFromFileU( _
   ByVal FilePath As String, _
   ByVal FontName As String, _
   ByVal CharSet As FontCharSet, _
   ByVal Bold As Boolean, _
   ByVal Italic As Boolean _
) As String
public string AddFontFromFileU( 
   string FilePath,
   string FontName,
   FontCharSet CharSet,
   bool Bold,
   bool Italic
)
public function AddFontFromFileU( 
    FilePath: String;
    FontName: String;
    CharSet: FontCharSet;
    Bold: Boolean;
    Italic: Boolean
): String; 
public function AddFontFromFileU( 
   FilePath : String,
   FontName : String,
   CharSet : FontCharSet,
   Bold : boolean,
   Italic : boolean
) : String;
public: string* AddFontFromFileU( 
   string* FilePath,
   string* FontName,
   FontCharSet CharSet,
   bool Bold,
   bool Italic
) 
public:
String^ AddFontFromFileU( 
   String^ FilePath,
   String^ FontName,
   FontCharSet CharSet,
   bool Bold,
   bool Italic
) 

Parameters

FilePath
The file path of the resource font file.

Please note that adding a font, that consists from several resource font files, is currently not supported.

FontName
The name of the required font to add for use in the PDF document.
CharSet
A member of the FontCharSet enumeration. Defines the character encoding system (character set) used by the specified font.
Bold
Set this parameter to true if you want to add the font in the bold style, otherwise set it to false.
Italic
Set this parameter to true if you want to add the font in the italic style, otherwise set it to false.

Return Value

Returns a resource name of the specified font required for the next usage within the PDF document. The GetStat method can be subsequently used to determine if this method has been successful.

This resource name you can subsequently pass, for example, to the DrawText method, as well as to all methods, which have a font resource name as a parameter.

Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Example
How to add a font from the specified file to the newly created PDF document. The font resource name is subsequently used to draw some unicode text on the newly created page.
Dim caption As String = "Example: AddFontFromFileU"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
    'You need to set the correct path to your resource font file here.
    Dim fontResName As String = gdpicturePDF.AddFontFromFileU("\WINDOWS\Fonts\mingliu.ttc", "MingLiu", FontCharSet.ANSI_CHARSET, False, False)
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        If (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetFillColor(255, 0, 0) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetTextSize(30) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.DrawText(fontResName, 10, 50, ChrW(20320) + "        " + ChrW(22909)) = GdPictureStatus.OK) Then
            status = gdpicturePDF.SaveToFile("test_AddFontFromFileU.pdf")
            If status = GdPictureStatus.OK Then
                MessageBox.Show("The example HAS been followed successfully.", caption)
            End If
        Else
            status = gdpicturePDF.GetStat()
        End If
    Else
        MessageBox.Show("The AddFontFromFileU() method has failed with the status: " + status.ToString(), caption)
        status = GdPictureStatus.OK
    End If
End If
If status <> GdPictureStatus.OK Then
    MessageBox.Show("The example HAS NOT been followed successfully. The last error status is = " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: AddFontFromFileU";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
    //You need to set the correct path to your resource font file here.
    string fontResName = gdpicturePDF.AddFontFromFileU("\\WINDOWS\\Fonts\\mingliu.ttc", "MingLiu", FontCharSet.ANSI_CHARSET, false, false);
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        string utext = ((char)(20320)).ToString() + "        " + ((char)(22909)).ToString();
        if ((gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetTextSize(30) == GdPictureStatus.OK) &&
            (gdpicturePDF.DrawText(fontResName, 10, 50, utext) == GdPictureStatus.OK))
        {
            status = gdpicturePDF.SaveToFile("test_AddFontFromFileU.pdf");
            if (status == GdPictureStatus.OK)
                MessageBox.Show("The example HAS been followed successfully.", caption);
        }
        else
            status = gdpicturePDF.GetStat();
    }
    else
    {
        MessageBox.Show("The AddFontFromFileU() method has failed with the status: " + status.ToString(), caption);
        status = GdPictureStatus.OK;
    }
}
if (status != GdPictureStatus.OK)
    MessageBox.Show("The example HAS NOT been followed successfully. The last error status is = " + status.ToString(), caption);
gdpicturePDF.Dispose();
See Also