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 As String, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean _
) As String
public string AddTrueTypeFontFromFile(
string ,
bool ,
bool ,
bool
)
public function AddTrueTypeFontFromFile(
: String;
: Boolean;
: Boolean;
: Boolean
): String;
public function AddTrueTypeFontFromFile(
: String,
: boolean,
: boolean,
: boolean
) : String;
public: string* AddTrueTypeFontFromFile(
string* ,
bool ,
bool ,
bool
)
public:
String^ AddTrueTypeFontFromFile(
String^ ,
bool ,
bool ,
bool
)
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
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 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();
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