Free Spire.Presentation for Java (免费版)
IntelliJ IDEA
方法1: 可通过e-iceblue官网下载。下载后,解压文件,将lib文件夹下的Spire.Presentation.jar文件导入java程序。
方法2:可通过maven仓库安装导入,配置路径及导入方法可参考链接里的步骤:https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html 。
测试文档如下,包含4页幻灯片内容:
import com.spire.presentation.*; public class Split1 { public static void main(String[] args)throws Exception { //加载测试文档1 Presentation ppt1 = new Presentation(); ppt1.loadFromFile('test1.pptx'); //遍历文档1 for (int i = 0; i < ppt1.getSlides().getCount(); i++) { //新建一个PPT文档,并移除默认生成的第一页幻灯片 Presentation newppt = new Presentation(); newppt.getSlides().removeAt(0); //将每一页添加到新建的文档,并保存 newppt.getSlides().append(ppt1.getSlides().get(i)); newppt.saveToFile(String.format('单页拆分-%1$s.pptx', i), FileFormat.PPTX_2013); } } }
拆分效果:
import com.spire.presentation.*; public class Split2 { public static void main(String[] args) throws Exception{ //加载文档1 Presentation ppt1 = new Presentation(); ppt1.loadFromFile('test1.pptx'); //新建文档1,移除默认生成的第一页幻灯片 Presentation newppt1 = new Presentation(); newppt1.getSlides().removeAt(0); //将文档1中的第一、二页添加到新建的文档1,并保存 for (int i = 0; i < 2; i++) { newppt1.getSlides().append(ppt1.getSlides().get(i)); } newppt1.saveToFile(String.format('拆分1.pptx'), FileFormat.PPTX_2013); //新建文档2,移除默认生成的第一页幻灯片 Presentation newppt2 = new Presentation(); newppt2.getSlides().removeAt(0);//将文档2中的第三、四页添加到新建的文档2,并保存 for(int j = 2;j < 4;j++){ newppt2.getSlides().append(ppt1.getSlides().get(j)); } newppt2.saveToFile(String.format('拆分2.pptx'), FileFormat.PPTX_2013); } }
拆分结果: