基本信息
源码名称:JavaWeb简单实现word转pdf
源码大小:1.34M
文件格式:.rar
开发语言:Java
更新时间:2020-06-06
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍

本文主要介绍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";
}
}