调通了ppt文件解析
This commit is contained in:
parent
f9a9fee343
commit
6c1e024d51
|
|
@ -15,10 +15,7 @@ public class PptParse extends FileParse {
|
|||
String res = "";
|
||||
try {
|
||||
FileUtil.writeFromStream(stream, fileTmpPath);
|
||||
if (fileType.endsWith("pptx")) {
|
||||
res = OfficeFileUtil.parsePptxAllText(fileTmpPath);
|
||||
}
|
||||
res = OfficeFileUtil.parsePptAllText(fileTmpPath);
|
||||
res = fileType.endsWith("pptx") ? OfficeFileUtil.parsePptxAllText(fileTmpPath) : OfficeFileUtil.parsePptAllText(fileTmpPath);
|
||||
} catch (Exception e) {
|
||||
log.error("解析{}格式的ppt错误,具体为{}",fileType, e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,17 +175,19 @@ public class OfficeFileUtil {
|
|||
}
|
||||
|
||||
public static String parsePptAllText(String filePath) throws IOException {
|
||||
log.info("Start parse ppt file, path is {}", filePath);
|
||||
return handlePptFile(filePath, false);
|
||||
}
|
||||
|
||||
public static String parsePptxAllText(String filePath) throws IOException {
|
||||
log.info("Start parse pptx file, path is {}", filePath);
|
||||
return handlePptFile(filePath, true);
|
||||
}
|
||||
|
||||
private static String handlePptFile(String path, boolean isPptx) throws IOException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
InputStream input = Files.newInputStream(Paths.get(path));
|
||||
String pptText = isPptx ? new SlideShowExtractor(new HSLFSlideShow(input)).getText() : new SlideShowExtractor(new XMLSlideShow(input)).getText();
|
||||
String pptText = isPptx ? new SlideShowExtractor(new XMLSlideShow(input)).getText() : new SlideShowExtractor(new HSLFSlideShow(input)).getText();
|
||||
stringBuilder.append(pptText);
|
||||
return EleCommonUtil.formateString(stringBuilder.toString());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue