package com.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import com.aspose.cells.PdfSaveOptions;
import com.aspose.cells.Workbook;
import com.aspose.slides.Presentation;
import com.aspose.words.Document;
public class AsposeUtil {
/**
* 获取license
*
* @return
*/
public static boolean getLicense(int type) {
boolean result = false;
try {
InputStream is = TestEcxel.class.getClassLoader().getResourceAsStream("license.xml");
if(type == 1) {//excel
com.aspose.cells.License aposeLic = new com.aspose.cells.License();
aposeLic.setLicense(is);
result = true;
} else if (type == 2) {//word
com.aspose.words.License aposeLic = new com.aspose.words.License();
aposeLic.setLicense(is);
result = true;
} else {//ppt
com.aspose.slides.License aposeLic = new com.aspose.slides.License();
aposeLic.setLicense(is);
result = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void Excel2Pdf() {
// 验证License
if (!getLicense(1)) {
return;
}
try {
long old = System.currentTimeMillis();
Workbook wb = new Workbook("D:\\pdftest\\Book1 - 副本.xlsx");// 原始excel路径
File pdfFile = new File("D:\\pdftest\\Book1 - 副本.pdf");// 输出路径
FileOutputStream fileOS = new FileOutputStream(pdfFile);
//wb.save(fileOS, com.aspose.cells.SaveFormat.PDF);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
wb.save(fileOS, pdfSaveOptions);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void Word2Pdf() {
// 验证License
if (!getLicense(2)) {
return;
}
try {
long old = System.currentTimeMillis();
Document doc = new Document("D:\\pdftest\\OKAY-HR-ZZ01-V5.0转正申请表.doc");// 原始word路径
File pdfFile = new File("D:\\pdftest\\OKAY-HR-ZZ01-V5.0转正申请表.pdf");// 输出路径
FileOutputStream fileOS = new FileOutputStream(pdfFile);
doc.save(fileOS, com.aspose.words.SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void PPT2Pdf() {
// 验证License
if (!getLicense(3)) {
return;
}
try {
long old = System.currentTimeMillis();
InputStream slides = new FileInputStream(new File("D:\\pdftest\\第12章获取openid讲解.pptx"));// 原始ppt路径
Presentation pres = new Presentation(slides);
File file = new File("D:\\pdftest\\第12章获取openid讲解.pdf");// 输出pdf路径
FileOutputStream fileOS = new FileOutputStream(file);
pres.save(fileOS, com.aspose.slides.SaveFormat.Pdf);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒\n\n" + "文件保存在:" + file.getPath());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Excel2Pdf();
//Word2Pdf();
//PPT2Pdf();
}
}

slinvoyage
- 粉丝: 3
最新资源
- 孤岛型微电网中改进下垂控制策略:'虚拟阻抗与无功均分的应用'
- 医药洁净室温湿度串级PID控制:基于200smart PLC的创新实现与挑战 专业版
- 基于Vuejs框架构建的现代化前端单页面应用项目-包含热重载开发服务器和Webpack生产环境构建配置-通过npm脚本命令实现依赖安装开发调试与生产打包-使用vue-loader.zip
- MATLAB中灰狼算法与改狼算法对23种测试函数的性能探究及应用前景 系统版
- 基于混合决策规则与Wasserstein度量的分布式鲁棒多阶段框架:适应风电渗透下的机组不确定性承诺与调度策略优化
- 电力电子领域Z源逆变器并网闭环仿真的L滤波器动态性能分析与应用
- 单相有源Boost PFC功率因数矫正电路设计原理与应用(220V交流转400V直流,功率200W)
- 基于Abaqus与Matlab蜂群算法耦合的结构优化程序研究及其工程应用 - Abaqus
- 基于配置化数据表格与动态图表展示的交互式数据可视化工具-支持拖拽排序-自定义样式-实时预览-多格式导出-响应式布局-数据绑定-配置驱动-JSON导入导出-Excel兼容-数据筛选-.zip
- 电机控制领域FOC电流环PI参数自整定Simulink仿真模型及其应用
- 一个目标检测图像增强的示例脚本
- 基于遗产算法的多目标分布式电源选址定容策略仿真研究:以投资成本等三目标实现方案验证 - 多目标优化
- BabeLua,一款vs的lua开发软件
- (雷同的那个是营销号)YOLOv8检测模块组合优化改进(成功涨点):添加GAM注意力机制;添加小目标检测头;替换为Wise-IoU损失函数+完整web端展示(实现简单目标跟踪功能)
- 基于MATLAB的LSTM与分位数回归多输入单输出时间序列预测模型
- MATLAB实现电-气-热综合能源系统耦合优化调度模型及其应用 综合能源系统 (2025-08-24)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


