openoffice转换成pdf

本文是基于若依架构集成openoffice转pdf

前言:电脑或者服务器必须安装Openoffice才能使用

1 application.yml引入配置:



	# openOffice
	jodconverter:
		   local:
			# 默认不开启 需要开启的设置成true
			enabled: false
			 # 设置openOffice主目录 默认会自动读取
			office-home: C:\Program Files (x86)\OpenOffice 4\
			# openOffice进程重启前的最大进程数
			max-tasks-per-process: 10
			# 开启多个openOffice进程,每个端口对应一个进程
			port-numbers: 8100

2 pom引入依赖

	        <!-- openoffice -->
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>unoil</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>ridl</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>jurt</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>juh</artifactId>
            <version>4.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-local</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-core</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-spring-boot-starter</artifactId>
            <version>4.3.0</version>
        </dependency>

3 代码:

    @Autowired(required = false)
    private DocumentConverter documentConverter;
	
	    /**
     * 集成openoffice转换pdf
     * 文件转换
     */
    @RequestMapping("converter")
    public AjaxResult converter() {
        try {
            documentConverter.convert(new File("C:\\Users\\Administrator\\Desktop\\备忘录.txt")).to(new File("C:\\Users\\Administrator\\Desktop\\备忘录.pdf")).execute();
        } catch (OfficeException e) {
            logger.error("转换失败{}", e);
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白菜码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值