String inputFile ="字体导出测试.pptx";
String outputFile="output";
File file =new File(outputFile);
if(!file.exists()){
file.mkdirs();
}
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
//设置自定义字体,您可以将字体文件放入font文件夹下
ppt.setCustomFontsFolder("font\\");
ISlide iSlide = ppt.getSlides().get(0);
IShape iShape = iSlide.getShapes().get(0);
if (iShape instanceof IAutoShape){
ITextFrameProperties textFrame = ((IAutoShape) iShape).getTextFrame();
TextRangeCollection textRanges = textFrame.getParagraphs().get(0).getTextRanges();
for (int i = 0; i < textRanges.size(); i++) {
PortionEx portionEx = textRanges.get(i);
portionEx.setEastAsianFont(new TextFont("迷你简粗倩"));
portionEx.setLatinFont(new TextFont("迷你简粗倩"));
}
}
//将ppt转为图片
for (int i = 0; i < ppt.getSlides().getCount(); i++) {
BufferedImage image = ppt.getSlides().get(i).saveAsImage();
String fileName = outputFile + "/" + String.format("ToImage-%1$s.png", i);
ImageIO.write(image, "PNG",new File(fileName));
}
ppt.saveToFile("b.pptx",FileFormat.PPTX_2016);
ppt.dispose();
// 我使用上述代码 将字体文件内嵌 再设置ppt中的文本字体为 我自己下载的字体文件 但是不生效 无论是图片还是ppt, 而且图片和ppt的显示还不一样
// 测试文件在附件
// spire for java version 7.12.4