Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Tue Jun 28, 2022 8:27 am

Hi All,

I need to extract the text value from AutoShape which is given in the Layouts in Slide Master. Using the following code:

Code: Select all
Presentation presentation = new Presentation();
        presentation.loadFromFile("test.pptx");
        ISlide slide = presentation.getSlides().get(1);
        IMasterLayouts layouts = presentation.getMasters().get(0).getLayouts() ;
        int length = layouts.getCount() ;
        for ( int licounter = 0; licounter < length; licounter++ )
        {
           if ( layouts.get(licounter).getName().equalsIgnoreCase("Page 1 - Title Page") )
           {
              //ISlide[] slides = layouts.get(licounter).getDependingSlides() ;
              //printShapes(slides[0].getShapes().toArray()) ;
           }
        }


I need to get the list of shapes on the layouts. Can somebody help in figuring out how to get the list of shapes on layouts and then extract values from them?

sachdevajs
 
Posts: 1
Joined: Mon Jun 27, 2022 3:10 pm

Wed Jun 29, 2022 3:13 am

Hello,

Thanks for your inquiry.
Please refer to the code below to achieve your needs. If you there is any other questions, please feel free to write back.
Code: Select all
   
        Presentation ppt = new Presentation();
        ppt.loadFromFile("Presentation.pptx");
        //loop through masters
        for (int i = 0;i<ppt.getMasters().getCount(); i++) {
            IMasterLayouts masterlayouts = ppt.getMasters().get(i).getLayouts();
            //get master layouts
            for (int j=0;j<masterlayouts.getCount();j++)
            {
                ActiveSlide activeSlide=(ActiveSlide) masterlayouts.get(j);
                //loop through all shapes
                for (IShape shape:(Iterable<? extends IShape>) activeSlide.getShapes()) {
                    if (shape instanceof IAutoShape)
                    {
                        String text=((IAutoShape) shape).getTextFrame().getParagraphs().get(0).getText();
                        System.out.println(text);
                    }
                }
            }
        }

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 200
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Presentation