Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / GetFontCount Method
Example





In This Topic
    GetFontCount Method (GdPicturePDF)
    In This Topic
    Returns the number of fonts used in the currently loaded PDF document.

    A font for use with a PDF consumer application is prepared in the form of a program. Such a font program is written in a special-purpose language, that is understood by a specialized font interpreter.

    Syntax
    'Declaration
     
    
    Public Function GetFontCount() As Integer
    public int GetFontCount()
    public function GetFontCount(): Integer; 
    public function GetFontCount() : int;
    public: int GetFontCount(); 
    public:
    int GetFontCount(); 

    Return Value

    The number of fonts used in the document. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    Please note that 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 oGdPicturePDF As New GdPicturePDF()
    Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("test.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim fontCount As Integer = oGdPicturePDF.GetFontCount()
        status = oGdPicturePDF.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 = oGdPicturePDF.GetFontName(i)
                status = oGdPicturePDF.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 = oGdPicturePDF.GetFontType(i)
                status = oGdPicturePDF.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 = oGdPicturePDF.GetFontEncoding(i)
                status = oGdPicturePDF.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 = oGdPicturePDF.IsFontEmbedded(i)
                status = oGdPicturePDF.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: GetFontCount")
        Else
            MessageBox.Show("The GetFontCount() method has failed with the status: " + status.ToString(), "Example: GetFontCount")
        End If
    Else
        MessageBox.Show("The file can't be loaded.", "Example: GetFontCount")
    End If
    oGdPicturePDF.Dispose()
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    GdPictureStatus status = oGdPicturePDF.LoadFromFile("test.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        int fontCount = oGdPicturePDF.GetFontCount();
        status = oGdPicturePDF.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 = oGdPicturePDF.GetFontName(i);
                status = oGdPicturePDF.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 = oGdPicturePDF.GetFontType(i);
                status = oGdPicturePDF.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 = oGdPicturePDF.GetFontEncoding(i);
                status = oGdPicturePDF.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 = oGdPicturePDF.IsFontEmbedded(i);
                status = oGdPicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                    output = output + ";  Embedded = " + fontEmbedded.ToString() + "\n";
                else
                    output = output + ";  Embedded = Error (" + status.ToString() + ")\n";
            }
            MessageBox.Show(output, "Example: GetFontCount");
        }
        else
        {
            MessageBox.Show("The GetFontCount() method has failed with the status: " + status.ToString(), "Example: GetFontCount");
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", "Example: GetFontCount");
    }
    oGdPicturePDF.Dispose();
    See Also