java中使用libreoffice将word转换成pdf格式
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
public void openPDF(HttpServletResponse response) {
try {
String targetPath = System.getProperty("java.io.tmpdir")+File.separator;
String docxPath = "http://192.168.200.201:9093/M00/00/01/wKjIyVqQ34yAUO-uAAAtY6q46LU28.docx";
wordConverterToPdf(docxPath, targetPath);
String name = docxPath.substring(docxPath.lastIndexOf("/")+1);
String[] nameArr = name.split("\\.");
CommandExecute.findPdf(response,targetPath+nameArr[0]+".pdf");
} catch (IOException e) {
e.printStackTrace();
}
}
File file = new File(docxPath);
// String path = file.getParent();
String osName = System.getProperty("os.name");
String command = "";
if (osName.contains("Windows")) {
command = "soffice --convert-to pdf -outdir " + targetPath + " " + docxPath;
} else {
command = "doc2pdf --output=" + targetPath + File.separator + file.getName().replaceAll(".(?i)docx", ".pdf") + " " + docxPath;
}
String result = CommandExecute.executeCommand(command);
if (result.equals("") || result.contains("writer_pdf_Export")) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return false;
}
import java.io.*;
* linux或windows命令执行
*/
public class CommandExecute {
// CommandExecute obj = new CommandExecute();
// String domainName = "www.baidu.com";
// //in mac oxs
// String command = "ping " + domainName;
// //in windows
// //String command = "ping -n 3 " + domainName;
// String output = obj.executeCommand(command);
// System.out.println(output);
// }
StringBuffer output = new StringBuffer();
Process p;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
inputStreamReader = new InputStreamReader(p.getInputStream(), "UTF-8");
reader = new BufferedReader(inputStreamReader);
String line = "";
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(inputStreamReader);
}
System.out.println(output.toString());
return output.toString();
response.setCharacterEncoding("utf-8");
FileInputStream in = new FileInputStream(new File(targetPath));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b)) != -1) {
out.write(b);
}
out.flush();
in.close();
out.close();
}
}
java中使用libreoffice将word转换成pdf格式相关推荐
- word转换成pdf java代码_java代码实现word转换成pdf
[实例简介] va代码 word转pdf ,word批量转换成pdf,word单独转换成pdf,只需要调用WordToPDFUtil方法就可以实现批量或者单独转换 [实例截图] [核心代码] e6f6 ...
- 用Python批处理将WORD文件转换成PDF格式(工具:win32com模块)
用Python批处理将WORD文件转换成PDF格式 一.问题分析 key words:批处理.WORD转换PDF.办公自动化 二.材料准备 三.代码实现 ☆其他问题:日常遇到问题,整理笔记不易,欢迎交 ...
- 如何批量将Word转换成PDF?这几种方法都可以实现批量转换
怎么把Word文档批量转换成PDF格式呢?我们在日常的工作学习中,经常会使用Word文档来编辑文件,把文件编辑好后在发送的时候一般都会选择PDF格式来发送,,因为这样我们编辑好的格式才不会混乱.当我们 ...
- 迅捷word转换成pdf转换器最新版
怎样把Word转换成PDF格式的好呢?随着PDF格式文件使用的范围越来越广,很多时候我们就需要把Word格式转换成PDF进行使用,很多朋友都会觉得手上都没有辅助软件而无法进行操作.也可能是没有找到正确 ...
- Word转换成PDF文件在线转换
Word文档转换成PDF文件怎么转换?为了文档的安全性考虑,有时候需要将Word转换成PDF格式的.如何进行两者的的转换是成功的主要因素所在,小编也有过这样的经历个人使用后,感觉迅捷word转换成pd ...
- 如何把word转成pdf格式以及如何从指定页开始设置页码技巧
Word文档我相信没几个人不认识,但word的使用技巧数不胜数,你确定你全部都掌握了吗?今天为大家分享两个Word使用过程中常见的难题!打包拿走,不谢! ·首先是Word转换成PDF格式的技巧 如果你 ...
- CAD看图软件怎么将CAD图纸转换成PDF格式
我们在CAD制图的时候,常常会遇到CAD图纸转换的各 种问题.其中较常见的就有怎么将CAD图纸转换成PDF格式?若是我们使用CAD看图软件,在查看CAD图纸的时候就直接将CAD图纸转换成PDF格式,该 ...
- 将word文档转换成pdf格式【使用Aspose技术实现:亲测可用】
提示:Java使用Aspose技术将word文件转换成pdf文件 文章目录 一.介绍 二.下载依赖并引入jar包 三.编写功能 一.介绍 Java语言使用Aspose技术将word转换成pdf文件的功 ...
- C# 使用Microsoft.Office.Interop将Excel、Word转换成PDF遇到的问题总结
首先应用中引入Microsoft.Office.Interop.Excel.Microsoft.Office.Interop.Word两个dll,将嵌入式互操作类型设为False, WORD转换成PD ...
- 用什么方法可以将Word转换成PDF文档?
我们有时编辑完Word文件需要打印或发送给他人查看,一般会先转换为PDF格式,这样在别的电脑上打开时就不会出现格式的变动,也不会出现因为版本而无法打开的问题,那么用什么方法可以将Word转换成PDF文 ...
最新文章
- SEO优化如何“搭乘”线上营销推广“列车”?
- ITRON系统使用方法
- 超图三维GIS开发概念学习
- php如何转换类型,PHP数据类型转换
- 【iCore3 双核心板_ uC/OS-III】例程七:信号量——任务同步
- POI的入门:单元格样式处理
- 0419 一些不错的UI作品,以后陆续更新
- 提升对前端的认知,不得不了解Web API的DOM和BOM
- 最新PC游戏下载链接
- Keras 报错:An operation has `None` for gradient.
- LM NTLM ophcrack RainBow table (转)
- 物联网云计算成本核算 小厂的出路在哪里
- 计算机考试考什么二级,计算机国家二级考试会考什么内容?怎么考?
- JavaScript 计数器
- 火热升级:360Safe VS 雅虎助手
- Lock接口和AQS原理与实现(Java并发编程的艺术整理)
- python pkl、npy数据转换为csv
- 物联网嵌入式系统开发应用软件公司怎么选择
- 计算机网络速度测试指令,怎么ping网速 ping命令简单测试网速方法【详解】
- 昇腾AI室外移动机器人原理与应用(二 初识室外移动机器人)