I am trying to get the text content of powerpoint files and replace with some
other text. I have a powerpoint file of 20 slides. where 13,14,15,16 slides
have hyperlink to 17,18,19 and 20th slide. I am using XMLSlideshow to
traverse through the slides, But it gives only 16 slides. It does not give
last 4 hyperlinked slides.

Any idea really appreciable in advance how can I get content of all
hyper-linked slides and Replace by some other text.

here is my code.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
public class Testing {
        static String inputFile =
"C:\\Users\\SM78882\\Desktop\\Testing\\IE_Basics_English.pptx";
        static String outputFile =
"C:\\Users\\SM78882\\Desktop\\Testing\\result.pptx";

        public static String replaceUnwantedChar(String originalString) {
                if (null != originalString)
                        return "" + 
originalString.replaceAll("(\n+)|(\t+)|(\\s{2,})", " ")
.trim();
                else
                        return "";
        }
        public static void main(String[] args) {
                FileInputStream fis = null;
                FileOutputStream fos = null;
                XMLSlideShow ppt = null;
                try {
                        fis = new FileInputStream(inputFile);
                        fos = new FileOutputStream(outputFile);
                        ppt = new XMLSlideShow(fis);
                        System.out.println("No of slides:" + 
ppt.getSlides().length); // gives 16 
slides.
                        for (XSLFSlide slide : ppt.getSlides()) {
                                for (XSLFShape shape : slide) {
                                        if (shape instanceof XSLFTextShape) {
                                                XSLFTextShape txShape = 
(XSLFTextShape) shape;
                                                for (XSLFTextParagraph 
xslfParagraph : txShape .getTextParagraphs()) {
                                                        String originalText = 
replaceUnwantedChar(xslfParagraph .getText());
                                                        if 
(!originalText.isEmpty()) {
                                                                String 
translation = "";
                                                                if (translation 
!= null) {
                                                                        
CTRegularTextRun[] ctRegularTextRun = xslfParagraph
.getXmlObject().getRArray();
                                                                        for 
(int index = ctRegularTextRun.length - 1; index > 0; index--) {
                                                                                
xslfParagraph.getXmlObject().removeR( index);
                                                                        }
                                                                        if 
(ctRegularTextRun.length > 0)
                                                                                
ctRegularTextRun[0].setT(translation);
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                        ppt.write(fos);
                        fos.close();
                        fis.close();
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
        }
}






--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Retrieving-content-of-hyperlinked-slides-in-powerpoint-files-PPTX-through-apache-POI-tp5714766.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to