Fonts

How can I query a document to find out which fonts are used? If it is possible, then please provide a code example on how to do this.


Ideally I don’t want to have to iterate through every slide to do this.

Thanks.


I wrote the code below (using aspose.slides for java) to determine what fonts are used in a presentation (powerpoint [.pptx] file).

The text in the powerpoint file is english. Multiple fonts are used (8 different fonts).

My problem is that this code is only able to detect fonts on the first slide. For every other slide, it says that the text-portion has no font :s. Am I doing something wrong? Have I missed some configuration/setting? Or is this a bug? I can attach the file for you if you like (the size of the file is approximately 1 MB).

public Set findFonts(File slides) throws Exception {
Set fonts = new HashSet<>();
try (ByteArrayInputStream bis = new ByteArrayInputStream(IOUtils.toByteArray(new FileInputStream(slides)))) {
Presentation presentation = new Presentation(bis, loadOptionsForSlides());
for (ISlide slide : presentation.getSlides()) {
for (int i = 0; i < slide.getShapes().size(); i++) {
IAutoShape shape = (IAutoShape) slide.getShapes().get_Item(i);
for (int j = 0; j < shape.getTextFrame().getParagraphs().getCount(); j++) {
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(j);
for (int k = 0; k < paragraph.getPortions().getCount(); k++) {
IPortion portion = paragraph.getPortions().get_Item(k);
IFontData latinFontData = portion.getPortionFormat().getLatinFont();
if (latinFontData != null) {
fonts.add(latinFontData.getFontName());
} else {
System.out.println("latin font data is null for portion with text: " + portion.getText());
}
}
}
}
}
}
return fonts;

Hi,

Thank you for sharing the sample code and template file.

I am able to reproduce your mentioned issue after an initial test. Your issue has been registered in our issue tracking system with issue id: SLIDESJAVA-34549. You will be notified via this forum thread once the issue gets resolved.

Thanks & Regards,

The issues you have found earlier (filed as SLIDESJAVA-34549) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.