GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / GetFontEncoding Method
The font index. It must be a value from 1 to GetFontCount.
Example





In This Topic
GetFontEncoding Method (GdPicturePDF)
In This Topic
Returns the encoding scheme (the base font encoding) of the font used in the currently loaded PDF document according to the font index you have specified. You can use the GetFontCount method to determine the number of all used fonts in the PDF document. The font index is simply an integer value from 1 to GetFontCount.

The font encoding refers to the mapping of a character code to a particular glyph (character shape) description. Each font in a PDF uses a specific type of encoding, either a standard or a custom one. The following types of encoding are supported by the PDF file format: StandardEncoding, WinAnsiEncoding, MacRomanEncoding, MacExpertEncoding, and PDFDocEncoding. For a font that is embedded in the PDF file, the implicit base encoding is the font program's built-in encoding.

Syntax
'Declaration
 
Public Function GetFontEncoding( _
   ByVal FontIdx As Integer _
) As String
public string GetFontEncoding( 
   int FontIdx
)
public function GetFontEncoding( 
    FontIdx: Integer
): String; 
public function GetFontEncoding( 
   FontIdx : int
) : String;
public: string* GetFontEncoding( 
   int FontIdx
) 
public:
String^ GetFontEncoding( 
   int FontIdx
) 

Parameters

FontIdx
The font index. It must be a value from 1 to GetFontCount.

Return Value

The encoding scheme. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Example
How to find out the number of all fonts and their properties used in the PDF document.
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
    Dim fontCount As Integer = gdpicturePDF.GetFontCount()
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        Dim output As String = "The number of fonts used in this document is " + fontCount.ToString() + "." + vbCrLf + vbCrLf
        For i As Integer = 1 To fontCount
            output = output + i.ToString() + ". Font: "
            Dim fontName As String = "", fontType As String = "", fontEncoding As String = ""
            
            'Finding out the name of the used font.
            fontName = gdpicturePDF.GetFontName(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                output = output + "  Name = " + fontName
            Else
                output = output + "  Name = Error (" + status.ToString() + ")"
            End If
            
            'Finding out the type of the used font.
            fontType = gdpicturePDF.GetFontType(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                output = output + ";  Type = " + fontType
            Else
                output = output + ";  Type = Error (" + status.ToString() + ")"
            End If
            
            'Finding out the font encoding of the used font.
            fontEncoding = gdpicturePDF.GetFontEncoding(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                output = output + ";  Encoding = " + fontEncoding
            Else
                output = output + ";  Encoding = Error (" + status.ToString() + ")"
            End If
            
            'Finding out if the used font is embedded.
            Dim fontEmbedded As Boolean = gdpicturePDF.IsFontEmbedded(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                output = output + ";  Embedded = " + fontEmbedded.ToString() + vbCrLf
            Else
                output = output + ";  Embedded = Error (" + status.ToString() + ")" + vbCrLf
            End If
        Next
        MessageBox.Show(output, "Example: GetFontEncoding")
    Else
        MessageBox.Show("The GetFontCount() method has failed with the status: " + status.ToString(), "Example: GetFontEncoding")
    End If
Else
    MessageBox.Show("The file can't be loaded.", "Example: GetFontEncoding")
End If
gdpicturePDF.Dispose()
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
    int fontCount = gdpicturePDF.GetFontCount();
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        string output = "The number of fonts used in this document is " + fontCount.ToString() + ".\n\n";
        for (int i = 1; i <= fontCount; i++)
        {
            output = output + i.ToString() + ". Font: ";
            string fontName = "", fontType = "", fontEncoding = "";
            
            //Finding out the name of the used font.
            fontName = gdpicturePDF.GetFontName(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
                output = output + "  Name = " + fontName;
            else
                output = output + "  Name = Error (" + status.ToString() + ")";
            
            //Finding out the type of the used font.
            fontType = gdpicturePDF.GetFontType(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
                output = output + ";  Type = " + fontType;
            else
                output = output + ";  Type = Error (" + status.ToString() + ")";
            
            //Finding out the font encoding of the used font.
            fontEncoding = gdpicturePDF.GetFontEncoding(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
                output = output + ";  Encoding = " + fontEncoding;
            else
                output = output + ";  Encoding = Error (" + status.ToString() + ")";
            
            //Finding out if the used font is embedded.
            bool fontEmbedded = gdpicturePDF.IsFontEmbedded(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
                output = output + ";  Embedded = " + fontEmbedded.ToString() + "\n";
            else
                output = output + ";  Embedded = Error (" + status.ToString() + ")\n";
        }
        MessageBox.Show(output, "Example: GetFontEncoding");
    }
    else
    {
        MessageBox.Show("The GetFontCount() method has failed with the status: " + status.ToString(), "Example: GetFontEncoding");
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", "Example: GetFontEncoding");
}
gdpicturePDF.Dispose();
See Also