public String conversionFile(ConversionDTO conversionDTO){
final String targetPath = conversionDTO.getTargetPath();
String savePath = null;
final String srcPath = conversionDTO.getSrcPath();
log.info(“>>>>开始解析ppt>>>”+srcPath);
savePath = targetPath + conversionDTO.getFileName();
final Presentation pres = new Presentation(srcPath);
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setDefaultRegularFont(FileConvertConstant.DEFAULT_FONT);
pdfOptions.setWarningCallback(new HandleFontsWarnings());
final IFontsManager fontsManager = pres.getFontsManager();
// 获取ppt里面所有的字体
IFontData[] embeddedFonts = fontsManager.getFonts();
FontsLoader.loadExternalFonts(new String[]{FileConvertConstant.FONT_PATH});
if(embeddedFonts.length > 0){
for (IFontData embeddedFont : embeddedFonts) {
final String fontName = embeddedFont.getFontName();
log.warn("font :{} not find",fontName);
// 最后指定默认的
fontsManager.replaceFont(embeddedFont, new FontData(FileConvertConstant.DEFAULT_FONT));
}
}
pres.save(savePath, SaveFormat.Pdf,pdfOptions);
log.info(">>>解析成功>>>"+savePath);
if(Objects.nonNull(pres)){
pres.dispose();
}
return savePath;
}
image.png (52.1 KB)