We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get styling details of a word in a shape?

Hi,

Can you please help I want to fetch the styling property of a word within the shape is it possible to do that in Aspose slide java?

Below zip contains a presentation file for investigation. In that file I have to get styling details of “[dynamic]” word, details like font family, font size, color, bold, italic, etc.

assets.zip (23.2 KB)

I am using Aspose slide java version 20.4.

Thanks & Regards,
Saquib Shaikh.

@saquibs,

Please try using following sample code to serve the purpose.

public static void FetchTextProps()
{
    String TextToFind="[dynamic]";
    String path="C:\\Users\\mudas\\Downloads\\assets\\";
    Presentation pres=new Presentation (path+"dynamicText.pptx");
    for(ISlide slide: pres.getSlides())
    {
        for(IShape shape:slide.getShapes())
        {
            if(shape instanceof IAutoShape)
            {
                IAutoShape ashp=(IAutoShape)shape;
                if(ashp.getTextFrame()!=null)
                {
                    for(IParagraph para: ashp.getTextFrame().getParagraphs())
                    {
                        for(IPortion portion:para.getPortions())
                        {
                            if(portion.getText().compareTo(TextToFind)==0)
                            {
                                System.out.println("Text Found: "+portion.getText());
                                IPortionFormat format=portion.getPortionFormat();
                                System.out.println("Text Bold: "+format.getFontBold());
                                System.out.println("Text Italic: "+format.getFontItalic());
                                System.out.println("Text Font: "+format.getLatinFont().getFontName());
                                System.out.println("Text Color: "+format.getFillFormat().getSolidFillColor().getColor());
                                
                            
                            }
                        }
                    }
                }
            }
        }
    }
 

}

Hi, Thank you so much for the code snippet. I have worked with it but I have to inform you that it was not worked as per the expectation.

In given presentation file there are 6 shapes each of having “[dynamic]” word in a sentence but this code has only read a shape which is having only [dynamic] word.

I want to read each shape [dynamic] word styling from the sentence.

Thanks,
Saquib Shaikh

@saquibs,

Please try using following sample code on your end. There was text distribution issue in portion of text inside presentation.

public static void FetchTextProps()
{
    int i=1;
    String TextToFind="[dynamic]";
    String path="C:\\Users\\mudas\\Downloads\\assets\\";
    Presentation pres=new Presentation (path+"dynamicText.pptx");
    pres.joinPortionsWithSameFormatting();
    for(ISlide slide: pres.getSlides())
    {
        for(IShape shape:slide.getShapes())
        {
            if(shape instanceof IAutoShape)
            {
                IAutoShape ashp=(IAutoShape)shape;
                if(ashp.getTextFrame()!=null)
                {
             
                    for(IParagraph para: ashp.getTextFrame().getParagraphs())
                    {
                        for(IPortion portion:para.getPortions())
                        {
                            //System.out.println("Portion Text: "+portion.getText());

                            //if(portion.getText().compareTo(TextToFind)==0)
                            if(portion.getText().contains(TextToFind))
                            {
                                System.out.println("Text Found: "+portion.getText());
                                System.out.println("Instance  "+i);
                                i++;
                                IPortionFormat format=portion.getPortionFormat();
                                System.out.println("Text Bold: "+format.getFontBold());
                                System.out.println("Text Italic: "+format.getFontItalic());
                                //System.out.println("Text Font: "+format.getLatinFont().getFontName());
                                System.out.println("Text Color: "+format.getFillFormat().getSolidFillColor().getColor());
                                System.out.println("\n\n");
                                
                            
                            }
                        }
                    }
                }
            }
        }
    }
 

}