Java教程

java中使用openoffice工具word转pdf

本文主要是介绍java中使用openoffice工具word转pdf,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
  • 下载openoffice https://www.openoffice.org/  

        版本:Apache_OpenOffice_4.1.5_Win_x86_install_zh-CN.exe

  • 添加pom依赖
<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>
  • 添加yml配置
jodconverter:
  local:
    enabled: true
    office-home: "C:\\Program Files (x86)\\OpenOffice 4"  #本地安装openoffice的路径
    max-tasks-per-process: 10
    port-numbers: 8100
  • Controller层写入
    @Autowired
    private DocumentConverter converter;


    /**
     * word转pdf
     * @param input word文件输入路径
     * @param output pdf文件输出路径
     */
    @ApiOperation(value = "wordtopdf")
    @RequestMapping(value = "/wordtopdf", method = RequestMethod.GET)
    public void wordtopdf(@RequestParam(name = "input") String input,@RequestParam(name = "output") String output) {
        File inputFile = new File(input);
        File outputFile = new File(output);
        try {
            converter.convert(inputFile).to(outputFile).execute();
        } catch (OfficeException e) {
            e.printStackTrace();
        }
    }

参考文章:

SpringBoot集成jodconverter使用openoffice将word转为pdf - 简书

Java实现word文档转换为pdf,jodconverter_XIA_1997的博客-CSDN博客_java pdfconverter

这篇关于java中使用openoffice工具word转pdf的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!