GetTextHeight(String,Single) Method
In This Topic
Calculates the height of the font you have specified, expressed in the current units used in the loaded PDF document, without respecting the font boundary box.
You can use the GdPicturePDF.GetMeasurementUnit method to determine the currently defined units and you can also use the GdPicturePDF.SetMeasurementUnit method to reset the units according to your preference.
Syntax
'Declaration
Public Overloads Function GetTextHeight( _
ByVal As String, _
ByVal As Single _
) As Single
public float GetTextHeight(
string ,
float
)
public function GetTextHeight(
: String;
: Single
): Single;
public function GetTextHeight(
: String,
: float
) : float;
public: float GetTextHeight(
string* ,
float
)
public:
float GetTextHeight(
String^ ,
float
)
Parameters
- FontResName
- The resource name of the font you prefer.
You can easily obtain this name using the GdPicturePDF.AddStandardFont method or any of the AddTrueTypeFont...() methods. For further assistance, please see the section Fonts of the GdPicturePDF class in the Reference Guide.
- TextSize
- The size of the text (the font size actually), in points.
Return Value
The height of the specified font, expressed in the current units specified by the SetMeasurementUnit method, not respecting the font boundary box.
The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Example
How to determine the height of the standard Times-Roman font.
Dim caption As String = "Example: GetTextHeight"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
Dim fontName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesRoman)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim height As Single = gdpicturePDF.GetTextHeight(fontName, 20)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
MessageBox.Show("The height of the Times-Roman font with the size 20 is " + height.ToString() + " centimeters.", caption)
Else
MessageBox.Show("The GetTextHeight() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("Units can't be set correctly.", caption)
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetTextHeight";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
string fontName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesRoman);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
float height = gdpicturePDF.GetTextHeight(fontName, 20);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
MessageBox.Show("The height of the Times-Roman font with the size 20 is " + height.ToString() + " centimeters.", caption);
else
MessageBox.Show("The GetTextHeight() method has failed with the status: " + status.ToString(), caption);
}
else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + status.ToString(), caption);
}
else
MessageBox.Show("Units can't be set correctly.", caption);
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
Example
How to determine the height of the standard Times-Roman font.
Dim caption As String = "Example: GetTextHeight"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
Dim fontName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesRoman)
If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
Dim height As Single = gdpicturePDF.GetTextHeight(fontName, 20)
status = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
MessageBox.Show("The height of the Times-Roman font with the size 20 is " + height.ToString() + " centimeters.", caption)
Else
MessageBox.Show("The GetTextHeight() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + status.ToString(), caption)
End If
Else
MessageBox.Show("Units can't be set correctly.", caption)
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetTextHeight";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
string fontName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesRoman);
if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
{
float height = gdpicturePDF.GetTextHeight(fontName, 20);
status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
MessageBox.Show("The height of the Times-Roman font with the size 20 is " + height.ToString() + " centimeters.", caption);
else
MessageBox.Show("The GetTextHeight() method has failed with the status: " + status.ToString(), caption);
}
else
MessageBox.Show("The AddStandardFont() method has failed with the status: " + status.ToString(), caption);
}
else
MessageBox.Show("Units can't be set correctly.", caption);
}
else
MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also