重写Linux下word转pdf
This commit is contained in:
parent
7e96ca171e
commit
a5766b31d3
|
|
@ -57,14 +57,8 @@ public class OfficeFileUtil {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
String pdfParentDir = FileUtil.getParent(pdfPath, 1) + File.separatorChar + IdUtil.fastSimpleUUID() + File.separatorChar;
|
||||
StringBuilder command = new StringBuilder();
|
||||
command.append("/usr/bin/libreoffice24.8").append(" ").append("--headless")
|
||||
.append(" ").append("--convert-to")
|
||||
.append(" ").append("pdf")
|
||||
.append(" ").append(wordPath)
|
||||
.append(" ").append("--outdir")
|
||||
.append(" ").append(pdfParentDir);
|
||||
command.append("unoconv -f pdf -o").append(" ").append(pdfPath).append(" ").append(wordPath);
|
||||
log.info("convert word file to pdf, command: {}", command);
|
||||
Process process = RuntimeUtil.exec(command.toString());
|
||||
process.waitFor();
|
||||
|
|
@ -72,9 +66,6 @@ public class OfficeFileUtil {
|
|||
String info = StrFormatter.format("word文档{}转换成pdf文档{}失败", wordPath, pdfPath);
|
||||
throw new BizException(info);
|
||||
}
|
||||
String outPdfPath = FileUtil.loopFiles(pdfParentDir).get(0).getAbsolutePath();
|
||||
FileUtil.move(new File(outPdfPath), new File(pdfPath), true);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new BizException(e.getMessage(), e);
|
||||
|
|
|
|||
Loading…
Reference in New Issue