openoffice将html转成pdf,通过openOffice将office文件转成pdf

ba7d3124646f6ac224689751a5ab8dd4.png

输入cmd回车

f66a84531026f13aca0ff5fc8baf3102.png

在命令窗口输入

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" –nofirststartwizard

此时服务就开启了将以下代码放到工具类里面,直接调用即可

import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;

import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;

import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

...

...

public File office2Pdf(String srcPath, String pdfPath) throws Exception {

// 源文件目录

File inputFile = new File(srcPath);

if (!inputFile.exists()) {

throw new Exception("程序出现问题,文件不存在");

}

// 输出文件目录

File outputFile = new File(pdfPath);

if (!outputFile.exists()) {

outputFile.createNewFile();

}

// 调用openoffice服务线程

String command = openOfficeCommand;

Process process = Runtime.getRuntime().exec(command);

// 连接openoffice服务

OpenOfficeConnection connection = new SocketOpenOfficeConnection(openOfficeUrl, openOfficePort);

connection.connect();

// 转换word到pdf

DocumentConverter converter = new OpenOfficeDocumentConverter(connection);

converter.convert(inputFile, outputFile);

// 关闭连接

connection.disconnect();

// 关闭进程

process.destroy();

return outputFile;

}

...

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值