在CentOS系统上使用LibreOffice进行文档转换的步骤如下:
x86-64
)下载相应的安装包,例如LibreOffice_7.2.4_Linux_x86-64_rpm.tar.gz
。/home/
目录下。cd /home/
tar -xvf LibreOffice_7.2.4_Linux_x86-64_rpm.tar.gz
yum install -y wget fontconfig
/etc/profile
文件,添加以下内容:export LibreOffice_PATH=/opt/libreoffice7.2/program
export PATH=$LibreOffice_PATH:$PATH
source /etc/profile
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
/etc/rc.local
文件中。<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-core</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-spring-boot-starter</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>4.2.2</version>
</dependency>
jodconverter:
local:
enabled: true
office-home: /opt/libreoffice7.2
max-tasks-per-process: 10
port-numbers: 8100
import com.yf.boot.base.api.exception.ServiceException;
import com.yf.exam.ability.doc.service.OfficeService;
import lombok.extern.log4j.Log4j2;
import org.jodconverter.DocumentConverter;
import org.jodconverter.local.LocalConverter;
@Log4j2
public class DocumentConverterService {
private final OfficeService officeService;
public DocumentConverterService(OfficeService officeService) {
this.officeService = officeService;
}
public void convert(String sourceFilePath, String targetFilePath) throws ServiceException {
DocumentConverter converter = LocalConverter.builder().build();
converter.convert(sourceFilePath).to(targetFilePath).execute();
}
}
/usr/share/fonts/
目录中。以上步骤应该可以帮助你在CentOS系统上使用LibreOffice进行文档转换。如果需要进一步的帮助,请参考LibreOffice和JodConverter的官方文档。