嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元微信扫码支付:5 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
本文主要介绍springboot openoffice实现word转pdf的功能
import org.jodconverter.DocumentConverter;
import org.jodconverter.office.OfficeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File;
@Controller
public class WordToPdf {
@Autowired
private DocumentConverter converter;
@RequestMapping("/convertPdf")
@ResponseBody
public String toPdf(String filepath) throws OfficeException {
filepath="D:\\test.docx"; //被转换的word文档
File word = new File(filepath);
//截取字符串把word的后缀改为pdf
String pdfpath= filepath.substring(0,filepath.lastIndexOf(".")) ".pdf";
File pdf = new File(pdfpath);
//文件转换
converter.convert(word).to(pdf).execute();
return "true";
}
}