How to extract slide title with Aspose Slides for Java

Hello everyone,

I need your help to find out how to use the power of the aspose library to extract information from a PowerPoint file.
I am a beginner with Aspose for Java library.

I do not find how to do the following two tasks:

1 - Extract the title from a slide

2 - Find the true position of a TextFrame because "paragraphs .rect" and "portions coordinates" returns values I don't understand.
My goal with this second solution is to find on slide without specific title shape, the shape located on the top left of the slide having a text with a big text format (a kind of text box that would replace the title on some slides).

Thank you for your help !

Best regards,

------------------------------------------------------------------------------

The following shows values I don't understand:

ISlide asposeSlide = new Presentation(pptFile.getAbsolutePath()).getSlides().get_Item(0);
final ITextFrame[] allTextFrames = SlideUtil.getAllTextBoxes(asposeSlide);
for (ITextFrame textFrame : allTextFrames) {
System.out.println("TextFrame text=" + textFrame.getText());
final Rectangle2D.Float paragraphRect = textFrame.getParagraphs().get_Item(0).getRect();
System.out.println("Paragraph x=" + paragraphRect.x + " y=" + paragraphRect.y);
final Point2D.Float portionCoordinates = textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0).getCoordinates();
System.out.println("Portion x=" + portionCoordinates.x + " y=" + portionCoordinates.y);
System.out.println("");
}

TextFrame text=Presentation title
Paragraph x=144.133 y=111.01297
Portion x=144.133 y=111.01297

TextFrame text=Simple text
Paragraph x=297.99725 y=-1.9948049
Portion x=297.99725 y=-1.9948049

TextFrame text=My company
Paragraph x=0.0 y=9.536743E-7
Portion x=0.0 y=9.536743E-7

Hi,

Thanks for your interest in Aspose.Slides.

I have observed your requirements and suggest you to please try using following sample code to traverse through slide shapes and finding Title placeholder and its position on slide.

public static void ExtractPres()
{
//Loading the presentaiton
Presentation pres=new Presentation(“Test.ppt”);

//Accessing first slide
ISlide asposeSlide = pres.getSlides().get_Item(0);

//Getting all text boxes from slide
final ITextFrame[] allTextFrames = SlideUtil.getAllTextBoxes(asposeSlide);

IShape shape=null;
IAutoShape ashp=null;
//Traversing through all shapes
for(int i=0;i<asposeSlide.getShapes().size();i++)
{
shape=asposeSlide.getShapes().get_Item(0);
if(shape instanceof IAutoShape)
{
ashp=(IAutoShape)shape;
if(ashp.getPlaceholder().getType()==PlaceholderType.Title)
{
System.out.println(“Shape is Title Text Frame”);
}
if(ashp.getTextFrame()!=null)
{
ITextFrame textFrame=ashp.getTextFrame();
System.out.println(“TextFrame text=” + textFrame.getText());
//final Rectangle2D.Float paragraphRect = textFrame.getParagraphs().get_Item(0)…getRect();
System.out.println(“Position X=” +ashp.getX() + " Y=" + ashp.getY());
System.out.println(“Width=” +ashp.getWidth()+ " Height=" + ashp.getHeight());
System.out.println("");

}
}
}
}

Now, coming to your point regarding understanding of position value used by Aspose.Slides. Aspose.Slides use 72 pixels/inch as a units for slide size. So a normal slide with 10’’ x 7.5’’ is mapped with 720 x 540 in Aspose.Slides. The coordinates 0,0 corresponds to top left corner of slide and 720,540 corresponds to bottom right corner of slide. I hope this will be understandable now. Please share if any further help is needed in this regard.

Many Thanks,

Thank you very much for your quick reply, I will try your solution quickly.

Hi Muddssir,
Thanks for above code snippet. I want Similar one. But After getting required textframe and text of it as below code,
ITextFrame textFrame=ashp.getTextFrame();
System.out.println(“TextFrame text=” + textFrame.getText());

I am unable to update text (text is not getting updated in generated slides) by setting it to updated value by using below code

textFrame.setText(“Updated SubTitle”);

Please suggest.

Thanks
Manoj Dhawale

@manojdhawale,

I have observed your comments. Can you please provide complete source code along with environment details and which Aspose.Slides version you are using on your end so that we may further investigate to help you out.

Thanks Adnan for Reply.
I this issue resolved. Actually updating text of textframe is not working. I have to extract portion object from paragraph object which in turns extracted from textframe.
Updating text of portion is visible on ppt.

Thanks

@manojdhawale,

We are glad to know that things are working on your end. Please share feedback with us if there is still an issue.