AddTrueTypeFont Method (GdPicturePDF)
                                 
                                
                                    
                                        In This Topic
                                    
                                
                                Adds a TrueType or OpenType system font to the currently loaded PDF document according to a font name and other parameters you have specified. Please note that only ANSI characters are supported when using this font to display some text. 
The TrueType font format has been adopted as a standard font format for the Microsoft Windows operating system. A TrueType font program can be embedded directly in a PDF file as a stream object.
 
            
            
            Syntax
            
            
            
            
            'Declaration
 
Public Function AddTrueTypeFont( _
   ByVal  As String, _
   ByVal  As Boolean, _
   ByVal  As Boolean, _
   ByVal  As Boolean _
) As String
             
        
            
            public string AddTrueTypeFont( 
   string ,
   bool ,
   bool ,
   bool 
)
             
        
            
            public function AddTrueTypeFont( 
    : String;
    : Boolean;
    : Boolean;
    : Boolean
): String; 
             
        
            
            public function AddTrueTypeFont( 
    : String,
    : boolean,
    : boolean,
    : boolean
) : String;
             
        
            
            public: string* AddTrueTypeFont( 
   string* ,
   bool ,
   bool ,
   bool 
) 
             
        
            
            public:
String^ AddTrueTypeFont( 
   String^ ,
   bool ,
   bool ,
   bool 
) 
             
        
             
        
            Parameters
- FontName
 
- The name of the required system 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.
 - 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 
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.
 
            
            
            
            
            
            Example
How to add a True Type system font 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: AddTrueTypeFont"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
    Dim fontResNameBold As String = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", True, False, False)
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        Dim fontResNameBoldItalic As String = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", True, True, 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(fontResNameBold, 10, 50, "Here is some bold text") = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.DrawText(fontResNameBoldItalic, 10, 100, "Here is some bold italic text") = GdPictureStatus.OK) Then
                status = gdpicturePDF.SaveToFile("test_AddTrueTypeFont.pdf")
                If status = GdPictureStatus.OK Then
                    MessageBox.Show("The example HAS been followed successfully. Both fonts have been added to the newly created document.", caption)
                End If
            Else
                status = gdpicturePDF.GetStat()
            End If
        Else
            MessageBox.Show("The AddTrueTypeFont() method for bold italic font has failed with the status: " + status.ToString(), caption)
            status = GdPictureStatus.OK
        End If
    Else
        MessageBox.Show("The AddTrueTypeFont() method for bold font 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: AddTrueTypeFont";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
    string fontResNameBold = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", true, false, false);
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        string fontResNameBoldItalic = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", true, true, false);
        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(fontResNameBold, 10, 50, "Here is some bold text") == GdPictureStatus.OK) &&
                (gdpicturePDF.DrawText(fontResNameBoldItalic, 10, 100, "Here is some bold italic text") == GdPictureStatus.OK))
            {
                status = gdpicturePDF.SaveToFile("test_AddTrueTypeFont.pdf");
                if (status == GdPictureStatus.OK)
                    MessageBox.Show("The example HAS been followed successfully. Both fonts have been added to the newly created document.", caption);
            }
            else
                status = gdpicturePDF.GetStat();
        }
        else
        {
            MessageBox.Show("The AddTrueTypeFont() method for bold italic font has failed with the status: " + status.ToString(), caption);
            status = GdPictureStatus.OK;
        }
    }
    else
    {
        MessageBox.Show("The AddTrueTypeFont() method for bold font 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();
	 
	
 
 
            
            Example
How to add a True Type system font 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: AddTrueTypeFont"
            Dim gdpicturePDF As New GdPicturePDF()
            Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
            If status = GdPictureStatus.OK Then
                gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
                gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
                Dim fontResNameBold As String = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", True, False, False)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    Dim fontResNameBoldItalic As String = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", True, True, 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(fontResNameBold, 10, 50, "Here is some bold text") = GdPictureStatus.OK) AndAlso
                           (gdpicturePDF.DrawText(fontResNameBoldItalic, 10, 100, "Here is some bold italic text") = GdPictureStatus.OK) Then
                            status = gdpicturePDF.SaveToFile("test_AddTrueTypeFont.pdf")
                            If status = GdPictureStatus.OK Then
                                MessageBox.Show("The example HAS been followed successfully. Both fonts have been added to the newly created document.", caption)
                            End If
                        Else
                            status = gdpicturePDF.GetStat()
                        End If
                    Else
                        MessageBox.Show("The AddTrueTypeFont() method for bold italic font has failed with the status: " + status.ToString(), caption)
                        status = GdPictureStatus.OK
                    End If
                Else
                    MessageBox.Show("The AddTrueTypeFont() method for bold font 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: AddTrueTypeFont";
            GdPicturePDF gdpicturePDF = new GdPicturePDF();
            GdPictureStatus status = gdpicturePDF.NewPDF();
            if (status == GdPictureStatus.OK)
            {
                gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
                gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
                string fontResNameBold = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", true, false, false);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    string fontResNameBoldItalic = gdpicturePDF.AddTrueTypeFont("TimesNewRoman", true, true, false);
                    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(fontResNameBold, 10, 50, "Here is some bold text") == GdPictureStatus.OK) &&
                            (gdpicturePDF.DrawText(fontResNameBoldItalic, 10, 100, "Here is some bold italic text") == GdPictureStatus.OK))
                        {
                            status = gdpicturePDF.SaveToFile("test_AddTrueTypeFont.pdf");
                            if (status == GdPictureStatus.OK)
                                MessageBox.Show("The example HAS been followed successfully. Both fonts have been added to the newly created document.", caption);
                        }
                        else
                            status = gdpicturePDF.GetStat();
                    }
                    else
                    {
                        MessageBox.Show("The AddTrueTypeFont() method for bold italic font has failed with the status: " + status.ToString(), caption);
                        status = GdPictureStatus.OK;
                    }
                }
                else
                {
                    MessageBox.Show("The AddTrueTypeFont() method for bold font 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