GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / AddTrueTypeFontFromFile Method
The file path of the resource font file.
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.
Set this parameter to true if you want to embed the font in the PDF document, otherwise set it to false.

Please note that embedding the font in the file significantly increases the filesize.

Example





In This Topic
AddTrueTypeFontFromFile Method (GdPicturePDF)
In This Topic
Adds a TrueType or OpenType font from a file to the currently loaded PDF document according to a font file path and other parameters you have specified. Please note that only ANSI characters are supported when using this font to display some text.
Syntax
'Declaration
 
Public Function AddTrueTypeFontFromFile( _
   ByVal FilePath As String, _
   ByVal Bold As Boolean, _
   ByVal Italic As Boolean, _
   ByVal Embedded As Boolean _
) As String
public string AddTrueTypeFontFromFile( 
   string FilePath,
   bool Bold,
   bool Italic,
   bool Embedded
)
public function AddTrueTypeFontFromFile( 
    FilePath: String;
    Bold: Boolean;
    Italic: Boolean;
    Embedded: Boolean
): String; 
public function AddTrueTypeFontFromFile( 
   FilePath : String,
   Bold : boolean,
   Italic : boolean,
   Embedded : boolean
) : String;
public: string* AddTrueTypeFontFromFile( 
   string* FilePath,
   bool Bold,
   bool Italic,
   bool Embedded
) 
public:
String^ AddTrueTypeFontFromFile( 
   String^ FilePath,
   bool Bold,
   bool Italic,
   bool Embedded
) 

Parameters

FilePath
The file path of the resource font file.
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.
Embedded
Set this parameter to true if you want to embed the font in the PDF document, otherwise set it to false.

Please note that embedding the font in the file significantly increases the filesize.

Return Value

Returns a resource name of the specified font required for the next usage within the PDF document. The GdPicturePDF.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 GdPicturePDF.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 GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Example
How to add a TrueType font from the specified file to the newly created PDF document. The font resource name is subsequently used to draw some text on the newly created page.
Dim caption As String = "Example: AddTrueTypeFontFromFile"
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.AddTrueTypeFontFromFile("\WINDOWS\Fonts\webdings.ttf", False, False, True)
    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, "Here is some text") = GdPictureStatus.OK) Then
            status = gdpicturePDF.SaveToFile("test_AddTrueTypeFontFromFile.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 AddTrueTypeFontFromFile() 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: AddTrueTypeFontFromFile";
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.AddTrueTypeFontFromFile("\\WINDOWS\\Fonts\\webdings.ttf", false, false, true);
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        if ((gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetFillColor(255, 0, 0) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetTextSize(30) == GdPictureStatus.OK) &&
            (gdpicturePDF.DrawText(fontResName, 10, 50, "Here is some text") == GdPictureStatus.OK))
        {
            status = gdpicturePDF.SaveToFile("test_AddTrueTypeFontFromFile.pdf");
            if (status == GdPictureStatus.OK)
                MessageBox.Show("The example HAS been followed successfully.", caption);
        }
        else
            status = gdpicturePDF.GetStat();
    }
    else
    {
        MessageBox.Show("The AddTrueTypeFontFromFile() 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