public class LibreOfficeConvertor extends OfficeConvertor
机器上需要安装LibreOffice,利用LibreOffice的进程执行文档格式转换,一个进程同一时刻只能转换一个文档。 不支持多进程。
经过实践,目前依靠LibreOffice进行PDF文档转换,对于excel支持的效果还比较好, 除了跨行合并的单元格文本不是水平居中对齐,其他效果都还比较理想。 另外经过对比,转换格式在效果上弱于JACOB(仅支持windows系统,依赖微软OFFICE), 在转换速度上,小文件openoffice转换更快,大文件libreoffice转换更快。
OFFICE_POSTFIXS
限定符和类型 | 方法和说明 |
---|---|
static void |
office2Pdf(String officeHome,
File officeFile,
File destPdf)
利用LibreOffice将office文档转换为pdf文档,其过程为:
|
static void |
stopOfficeService()
关闭LibreOffice服务
|
verifyConvertFiles
public static void stopOfficeService()
public static void office2Pdf(String officeHome, File officeFile, File destPdf) throws org.jodconverter.office.OfficeException, InterruptedException
officeHome
- libreOffice安装目录,
windows,如:C:\Program Files\LibreOffice
Linux,如:/opt/libreoffice6.3
Mac,如:/Application/libreOfficeSoftofficeFile
- 源office文档destPdf
- 目标PDF文档org.jodconverter.office.OfficeException
- 转换过程中,可能抛出该异常InterruptedException
- 转换过程中,可能抛出该异常