Aspose.Slides for Java v17.6
I’m trying to convert powerpoint files to txt using PresentationFactory.getInstance().getPresentationText(…)
When I try to convert PPT files, Aspose.Slides arrange the text correctly. However, using PPTX files the text file isn’t arranged. Please see the source code below and the files attached to this topic. How to fix this?
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import com.aspose.slides.IPresentationText;
import com.aspose.slides.ISlideText;
import com.aspose.slides.PresentationFactory;
import com.aspose.slides.TextExtractionArrangingMode;
public class TestPPTXToTXT {
public static void main(String[] args) throws Exception {
convertPowerPointToTXT("E:\\Download\\powerpoint\\Test1.ppt", "E:\\Download\\powerpoint\\Test1.txt");
convertPowerPointToTXT("E:\\Download\\powerpoint\\Test2.pptx", "E:\\Download\\powerpoint\\Test2.txt");
}
private static void convertPowerPointToTXT(String fileFrom, String fileTo) throws IOException {
IPresentationText presentationText =
PresentationFactory.getInstance().getPresentationText(fileFrom, TextExtractionArrangingMode.Arranged);
ISlideText[] slidesText = presentationText.getSlidesText();
StringBuffer stringBuffer = new StringBuffer();
// Loop through the Array of TextFrames
for (int i = 0; i < slidesText.length; i++) {
stringBuffer.append(slidesText[i].getText());
}
FileUtils.writeStringToFile(FileUtils.getFile(fileTo), stringBuffer.toString(), StandardCharsets.UTF_8);
}
}
powerpoint.zip (253.0 KB)
This Topic is created by codewarior using the Email to Topic plugin.
This Topic is created by codewarior using the Email to Topic plugin.