Tutorial - Extract Font Information

Top  Previous  Next

 

This code snippet demonstrates how to extract font information for fonts present on a particular page.

 

[VC++]

 

       m_PDFDoc.LoadFromFile("InputFile");

       

       CgtPDFFontObjectX PDFFont;

 

       CString str = "The fonts on Page 1 are : \nName\t\tType\n";

 

       for (int i=0; i<m_PDFDoc.GetTotalPDFFontsInPage(1);i++)

       {

               PDFFont = m_PDFDoc.GetPDFFontObjectAtIndex(1,i);

               str = str + PDFFont.GetFontName()+"\t\t"+ PDFFont.GetFontType()+"\n";

       }

 

       MessageBox (str,"Fonts in PDF Document");

 

[CS]

       axgtPDFDocumentX1.LoadFromFile("InputFile");

       PDFtoolkitX.gtPDFFontObjectX PDFFont;

       string str = "The fonts on Page 1 are : \nName\t\tType\n";

       for (int i=0;i<axgtPDFDocumentX1.GetTotalPDFFontsInPage(1);i++)

       {

           PDFFont = axgtPDFDocumentX1.GetPDFFontObjectAtIndex(1,i);

               str = str + i.ToString() +" "+PDFFont.FontName+"\t\t"+                                PDFFont.FontType+"\n";

       }

 

       MessageBox.Show(str, "Fonts in PDF Document");

 

[VB]

       gtPDFDocumentX1.LoadFromFile ("InputFileName")

 

     Dim PDFFont As gtPDFFontObjectX

     Dim str As String

 

     str = "The fonts on Page 1 are : Name Type"

 

     Dim i As Integer

     For i = 0 To gtPDFDocumentX1.GetTotalPDFFontsInPage(2) - 1

         Set PDFFont = gtPDFDocumentX1.GetPDFFontObjectAtIndex(2, i)

         str = str + " " + PDFFont.FontName + " " + PDFFont.FontType

     Next

 

       MsgBox str, vbOKOnly, "Fonts in PDF Document"