The file path of the resource font file.
The name of the required font to add for use in the PDF document.
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 subset the font, otherwise set it to false.

Subsetting a font allows you to keep a file smaller, but note that the font subset is gradually updated with each use of the GdPicturePDF.DrawText method.

Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / AddTrueTypeFontFromFileU Method

AddTrueTypeFontFromFileU Method (GdPicturePDF)

In This Topic
Adds an embedded 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. The displaying of Unicode characters is supported when using the font added by this method.
Syntax
'Declaration
 
Public Function AddTrueTypeFontFromFileU( _
   ByVal FilePath As String, _
   ByVal FileName As String, _
   ByVal Bold As Boolean, _
   ByVal Italic As Boolean, _
   ByVal EnableSubset As Boolean _
) As String
public string AddTrueTypeFontFromFileU( 
   string FilePath,
   string FileName,
   bool Bold,
   bool Italic,
   bool EnableSubset
)
public function AddTrueTypeFontFromFileU( 
    FilePath: String;
    FileName: String;
    Bold: Boolean;
    Italic: Boolean;
    EnableSubset: Boolean
): String; 
public function AddTrueTypeFontFromFileU( 
   FilePath : String,
   FileName : String,
   Bold : boolean,
   Italic : boolean,
   EnableSubset : boolean
) : String;
public: string* AddTrueTypeFontFromFileU( 
   string* FilePath,
   string* FileName,
   bool Bold,
   bool Italic,
   bool EnableSubset
) 
public:
String^ AddTrueTypeFontFromFileU( 
   String^ FilePath,
   String^ FileName,
   bool Bold,
   bool Italic,
   bool EnableSubset
) 

Parameters

FilePath
The file path of the resource font file.
FileName
The name of the required font to add for use in the PDF document.
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.
EnableSubset
Set this parameter to true if you want to subset the font, otherwise set it to false.

Subsetting a font allows you to keep a file smaller, but note that the font subset is gradually updated with each use of the GdPicturePDF.DrawText method.

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 unicode text on the newly created page.
Dim caption As String = "Example: AddTrueTypeFontFromFileU"
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.AddTrueTypeFontFromFileU("\Windows\Fonts\SimSun.ttc", "SimSun", 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, ChrW(20320) + "        " + ChrW(22909)) = GdPictureStatus.OK) Then
            status = gdpicturePDF.SaveToFile("test_AddTrueTypeFontFromFileU.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 AddTrueTypeFontFromFileU() 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: AddTrueTypeFontFromFileU";
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.AddTrueTypeFontFromFileU("\\Windows\\Fonts\\SimSun.ttc", "SimSun", false, false, true);
    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_AddTrueTypeFontFromFileU.pdf");
            if (status == GdPictureStatus.OK)
                MessageBox.Show("The example HAS been followed successfully.", caption);
        }
        else
            status = gdpicturePDF.GetStat();
    }
    else
    {
        MessageBox.Show("The AddTrueTypeFontFromFileU() 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