系统维护需求,需要将word转成pdf,上一篇博客是把word2003的模板升级成word2007模板,因为旧模板生成的word为xml格式转成pdf后内容不对,在网上搜寻了很久linux系统相关支持,发现了openoffice4.
参考:openoffice安装和卸载
https://blog.csdn.net/lx_nhs/article/details/99305227
https://blog.csdn.net/zhou920786312/article/details/79964040
启动openoffice
linux下:
cd /opt/openoffice4/program
./soffice "-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" -nologo -headless -nofirststartwizard &
查看是否启动
ps -ef | grep openoffice
贴上部分java代码word转成pdf
public boolean officeToPDF(String sourceFile, String destFile) {
try {
File inputFile = new File(sourceFile);
// Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(inputFile), "UTF-8"));
if (!inputFile.exists()) {
// 找不到源文件, 则返回false
return false;
}
// 如果目标路径不存在, 则新建该路径
File outputFile = new File(destFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
//如果目标文件存在,则删除
if (outputFile.exists()) {
outputFile.delete();
}
/* Document document = new Document();
document.loadFromFile("Sample.docx");
//保