Best Way to Identify Header in a Presentation Slide Using Aspose.Slides for Java

Hello, I am trying to output each slide of an input pptx file as a separate presentation (this part works fine). I wish to name the file as the header of the given slide. I’m currently using the below code to identify the header, but it only works about 80% of the time. Other times, it will either fail to return any string, or even return random text from the middle of the body of the slide. Is there a better way to reliably identify the header text of a slide? Please assume that there always is a text header on each slide (I’ve already written a contingency for no header present, which is working).
Thank you

filename = ((IAutoShape)slide.getShapes().get_Item(port)).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getText()

@neelkri,
Thank you for posting the question.

If the content on your presentation slides is freeform, then in general you won’t be able to accurately determine the header of the slide from a text box. But if the slides have a layout applied and the slide headers are contained in placeholders, you can detect them like this:

for (IShape shape : slide.getShapes()) {
    IPlaceholder placeholder = shape.getPlaceholder();
    if (placeholder != null && placeholder.getType() == PlaceholderType.Title) {
        String text = ((IAutoShape) shape).getTextFrame().getText();
        System.out.println(text);
        break;
    }
}