GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetFontData Method
The font index. It must be a value from 1 to GdPicturePDF.GetFontCount.
Output parameter. An array of bytes containing the uncompressed content (data) of the embedded font program.
Example





In This Topic
GetFontData Method (GdPicturePDF)
In This Topic
Returns, in other words extracts, the embedded font program of the font used in the currently loaded PDF document according to the font index you have specified. You can use the GdPicturePDF.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 GdPicturePDF.GetFontCount.

A font program can be embedded in a PDF file as data contained in a PDF stream object. Such a stream object is also called a font file by analogy with font programs that are available from sources external to the consumer application.

Syntax
'Declaration
 
Public Function GetFontData( _
   ByVal FontIdx As Integer, _
   ByRef Data() As Byte _
) As GdPictureStatus
public GdPictureStatus GetFontData( 
   int FontIdx,
   ref byte[] Data
)
public function GetFontData( 
    FontIdx: Integer;
   var  Data: Bytearray of
): GdPictureStatus; 
public function GetFontData( 
   FontIdx : int,
   Data : byte[]
) : GdPictureStatus;
public: GdPictureStatus GetFontData( 
   int FontIdx,
   ref byte[]* Data
) 
public:
GdPictureStatus GetFontData( 
   int FontIdx,
   array<byte>^% Data
) 

Parameters

FontIdx
The font index. It must be a value from 1 to GdPicturePDF.GetFontCount.
Data
Output parameter. An array of bytes containing the uncompressed content (data) of the embedded font program.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.
Remarks
This method is only allowed for use with non-encrypted documents.

Be aware that the font program, which you are going to extract, needs to be embedded in the PDF document. Using this method you are allowed to extract a font program, that is embedded as subset as well.

Example
How to extract the font program for all embedded fonts 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 = gdpicturePDF.GetFontName(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                output = output + "  Name = " + fontName
            Else
                output = output + "  Name = Error (" + status.ToString() + ")"
            End If
            
            Dim fontEmbedded As Boolean = gdpicturePDF.IsFontEmbedded(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                output = output + ";  Embedded = " + fontEmbedded.ToString() + vbCrLf
                If fontEmbedded Then
                    Dim fontData As Byte() = Nothing
                    Dim fontFileData As String = fontName + "_fontData.dat"
                    status = gdpicturePDF.GetFontData(i, fontData)
                    If status = GdPictureStatus.OK Then
                        Dim oFileStream As System.IO.FileStream = Nothing
                        oFileStream = New System.IO.FileStream(fontFileData, System.IO.FileMode.Create)
                        oFileStream.Write(fontData, 0, fontData.Length)
                        oFileStream.Close()
                        output = output + ";  Font data have been saved." + vbCrLf
                    Else
                        output = output + ";  Font data have NOT been saved. Error (" + status.ToString() + ")" + vbCrLf
                    End If
                End If
            Else
                output = output + ";  Embedded = Error (" + status.ToString() + ")" + vbCrLf
            End If
        Next
        MessageBox.Show(output, "Example: GetFontData")
    Else
        MessageBox.Show("The GetFontCount() method has failed with the status: " + status.ToString(), "Example: GetFontData")
    End If
Else
    MessageBox.Show("The file can't be loaded.", "Example: GetFontData")
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 = gdpicturePDF.GetFontName(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
                output = output + "  Name = " + fontName;
            else
                output = output + "  Name = Error (" + status.ToString() + ")";
            
            bool fontEmbedded = gdpicturePDF.IsFontEmbedded(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                output = output + ";  Embedded = " + fontEmbedded.ToString() + "\n";
                if (fontEmbedded)
                {
                    byte[] fontData = null;
                    string fontFileData = fontName + "_fontData.dat";
                    status = gdpicturePDF.GetFontData(i, ref fontData);
                    if (status == GdPictureStatus.OK)
                    {
                        System.IO.FileStream oFileStream = default(System.IO.FileStream);
                        oFileStream = new System.IO.FileStream(fontFileData, System.IO.FileMode.Create);
                        oFileStream.Write(fontData, 0, fontData.Length);
                        oFileStream.Close();
                        output = output + ";  Font data have been saved.\n";
                    }
                    else
                        output = output + ";  Font data have NOT been saved. Error (" + status.ToString() + ")\n";
                }
            }
            else
                output = output + ";  Embedded = Error (" + status.ToString() + ")\n";
        }
        MessageBox.Show(output, "Example: GetFontData");
    }
    else
    {
        MessageBox.Show("The GetFontCount() method has failed with the status: " + status.ToString(), "Example: GetFontData");
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", "Example: GetFontData");
}
gdpicturePDF.Dispose();
See Also