Get List of the Fonts from the PDF File using Aspose.PDF for .NET

Hello,
i try to execute the example show in the documentation. I use the aspose.pdf-11.1.0.jar
//create PdfExtractor object
PdfExtractor pdfExtractor = new PdfExtractor();
//bind input PDF file
pdfExtractor.bindPdf(“easya.pdf”);
//get fonts list
Set resSet = pdfExtractor.getFonts();
//iterating over the elements in the set
Iterator it = resSet.iterator();
while (it.hasNext()) {
//get and display element
Object element = it.next();
System.out.println(element);
}
but the method getFonts() not exits.
How i can resolve?
Thanks a lot.

Hi Filippo,


Thanks for your inquiry. You can use following code snippet to get fonts from Pdf document. It will help you to accomplish the task.

Furthermore, I am afraid getFonts() method is not implemented in PdfExtractor. I will appreciate it if you please point me to the documentation so I will update it as well. We are sorry for the inconvenience.

public static void GetFontsList()<o:p></o:p>

{

Document pdf = new Document(myDir + "test_pdfextractor.pdf");

Map fontNames = new HashMap();

for (int i = 1; i <= pdf.getPages().size(); i++)

{

for (com.aspose.pdf.Font font: (Iterable) pdf.getPages().get_Item(i).getResources().getFonts())

{

if(!fontNames.containsValue(font.getFontName()))

fontNames.put(font.getFontName(),font.getFontName());

}

if (pdf.getPages().get_Item(i).getResources().getForms().size() > 0)

ProcessXForms(pdf.getPages().get_Item(i).getResources().getForms(),fontNames);

}

Set fonts = fontNames.keySet();

for (Iterator font = fonts.iterator(); font.hasNext();)

{

System.out.println("Font found in the PDF document: "+(String)font.next());

}

pdf.dispose();

}

public static void ProcessXForms(com.aspose.pdf.XFormCollection forms,Map fontNames)

{

for (com.aspose.pdf.XForm form: (Iterable)forms)

{

if (form.getResources().getFonts().size()!= 0)

{

for (com.aspose.pdf.Font font: (Iterable)form.getResources().getFonts())

{

if (!fontNames.containsValue(font.getFontName()))

fontNames.put(font.getFontName(),font.getFontName());

}

// recursive call

if (form.getResources().getForms().size() > 0)

ProcessXForms(form.getResources().getForms(), fontNames);

}

}

}


Best Regards,

@filippoangileri

We are excited to share with you that you can now get all fonts from a PDF document using Aspose.PDF for .NET.