- pom.xml添加documents4j依赖
dependency>
groupId>com.documents4jgroupId>
artifactId>documents4j-localartifactId>
version>1.0.3version>
dependency>
dependency>
groupId>com.documents4jgroupId>
artifactId>documents4j-transformer-msoffice-wordartifactId>
version>1.0.3version>
dependency>
dependency>
groupId>com.documents4jgroupId>
artifactId>documents4j-transformer-msoffice-excelartifactId>
version>1.0.3version>
dependency>
- 使用
/**
* word/excel转pdf
* @param inputWordPath 传入转换之前的路径 比如:"D:printFiletest.pdf"
* @param outPdfPath 传入转换之后的路径 比如:"D:printFiletest.pdf"
*/
private void wordOrExcelTransition(String inputWordPath, String outPdfPath){
File inputWord = new File(inputWordPath);
File outputFile = new File(outPdfPath);
try {
InputStream docxInputStream = new FileInputStream(inputWord);
OutputStream outputStream = new FileOutputStream(outputFile);
IConverter converter = LocalConverter.builder().build();
String fileTyle = inputWordPath.substring(inputWordPath.lastIndexOf("."), inputWordPath.length());//获取文件类型
if(".docx".equals(fileTyle)){
converter.convert(docxInputStream).as(Docum服务器托管entType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
}else if(".doc".equals(fileTyle)){
converter.convert(docxInputStream).as(DocumentType.DOC).to(outputStream).as(DocumentType.PDF).execute();
}else if(".xls".equals(fileTyle)){
converter.convert(docxInputStream).as(DocumentType.XLS).to(outputStream).as(DocumentType.PDF).execute();
}else if(".xlsx".equals(fileTyle)){
converter.convert(docxInputStream).as(DocumentType.XLSX).to(outputStream).as(DocumentType.PDF).execute();
}
outputStream.close();
System.out.println("success");
} catch (Exception e) {
e.printStackTrace();
}
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
相关推荐: 记录一次k8s pod之间ip无法访问,问题排查与定位
记录一次k8s pod之间ip无法访问,问题排查与定位 问题展现现象 node之间通信正常 部分node上的pod无法通信 排查有问题node 使用启动网络测试工具 环境准备 docker 数据库mysql 使用有状态副本集合 — apiVersion: …